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

    • content: string

      The Markdown or HTML content to be converted.

    • toHtml: boolean = true

      default=true - If true, converts Markdown to HTML. If false, converts HTML to Markdown.

    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>