DEV Community

Aaditya
Aaditya

Posted on

How do browsers render Markdown???

How do browsers render markdown files?? For example in this website itself(dev.to) ,users write the posts in markdown and it gets displayed in form of html. Just curious to know how is it done.

Top comments (3)

Collapse
 
jmfayard profile image
Jean-Michel πŸ•΅πŸ»β€β™‚οΈ Fayard

There are libraries that transform markdown files to HTML that is then rendered by the browser.

GitHub logo markdown-it / markdown-it

Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed

markdown-it

Build Status NPM version Coverage Status Gitter

Markdown parser done right. Fast and easy to extend.

Live demo

  • Follows the CommonMark spec + adds syntax extensions & sugar (URL autolinking, typographer).
  • Configurable syntax! You can add new rules and even replace existing ones.
  • High speed.
  • Safe by default.
  • Community-written plugins and other packages on npm.

Table of content

Install

node.js & bower:

npm install markdown-it --save
bower install markdown-it --save

browser (CDN):

Usage examples

See also:

Simple

// node.js, "classic" way:
var MarkdownIt = require('markdown-it'),
    md = new MarkdownIt();
var result = md.render('# markdown-it rulezz!');
// node.js,
…

The real issue is that Markdown is not a real file format, it's just a small set of simple ideas, but unsufficient in practice, so everyone make his own Markdown.

There are much better file formats like asciidoctor.org/

Unfortunately it's a case of "worse is better" where the worse solution wins because it's more popular

Collapse
 
aadityajha2004 profile image
Aaditya

Ok, so There are no direct method to render md files. Can you suggest me how can I convert markdown to HTML in flask framework.

Collapse
 
jmfayard profile image
Jean-Michel πŸ•΅πŸ»β€β™‚οΈ Fayard

I would google "markdown python library"