【问题标题】:How to detect code language for markdown?如何检测markdown的代码语言?
【发布时间】:2016-12-26 12:41:28
【问题描述】:

我已经在文本区域中写了:

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

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

【问题讨论】:

    标签: ruby markdown redcarpet


    【解决方案1】:

    您想要的选项是fenced_code_block<b><i>s</i></b>,带有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
    

    【讨论】:

      猜你喜欢
      • 2015-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多