I have started to build a markdown editor using javascript from scratch. First I studied the syntax of markdown and what is it about. Then someone asked me to use a markdown parser. I dont really understand it does and how to use it after many searches. Any help would be beneficial. Thanks in advance.
I have started to build a markdown editor using javascript from scratch. First I studied the syntax of markdown and what is it about. Then someone asked me to use a markdown parser. I dont really understand it does and how to use it after many searches. Any help would be beneficial. Thanks in advance.
A long but inplete list of Markdown "Parsers" can be found here: https://github./markdown/markdown.github./wiki/Implementations
However, to call those all "parsers" is a bit of a misnomer. They do "parse" the Markdown, but they also render/pile the Markdown into something else, usually HTML. As this question is tagged [javascript], we'll use a JavaScript library as an example. The Marked library has the following tag line:
A full-featured markdown parser and piler, written in JavaScript.
It is honest about its function. It both parses and then piles/renders the output as HTML. In fact, the simple use case given in the documentation is:
var marked = require('marked'); console.log(marked('I am using __markdown__.')); // Outputs: <p>I am using <strong>markdown</strong>.</p>
You pass in a Markdown text string and it returns a string of HTML. But when you read through the documentation, you find a section for Pro level use which explains that "[y]ou also have direct access to the lexer and parser if you so desire." Note the example:
$ node require('marked').lexer('> i am using marked.') [ { type: 'blockquote_start' }, { type: 'paragraph', text: 'i am using marked.' }, { type: 'blockquote_end' }, links: {} ]
Given a Markdown text string, the "lexer" returns a list of tokens. It is now up to you to determine how those tokens are used.
How to use that to build a Markdown editor is beyond the scope of this forum, I'm afraid.
This is not really a question about a programming, but you seem to be nice, and it might help other people...
A markdown parser is a library (a or some scripts) that are going to parse, in this case, markdown. Markdown is often transformed into HTML
.
So, a markdown parser transforms markdown into html.
So, with a markdown parser, you'd just have to do something like this:
html = parseMarkdown(markdown_code)
And you're done. You don't have to parse the markdown yourself.