簡體   English   中英

如何檢測markdown的代碼語言?

[英]How to detect code language for markdown?

我寫在textarea:

```ruby
 puts 'hello word!'
```

我不會得到:

<pre lang='ruby'><code>puts hello word!</code></pre>

相反,我得到了:

<code>puts hello word!</code>

我嘗試了不同的屬性。 我的幫手:

def markdown(text)
    renderer = Redcarpet::Render::HTML.new(
                                            hard_wrap:         true,
                                            fenced_code_block: true,
                                            no_intra_emphasis: true,
                                            filter_html:       true
                                            )
    markdown =
      Redcarpet::Markdown.new(
                              renderer,
                              fenced_code_block: true,
                              no_intra_emphasis: true,
                              fenced_code:       true,
                              gh_blockcode:      true,
                              autolink:          true,
                              hard_wrap:         true,
                              filter_html:       true
                              )

      markdown.render(text).html_safe
  end

為什么? 如何檢測代碼語言?

, with an s . 你想要的選項fenced_code_block ,用s 您似乎也在混合渲染器和擴展選項。 嘗試這個:

renderer = Redcarpet::Render::HTML.new(hard_wrap:   true,
                                       filter_html: true)

markdown = Redcarpet::Markdown.new(renderer,
                                   fenced_code_blocks: true,
                                   no_intra_emphasis:  true,
                                   autolink:           true)

markdown.render(text).html_safe

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM