Search code examples
javascriptparsingmarkdown

Javascript: Sanitize markdown


I've got an article writed in markdown on my webpage and I want to show a short resume on the index page.

The problem is that the body has got markdown, and I want to show plain text on the resume.

Ex:

Article text: Hello people

Resume text: Hello people

How can I do that in Javascript?


Solution

  • What i might do is parse the markdown as HTML, then take only the textual content of it.

    Psudeocode:

    htmlElement.innerHtml = markdown.parse(myMarkDownString);
    var plaintext = htmlElement.innerText;
    alert(plaintext);