7

我知道 github 已经发布了用于将 markdown 转换为 HTML 的 Redcarpet gem,但据我所知,它不支持(或识别)Github 风格的 markdown,例如

javascript var x = 1;

任何人都知道是否有 gem(或 redcarpet 的某种方式)来处理 github 风格的语法,特别是我对语法突出显示感兴趣。

谢谢。

4

2 回答 2

4

现在最好使用 github-markdown gem。

GitHub::Markdown.render(content)
于 2012-04-16T17:03:18.700 回答
3

您可以使用 Redcarpet 将 markdown 代码转换为 HTML。这里有两个从 Redcarpet 项目测试中提取的示例

def test_compat_api_knows_fenced_code_extension
  text = "```ruby\nx = 'foo'\n```"
  html = RedcarpetCompat.new(text, :fenced_code).to_html
  html_equal "<pre><code class=\"ruby\">x = 'foo'\n</code></pre>", html
end

def test_compat_api_ignores_gh_blockcode_extension
  text = "```ruby\nx = 'foo'\n```"
  html = RedcarpetCompat.new(text, :fenced_code, :gh_blockcode).to_html
  html_equal "<pre><code class=\"ruby\">x = 'foo'\n</code></pre>", html
end

我希望这回答了你的问题

于 2012-04-05T12:24:50.813 回答