The Challenge
In this challenge, you are supposed to write a program or function that takes in a String, which will contain the simplified Markdown-like Markup, and outputs the corresponding HTML Markup.
The Input
You can take input in whatever way you wish to. The type
of the input should be String.
The Output
You can output the result in any way you want. Logging to Console or Terminal, printing on screen, returning from function etc. are perfectly valid.
The Rules
- Convert each occurrence of
*foo*
and_foo_
to<em>foo</em>
. - Convert each occurrence of
**foo**
and__foo__
to<strong>foo</strong>
. - Convert each occurrence of
<tab or four spaces here>foo\n
to<pre><code>foo</code></pre>
. - Convert each occurrence of
#foo\n
to<h1>foo</h1>
. - Convert each occurrence of
##bar\n
to<h2>bar</h2>
. - Convert each occurrence of
###bar\n
to<h3>bar</h3>
. - Convert each occurrence of
####bar\n
to<h4>bar</h4>
. - Convert each occurrence of
#####bar\n
to<h5>bar</h5>
. - Convert each occurrence of
######bar\n
to<h6>bar</h6>
. - Convert each occurrence of
[foo](https:\\www.bar.com)
to<a href="https:\\www.bar.com">foo</a>
. - Convert each occurrence of

to<img src="https:\\www.bar.com" alt="foo"/>
. - Convert each occurrence of
>foo\n
to<blockquote>foo</blockquote>
. - Convert each occurrence of
- foo\n
as<li>foo</li>
(add<ul>
before theli
if the-
is the first of its consecutive series and add</ul>
if it is the last.) - Convert each occurrence of
n. foo\n
(where the firstn
denotes an Integer such as 12,1729 etc.) as<li>foo</li>
(add<ol>
before theli
if the element is the first of its consecutive series and add</ol>
if it is the last.) - Although there exist many more rules of conversion, you are supposed to follow only the abovementioned ones (for the sake of simplicity).
- You are supposed to output only the corresponding HTML Markup for the given String. No need to add extra elements that are necessary for creating a valid HTML file (like
<body>
,<html>
etc.). However, if they are present in the input String, then you will have to output them too, that is, replace<
and>
with<
and>
, repspectively. - You must NOT use any built-in! (I doubt whether there exists one)
Note : In the abovementioned rules, foo
, bar
and https:\\www.bar.com
are only placeholders. Your program or function must be flexible enough to work for Strings different than these too.
Scoring
This is code-golf, so the shortest code in bytes wins!
Test Cases
"**Hello**" -> "<strong>Hello</strong>"
"#IsThisAwesome?\n" -> "<h1>IsThisAwesome?</h1>"
"> -> "<blockquote><img src='https:\\www.somewhereontheintenet.com' alt='Image'/></blockquote>"
">Some Content\n- Item1\n- Item2\n- Item3\n" -> "<blockquote>Some Content</blockquote><ul><li>Item1</li><li>Item2</li><li>Item3</li></ul>"
"1.Hello\n2.Bye\n3.OK\n" -> "<ol><li>Hello</li><li>Bye</li><li>OK</li></ol>"
Special Thanks to FakeRainBrigand!
This challenge was originally proposed by @FakeRainBrigand in the Sandbox. He granted me the permission to post this challenge on the regular website. Due to unclear and broad specifications, the challenge was closed. Now, it has been reopened with clearer and fewer specs by @Arjun.