Ask coding questions

← Back to all posts
Markdown in HTML
isaiah08 (86)

Is there a HTML tag that processes markdown? I know that there is a way to do it with JS, but can you do it just with HTML?

<div markdown="1">

doesn't work.

Answered by Baconman321 (1103) [earned 5 cycles]
View Answer
Comments
hotnewtop
Baconman321 (1103)

No, but you can make a parser quite easily. Just use JavaScript to go over each character of the text and find the commands for markdown.

For code, you can use a syntax highlighter.

isaiah08 (86)

Thanks for the quick response! @Baconman321

xxpertHacker (931)

@Baconman321 Since when is creating a markdown parser from scratch that fully conforms to the MD specification quite easy.

Btw, the parser I've used was this one; very easy setup.

(Example of use in real Repl: https://repl.it/@EpicGamer007/HackTalk#modules/md.mjs)

xxpertHacker (931)

Well... you can target the DOM:

const div = document.body.querySelector("div[markdown='1']");

const parser = new DOMParser;

const input = div.textContent;

const output_document = parser.parseFromString("text/html", parseMarkdown(input));

const output_element = output_document.documentElement;

div.replaceWith(output_element);
SixBeeps (5320)

No, because HTML is itself a markdown language (hence the name HyperText Markdownup Language)

isaiah08 (86)

Thanks for the quick response! @SixBeeps

Baconman321 (1103)

@SixBeeps LOL imagine confusing markdown with markup

Baconman321 (1103)

@SixBeeps U gonna pay to keep quiet?

Jk, Jk