Insert Mark (md) in HTML

I need help inserting markdown or * .md file inside HTML index file. I found that I can embed HTML inside markdowns, but not vice versa. This would help increase the speed of my editing, because the markdown format is extremely easy to use (since I'm using it now), and I donโ€™t need to change the format of the rest of my site. I know something like this is being done to insert another HTML file from <iframe src="path/to/html>html-name</iframe>. I could also use javascript to interpret the md format when loading the page. Thanks in advance.

+4
source share
1 answer

Here's a solution that I forgot about a long time ago:

Tagdown Logo

, , marked.js.

tagdown.js.

: http://spikespaz.com/tagdownjs/

, : https://spikespaz.imtqy.com/tagdownjs/

Github: https://github.com/spikespaz/tagdownjs

, markdown. . . , .

Update

TagdownJS Github. , .

, Marked.js .

document.body.style.display = "none"; // Hide the page until it finished rendering.

document.createElement("markdown");
var md_tags = document.getElementsByTagName("markdown"); // Returns array of all markdown tags.

for (var i = 0; i < md_tags.length; i++) { // Iterate through all the tags, and generate the HTML.
    var md_text = md_tags[i].textContent.replace(/^[^\S\n]+/mg, ""); // I love regex, so shoot me.

    var md_div = document.createElement("div"); // Make a new div to replace the fake tag.
    md_div.id = "content";
    md_div.innerHTML = marked(md_text);

    md_tags[i].parentNode.appendChild(md_div); // Add remove the old raw markdown.
    md_tags[i].parentNode.removeChild(md_tags[i]);
}

document.body.style.display = ""; // Show the rendered page.
+5

Source: https://habr.com/ru/post/1612521/


All Articles