my wiki parser- beta modifications

by epinapala

HTML

<textarea id="wikitext" cols="50" rows="18">'''Bold text'''
''Italic text''
<u>Underlined text</u>
<s>Striked text</s>
<nowiki>Insert non-formatted text here</nowiki>'''''South Park''''' is an [[Television in the United States|American]] [[adult animation|adult]] [[animated sitcom]] created by [[Trey Parker]] and [[Matt Stone]] 
* OL 1
* OL 2
** OL 2.1
** OL 2.2

* OL 3
* OL 4  
    
# UL 1
# UL 2
## UL 2.1
## UL 2.2

# UL 3
# UL 4 
</textarea>
<br>
<input id="btnsave" type="button" value="Preview HTML" />
<br>
<hr>
<div id="html"></div>

JavaScript

document.getElementById("btnsave").addEventListener("click", parseWiki, false);



/**
 * This is a JS function to convert yioop wiki markup to
 * html.
 * @param {String} wiki_text tobe parsed as HTML
 * @returns {String} parsed html
 */
function displayParsedContent(wiki_text)
{
    var html = wiki_text;
    
    //note that line breaks from a text area are sent
    //as \r\n , so make sure we clean them up to replace
    //all \r\n with \n
    html = html.replace(/\r\n/g, "\n");
    
    //Regex replace for blocks
    html = html.replace(/(?:^|\n+)([^# =\*<].+)(?:\n+|$)/gm,
            function (match, contents) {
                if (contents.match(/^\^+$/))
                    return contents;
                return "\n<div>" + contents + "</div>\n";
            });
    
        //Regex replace for headings
    html = html.replace(/(?:^|\n)([=]+)(.*)\1/g,
            function (match, contents, t) {
                return '<h'
                        + contents.length + '>'
                        + t
                        + '</h'
                        + contents.length
                        + '>';
            });

    //Regex replace for Bold characters
    html = html.replace(/'''(.*?)'''/g, function (match, contents) {
        return '<strong>' + contents + '</strong>';
    });

    //Regex replace for Italic characters
    html = html.replace(/''(.*?)''/g, function (match, contents) {
        return '<em>' + contents + '</em>';
    });

    html = parseLists(html);

    //Regex replace normal links
    html = html.replace(/[^\[](http[^\[\s]*)/g, function(m, l) {
        // normal link
        return '<a href="' + l + '">' + l + '</a>';
    });
    //Regex replace for external links
    html = html.replace(/[\[](http.*)[!\]]/g, function(m, l) {
        // external link
        var p = l.replace(/[\[\]]/g, '').split(/ /);
        var link = p.shift();
        return '<a href="' + link + '">' + (p.length ? p.join(' ') :
            link) + '</a>';
   ...