我正在寻找一种将html
文件转换为Markdown
类型语法的方法。那是我客户的要求。他们认为这种存档方法非常适合在其GUI应用程序中进行操作,同时还能以可接受的保留标记数量进行编辑。
我正在查看Kramdown
,但令人困惑。我创建了一个从Kramdown
文件导入的html
对象:
doc = Kramdown::Document.new(source, :input => 'html')
我想输出Kramdown
格式,但是我不明白如何将其另存为Kramdown
格式。
是否可以使用Kramdown
格式保存文件?原始的html
文件已解析为Kramdown
,现在我想像使用简单的标记语法那样保存Markdown
文件一样保存该文件。效果很好:
puts doc.to_html
...所以doc
很好。我只需要一种输出Kramdown
版本的方法。任何见解表示赞赏。干杯
答案 0 :(得分:1)
您需要使用to_kramdown
方法。它不是直接记录的,因为它是动态调用的,但请参见method_missing
。
doc = Kramdown::Document.new(source, :input => 'html')
puts doc.to_kramdown
答案 1 :(得分:0)
您可以使用https://github.com/xijo/reverse_markdown:
input = '<strong>feelings</strong>'
result = ReverseMarkdown.convert input
result.inspect # " **feelings** "