简体   繁体   中英

Ruby Output Kramdown to Text/Kramdown

I'm looking for a way to translate an html file to a Markdown type syntax. That's the request from my client. They think that this type of archival method is good for manipulation into one of their GUI apps, while maintaining the ability to edit with an acceptable amount of retained markup.

I'm looking at Kramdown , but it's confusing. I have created a Kramdown object imported from the html file:

doc = Kramdown::Document.new(source, :input => 'html')

I'd like to output the Kramdown format, but I don't understand how to save it as a Kramdown format.

Is there a way to save the file with the Kramdown format? The original html file is parsed into Kramdown , now I want to save that file much like how I would a Markdown file, with that simple markup syntax. This works just fine:

puts doc.to_html

...so doc is just fine. I just need a way to output the Kramdown version. Any insight appreciated. Cheers

You need the to_kramdown method. It's not documented directly as it is dynamically called, but see method_missing .

doc = Kramdown::Document.new(source, :input => 'html')
puts doc.to_kramdown

You could use https://github.com/xijo/reverse_markdown :

input  = '<strong>feelings</strong>'
result = ReverseMarkdown.convert input
result.inspect # " **feelings** "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM