Parse the Markdown-like Markup! 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 &lt;em&gt;foo&lt;/em&gt;.
Convert each occurrence of **foo** and __foo__ to &lt;strong&gt;foo&lt;/strong&gt;.
Convert each occurrence of &lt;tab or four spaces here&gt;foo\n to &lt;pre&gt;&lt;code&gt;foo&lt;/code&gt;&lt;/pre&gt;.
Convert each occurrence of #foo\n to &lt;h1&gt;foo&lt;/h1&gt;.
Convert each occurrence of ##bar\n to &lt;h2&gt;bar&lt;/h2&gt;.
Convert each occurrence of ###bar\n to &lt;h3&gt;bar&lt;/h3&gt;.
Convert each occurrence of ####bar\n to &lt;h4&gt;bar&lt;/h4&gt;.
Convert each occurrence of #####bar\n to &lt;h5&gt;bar&lt;/h5&gt;.
Convert each occurrence of ######bar\n to &lt;h6&gt;bar&lt;/h6&gt;.
Convert each occurrence of [foo](https:\\www.bar.com) to &lt;a href="https:\\www.bar.com"&gt;foo&lt;/a&gt;.
Convert each occurrence of ![foo](https:\\www.bar.com) to &lt;img src="https:\\www.bar.com" alt="foo"/&gt;.
Convert each occurrence of &gt;foo\n to &lt;blockquote&gt;foo&lt;/blockquote&gt;.
Convert each occurrence of - foo\n as &lt;li&gt;foo&lt;/li&gt; (add &lt;ul&gt; before the li if the - is the first of its consecutive series and add &lt;/ul&gt; if it is the last.)
Convert each occurrence of n. foo\n (where the first n denotes an Integer such as 12,1729 etc.) as &lt;li&gt;foo&lt;/li&gt; (add &lt;ol&gt; before the li if the element is the first of its consecutive series and add &lt;/ol&gt; 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 &lt;body&gt;, &lt;html&gt; etc.). However, if they are present in the input String, then you will have to output them too, that is, replace &lt; and &gt; with &amp;lt; and &amp;gt;, 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**" -&gt; "&lt;strong&gt;Hello&lt;/strong&gt;"

"#IsThisAwesome?\n" -&gt; "&lt;h1&gt;IsThisAwesome?&lt;/h1&gt;"

"&gt;![Image](http:\\www.somewhereontheinternet.com) -&gt; "&lt;blockquote&gt;&lt;img src='https:\\www.somewhereontheintenet.com' alt='Image'/&gt;&lt;/blockquote&gt;"

"&gt;Some Content\n- Item1\n- Item2\n- Item3\n" -&gt; "&lt;blockquote&gt;Some Content&lt;/blockquote&gt;&lt;ul&gt;&lt;li&gt;Item1&lt;/li&gt;&lt;li&gt;Item2&lt;/li&gt;&lt;li&gt;Item3&lt;/li&gt;&lt;/ul&gt;"

"1.Hello\n2.Bye\n3.OK\n" -&gt; "&lt;ol&gt;&lt;li&gt;Hello&lt;/li&gt;&lt;li&gt;Bye&lt;/li&gt;&lt;li&gt;OK&lt;/li&gt;&lt;/ol&gt;"




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.
PHP, 770 Bytes

Online Version

There are some rules to make html with this markup 

the replacement of blockquote must before all others

h6,h5,h4,h3,h2,h1 is the next order

strong, em

img, a

and (li ,ul, li,ol) or (li ,ol, li,ul)


$s=[
"%&gt;(.*)\n%Us"
,'%(\*|_)\1(.+)\1\1%Us'
,'%(\*|_)(.*)\1%Us'
,'%######(.*)\n%Us'
,'%#####(.*)\n%Us'
,'%####(.*)\n%Us'
,'%###(.*)\n%Us'
,'%##(.*)\n%Us'
,'%#(.*)\n%Us'
,'%- (.*)\n%Us'
,'%(?&lt;!&lt;/li&gt;)&lt;li&gt;%Us'
,'%&lt;/li&gt;(?!&lt;li&gt;)%Us'
,'%\d+\. (.*)\n%Us'
,'%(?&lt;!li&gt;|ul&gt;)&lt;li&gt;%Us'
,'%&lt;/li&gt;(?!&lt;(li|/ul)&gt;)%Us'
,'%(\t|    )(.*)\n%Us'
,'%!\[(.*)\]\((.*)\)%Us'
,'%\[(.*)\]\((.*)\)%Us'
];
$r=[
'&lt;blockquote&gt;\1&lt;/blockquote&gt;'
,'&lt;strong&gt;\2&lt;/strong&gt;'
,'&lt;em&gt;\2&lt;/em&gt;'
,'&lt;h6&gt;\1&lt;/h6&gt;'
,'&lt;h5&gt;\1&lt;/h5&gt;'
,'&lt;h4&gt;\1&lt;/h5&gt;'
,'&lt;h3&gt;\1&lt;/h5&gt;'
,'&lt;h2&gt;\1&lt;/h5&gt;'
,'&lt;h1&gt;\1&lt;/h5&gt;'
,'&lt;li&gt;\1&lt;/li&gt;'
,'&lt;ul&gt;&lt;li&gt;'
,'&lt;/li&gt;&lt;/ul&gt;'
,'&lt;li&gt;\1&lt;/li&gt;'
,'&lt;ol&gt;&lt;li&gt;'
,'&lt;/li&gt;&lt;/ol&gt;'
,'&lt;pre&gt;&lt;code&gt;\2&lt;/code&gt;&lt;/pre&gt;'
,'&lt;img src="\2" alt="\1"/&gt;'
,'&lt;a href="\2"&gt;\1&lt;/a&gt;'
];
echo preg_replace($s,$r,$i);