#C6727. Markdown-to-HTML Converter
Markdown-to-HTML Converter
Markdown-to-HTML Converter
Your task is to implement a Markdown-to-HTML converter that supports the following features:
- Headers: Levels 1, 2, and 3 (using '#' syntax).
- Paragraphs: Plain text should be wrapped in
<p>
tags. - Unordered lists: Lines starting with "- " should be wrapped in
<ul>
and each item in<li>
tags. - Ordered lists: Lines starting with numbers followed by a period ("1. ", "2. ", ...) should be wrapped in
<ol>
and each item in<li>
tags. - Inline code: Text wrapped with backticks (`) should be converted to
<code>
tags. Use LaTeX-style formatting if you refer to any formulas (e.g. $`code`$ is not required here though).
The input will be provided via standard input (stdin) containing the Markdown text and the output must be printed to standard output (stdout) as HTML. Ensure that your solution can pass multiple test cases including edge cases.
inputFormat
The input consists of a Markdown string provided through standard input. The Markdown text may contain multiple lines and can include headers, paragraphs, unordered lists, ordered lists, and inline code.
For example:
# Header 1 ## Header 2 ### Header 3This is a paragraph with
inline code
.
- Item 1
- Item 2
- Item 3
- First item
- Second item </pre>
outputFormat
The program should output the corresponding HTML string. The HTML should convert headers, paragraphs, lists, and inline code to their respective HTML tags.
For the example above, the output would be:
Header 1
Header 2
Header 3
This is a paragraph with
inline code
.
- Item 1
- Item 2
- Item 3
- First item
- Second item
# Header 1
## Header 2
### Header 3
Header 1
Header 2
Header 3