#421 · Parsing · Advanced · 160 XP · about 35 min
Chat apps let people type **bold** or *italic* and show the message formatted. Write md_inline(text) that turns one line of Markdown into HTML with these rules:
**hi** becomes <strong>hi</strong>. Two asterisks next to each other always mean bold.*hi* becomes <em>hi</em>.<code> and </code>.[label](url) makes a link, <a href="url">label</a>. The label may contain bold, italic and code. The url runs up to the first ) and is copied as it is.*, [, ], ( or ) stands for that character as plain text. A backslash in front of anything else is a plain backslash.& with &, < with <, > with >, a double quote with " and a single quote with '. This is exactly what html.escape does.md_inline('Some **bold** and *italic* text') # returns 'Some <strong>bold</strong> and <em>italic</em> text' md_inline('Run `x < 3 && y` first') # returns 'Run <code>x < 3 && y</code> first' md_inline('See [the **docs**](https://example.com/?a=1&b=2).') # returns 'See <a href="https://example.com/?a=1&b=2">the <strong>docs</strong></a>.' md_inline('Price: 2 \\* 3 is *six*') # returns 'Price: 2 * 3 is <em>six</em>'
In the last example the text holds a backslash before the first asterisk, so that asterisk is plain text.
text has at most 100,000 characters and no line breaks.] that is not escaped always ends a link's label, and a url contains only letters, digits and the characters : / . ? = & # - _ %.First solves only, ranked by stars and then time.