Markdown to plain text in Ruby?

后端 未结 3 1826
盖世英雄少女心
盖世英雄少女心 2021-01-07 21:26

I\'m currently using BlueCloth to process Markdown in Ruby and show it as HTML, but in one location I need it as plain text (without some of the Markdown). Is there a way to

3条回答
  •  我在风中等你
    2021-01-07 21:52

    It's not ruby, but one of the formats Pandoc now writes is 'plain'. Here's some arbitrary markdown:

    # My Great Work
    
    ## First Section
    
    Here we discuss my difficulties with [Markdown](http://wikipedia.org/Markdown)
    
    ## Second Section
    
    We begin with a quote:
    
    > We hold these truths to be self-evident ...
    
    then some code:
    
        #! /usr/bin/bash
    
    That's *all*. 
    

    (Not sure how to turn off the syntax highlighting!) Here's the associated 'plain':

    My Great Work
    =============
    
    First Section
    -------------
    
    Here we discuss my difficulties with Markdown
    
    Second Section
    --------------
    
    We begin with a quote:
    
      We hold these truths to be self-evident ...
    
    then some code:
    
        #! /usr/bin/bash
    
    That's all.
    

    You can get an idea what it does with the different elements it parses out of documents from the definition of plainify in pandoc/blob/master/src/Text/Pandoc/Writers/Markdown.hs in the Github repository; there is also a tutorial that shows how easy it is to modify the behavior.

提交回复
热议问题