Function convertMarkdownToHtml

  • Converts Markdown text to HTML. It handles the following Markdown elements:

    • Headers (h1 to h6)
    • Bold text
    • Italic text
    • Unordered lists
    • Ordered lists
    • Paragraphs
    • Images
    • Links

    Parameters

    • markdown: string

      The Markdown-formatted text to be converted.

    Returns string

    The resulting HTML string.

    const markdown = "# Header\n\nThis is **bold** and *italic* text.\n\n* List item 1\n* List item 2";
    const html = convertMarkdownToHtml(markdown);
    console.log(html);
    // Output:
    // <h1>Header</h1>
    // <p>This is <strong>bold</strong> and <em>italic</em> text.</p>
    // <ul><li>List item 1</li><li>List item 2</li></ul>