[英]Ruby Kramdown breaks code block and table in a markdown
當我使用to_kramdown
時,Kramdown 似乎將代碼塊的分隔符從```
更改為`
。 最低代碼如下。
require 'kramdown'
code = <<END
```rb
num = 0
while num < 2 do
print("num = ", num)
end
print("End")
```
END
puts code #1
doc = Kramdown::Document.new(code)
puts doc.to_kramdown #2
這給你:
```rb
num = 0
while num < 2 do
print("num = ", num)
end
print("End")
```
`rb
num = 0
while num < 2 do
print("num = ", num)
end
print("End")
`
如何使用```
恢復代碼塊?
我檢查了KD:Documnt
object 並且它有:codespan_delimiter=>"```"
。 有沒有辦法在我恢復時使用它?
<KD:Document: options={:template=>"", :auto_ids=>true, :auto_id_stripping=>false, :auto_id_prefix=>"", :transliterated_header_ids=>false, :parse_block_html=>false, :parse_span_html=>true, :html_to_native=>false, :link_defs=>{}, :footnote_nr=>1, :entity_output=>:as_char, :toc_levels=>[1, 2, 3, 4, 5, 6], :line_width=>72, :latex_headers=>["section", "subsection", "subsubsection", "paragraph", "subparagraph", "subparagraph"], :smart_quotes=>["lsquo", "rsquo", "ldquo", "rdquo"], :typographic_symbols=>{}, :remove_block_html_tags=>true, :remove_span_html_tags=>false, :header_offset=>0, :syntax_highlighter=>:rouge, :syntax_highlighter_opts=>{}, :math_engine=>:mathjax, :math_engine_opts=>{}, :footnote_backlink=>"↩", :footnote_backlink_inline=>false, :footnote_prefix=>"", :remove_line_breaks_for_cjk=>false, :forbidden_inline_options=>[:template], :list_indent=>2} root=<kd:root options={:encoding=>#<Encoding:UTF-8>, :location=>1, :options=>{}, :abbrev_defs=>{}, :abbrev_attr=>{}, :footnote_count=>0} children=[<kd:p options={:location=>1} children=[<kd:codespan value="rb\nnum = 0\nwhile num < 2 do\n print(\"num = \", num)\nend\nprint(\"End\")\n" options={:codespan_delimiter=>"```", :location=>1}>]>]> warnings=[]>
我也試過Kramdown GFM Parser但它轉換代碼塊的方式不同,如下所示。
num = 0
while num < 2 do
print("num = ", num)
end
print("End")
{: .language-rb}
根據 Kramdown 規范:
Code Span適用於 Inline Code,與Code Blocks不同。
您當前用於代碼塊 ( ```
) 的風格是Github 風格 Markdown這就是 GFM 解析器/轉換器工作的原因。 例如
num = 0
while num < 2 do
print("num = ", num)
end
print("End")
{: .language-rb}
是正確的 output 因為 4 個空格也是有效的代碼塊語法。
如果你想使用kramdown
gem,你必須將其更改為:
require 'kramdown'
code = <<END
~~~ruby
num = 0
while num < 2 do
print("num = ", num)
end
print("End")
~~~
END
doc = Kramdown::Document.new(code)
doc.to_kramdown
在這種情況下,output 與 GFM 解析器相同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.