gettalong / kramdown

kramdown is a fast, pure Ruby Markdown superset converter, using a strict syntax definition and supporting several common extensions.
http://kramdown.gettalong.org
Other
1.72k stars 274 forks source link

Revert back to original markdown #776

Closed narutaro closed 1 year ago

narutaro commented 1 year ago

Hi,

I am looking for a way to revert back to original markdown from Kramdown::Document.

My code is:

require 'kramdown'

code = <<END
# Code block

```rb
num = 0
while num < 2 do
   print("num = ", num)
end
print("End")

END

table = <<END

Table

Option Description
data path to data files to supply the data that will be passed into templates.
engine engine to be used for processing templates. Handlebars is the default.
ext extension to be used for dest files.

END

In my real application, I want to do something on the kramdown object and revert back to a markdown

c = Kramdown::Document.new(code) puts c.to_kramdown puts "---" t = Kramdown::Document.new(table) puts t.to_kramdown


This code returns slightly different markdown. `` ``` `` becomes `` ` `` and `| ------ | ----------- |` is `|----------`.

Code block

rb num = 0 while num < 2 do print("num = ", num) end print("End")


Table

Option Description
data path to data files to supply the data that will be passed into templates.
engine engine to be used for processing templates. Handlebars is the default.
ext extension to be used for dest files.

Do you have an advice how I can get original markdown from `Kramdown::Document`?
gettalong commented 1 year ago

You are using an invalid syntax, code blocks are started with three tildes ~~~, you are starting a code span with three backticks. Use the correct syntax and the output should be fine.

The table output is just the minimum needed to recreate the table. There is nothing implemented to create nice aesthetics. If you need nicely formatted table output, you need to create a custom converter that produces your desired output.

narutaro commented 1 year ago

@gettalong - thank you for your clarification. I will try that way. :)