You can use Redcarpet to convert markdown code into HTML. Here you have two examples extracted from Redcarpet design tests.
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
Hope this answers your question.
pvcarrera
source share