Loading...
Loading...
You are given a list of strings lines, the lines of a document written in a simplified Markdown, in order.
Return the document converted to HTML, as a single string.
The document is made of blocks, which are headings and paragraphs. Find them line by line:
#, ##, or ### followed by a space is a heading of level 1, 2, or 3. Its content is the rest of the line after that space, with leading spaces removed. It becomes <h1>content</h1>, <h2>content</h2>, or <h3>content</h3>.<p> and </p>.Note that a heading needs a space right after its # characters, and at most three of them. Lines such as #title or #### title are text lines.
Inside headings and paragraphs, replace each inline marker:
**text** becomes <b>text</b>._text_ becomes <i>text</i>.[text](url) becomes <a href="url">text</a>.Every other character is copied unchanged. Spaces inside a line are kept as they are, and nothing is HTML-escaped.
The answer is the HTML of every block, in document order, with no separators or newlines between blocks. If the document has no blocks, return an empty string.
You can assume:
*, _, [, ], (, and ) appear only as part of the markers above.text and url of a marker are non-empty and contain none of those six characters, so markers are never nested.url contains no spaces.Input: lines = ["# This is a heading", "This is a paragraph with **bold** text.", "This is another one. With a [link](http.example.com) and _italic_."]
Output: "<h1>This is a heading</h1><p>This is a paragraph with <b>bold</b> text. This is another one. With a <a href=\"http.example.com\">link</a> and <i>italic</i>.</p>"
Explanation: The first line starts with "# ", so it is a level-1 heading.
The next two lines are consecutive text lines, so they form one paragraph,
joined by a single space. Each marker is replaced inside that paragraph.
Input: lines = [" ## Steps ", "#1 install", "#### then run", "", " ", "Check the **logs**.", "### Done"]
Output: "<h2>Steps</h2><p>#1 install #### then run</p><p>Check the <b>logs</b>.</p><h3>Done</h3>"
Explanation: The first line is trimmed to "## Steps", a level-2 heading.
"#1 install" has no space after "#", and "####" is more than three "#", so both
are text lines and form one paragraph. The blank lines end it. The double space
in "Check the" is inside the line, so it is kept. "### Done" is a level-3 heading.
Input: lines = ["", " "]
Output: ""
Explanation: Both lines are blank, so the document has no blocks.
lines.length ≤105lines[i] consists of printable ASCII characters (codes 32 to 126) other than " and \