Back to Samsara questions
BehavioralSoftware Engineer

Markdown-to-HTML Processor

Frequency: Reported


Reported prompt

Implement a markup processor that converts a Markdown file into HTML. Support:

  • Two or more consecutive newline characters start a new paragraph. Other formatting does not cross paragraph boundaries.
  • A single newline is a soft line break represented by <br/>.
  • A blockquote consists of one or more consecutive lines beginning with > .
  • Strikethrough text is surrounded by ~~ and converted to <del>...</del>.

Example

java
String input = "This is a paragraph with a soft\n" +
    "line break.\n\n" +
    "This is another paragraph that has\n" +
    "> Some text that\n" +
    "> is in a\n" +
    "> block quote.\n\n" +
    "This is another paragraph with a ~~strikethrough~~ word.";

One valid conversion is:

html
<p>This is a paragraph with a soft<br/>line break.</p>
<p>This is another paragraph that has <br/>
  <blockquote>Some text that<br/>is in a<br/>block quote</blockquote>
</p>
<p>This is another paragraph with a <del>strikethrough</del> word.</p>

The output does not need to match this formatting exactly; only valid HTML is required.

Follow-ups

Two reported extensions added support for:

  • bold text; and
  • links.

The source did not preserve the delimiters or exact HTML expected for those extensions.