我目前正在使用BlueCloth在Ruby中处理Markdown并将其显示为HTML,但在一个地方我需要它为纯文本(没有一些Markdown)。有没有办法做到这一点?
有没有一种将markdown转换为纯文本的方法?有没有一种html转纯文本的方法,可以让我感受到BlueCloth的效果?
发布于 2014-11-14 12:12:36
Markdown gem有一个Redcarpet::Render::StripDown渲染器,可以“将Markdown转换为纯文本”。
复制并修改它以满足您的需要。
或者像这样使用它:
Redcarpet::Markdown.new(Redcarpet::Render::StripDown).render(markdown)
发布于 2010-04-13 08:20:17
它不是ruby,但Pandoc现在写的一种格式是“普通的”。下面是一些任意的标记:
# 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*.
(不确定如何关闭语法突出显示!)下面是相关的“普通版”:
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.
您可以从Github存储库的pandoc/blob/master/src/Text/Pandoc/Writers/Markdown.hs中的plainify
定义中了解它如何处理从文档中解析出的不同元素;还有一个tutorial展示了修改行为是多么容易。
https://stackoverflow.com/questions/2547343
复制相似问题