如何检测降价的代码语言?

How to detect code language for markdown?

我在文本区写过:

```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

为什么?如何检测代码语言?

你想要的选项是fenced_code_block<b><i>s</b></i>,加上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