I know github has released the Redcarpet gem for converting markdown to HTML but as far as I have seen it doesn't support (or recognize) Github flavored markdown such as
javascript
var x = 1;
Anyone know if there is a gem (or some way with redcarpet) to handle the github flavored syntax, specifically I am interested in the syntax highlighting.
Thanks.
Markdown is converted to HTML by the comrak crate. The default stylesheet (the CSS file) is from sindresorhus/github-markdown-css. If ``` is used in the input Markdown file, the highlight. js will be automatically embedded in the output HTML file.
To convert Markdown to HTML using Typora, click File —> Export —> HTML. Then save the file in your preferred location. The image below shows that the HTML output looks exactly as how the Markdown is displayed inside Typora.
You can either use the syntactic sugar that GFM (or other GitHub-supported markup language you're using) provides or, since Markdown can contain raw HTML, you can enter the HTML tags manually.
Now better to use github-markdown gem.
GitHub::Markdown.render(content)
You can use Redcarpet for converting markdown code to HTML. Here you have two examples extracted from Redcarpet project 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
I hope this answers your question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With