Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert github flavored markdown to HTML?

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.

like image 527
codecraig Avatar asked Mar 14 '12 00:03

codecraig


People also ask

How does GitHub convert Markdown to HTML?

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.

How do I convert Markdown to HTML?

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.

Does GitHub Markdown support HTML?

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.


2 Answers

Now better to use github-markdown gem.

GitHub::Markdown.render(content)
like image 147
Akzhan Abdulin Avatar answered Sep 22 '22 08:09

Akzhan Abdulin


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

like image 24
pvcarrera Avatar answered Sep 21 '22 08:09

pvcarrera