Attempting minimal Wiki text

Scavenged gist to attempt making a minimal Wikitext parser

by Renoir Boulanger

HTML

<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<textarea id="textarea" onchange="$('#preview').html(wiky.process($(this).val()));" cols="60" rows="20">
  
=== Heading === 
Some content
I would like to add another line

== Subheading ==
Some more content
Some more lines1
:A line with indent
:: A 2-indented line
:: more
:back to 1-indented line

Unicorns are cool!
[[File:https://2.bp.blogspot.com/-tccm-VVZfg0/U01A45Tg-3I/AAAAAAAAEow/MhMFaPGAbIQ/s1600/Screen+Shot+2014-04-15+at+10.22.55+AM.png Unicorns rocks!]]

This is a link:[https://www.google.com Google].
This is a bold link:'''[https://www.google.com Google]'''.
This is a bold-italic link:'''''[https://www.google.com Google]'''''.
This is '''bold''', '''''bold-italic''''', and ''italic''

[[Video:https://www.youtube.com/embed/3yYZa-70u_M]]

# First
# secon
## Second-First
*** First Point
*** Second Point
#### z
#### y
#### x
*** Third Point
## Second-Second [ftp://www.facebook.com FacebookFTP]
## Second-Third [https://www.google.com Google Here] 
# third

{{Page_Title}}
{{Flags
|State=In Progress
|Editorial notes=Add examples
|Checked_Out=No
}}
{{Standardization_Status|W3C Recommendation}}
{{API_Name}}
{{Summary_Section|Border-collapse can be used for collapsing the borders between table cells}}
{{CSS Property
|Initial value=separate
|Applies to=Table and inline-table elements
|Inherited=Yes
|Media=visual
|Computed value=
|Animatable=No
|CSS object model property=borderCollapse
|CSS percentages=
|Values={{CSS Property Value
|Data Type=separate
|Description=Default. Borders are detached (standard HTML). Each table cell has an individual border, with optional space between the borders.
}}{{CSS Property Value
|Data Type=collapse
|Description=Adjacent borders and the space between them are collapsed into a single border.
}}{{CSS Property Value
|Data Type=inherit
|Description=The same specified value as the property for the element's parent will be...

JavaScript

/**
 * Attempt at making a minimal JavaScript Wikitext renderer.
 *
 * See also:
 * https://rawgit.com/chjj/marked/master/marked.min.js
 * https://rawgit.com/joaomsa/txtwiki.js/master/txtwiki.js
 * https://rawgit.com/tanin47/wiky.js/master/wiky.js
 **/

var wiky = {
    options: {
        'link-image': true //Preserve backward compat
    }
};


var NO_LINK = 0,          // outside any link - ignoring...
    IN_LINK = 1;          // inside link

/**
 * WikitextLink handler. Unfinished and unused class
 *
 * Variant 1:
 * '[[Special:Help|Text help]]'.split(/(\[\[?|\||\]\]?)/)
 * > ["", "[[", "Special:Help", "|", "Text help", "]]", ""]
 *
 * Variant 2:
 * '[google.com hi bob]'.split(/(\[\[?|\||\]\]?)/)
 * > ["", "[", "google.com hi bob", "]", ""]
 *
 * Variant 3:
 * 
 * '[google.com hi bob]'.split(/(\[\[?|[\||\s]|\]\]?)/)
 * > ["", "[", "google.com", " ", "hi", " ", "bob", "]", ""]
 *
 * '[[Special:Help|Text help]]'.split(/(\[\[?|[\||\s]|\]\]?)/)
 * > ["", "[[", "Special:Help", "|", "Text", " ", "help", "]]", ""]
 */
function WikitextLink(wikitext) {

  var tokens = wikitext.split(/(\[\[?|[\||\s]|\]\]?)/),
      i = -1, end = tokens.length - 1,
      hit_first_space = false,
      link_text = '',
      token, next, state = NO_LINK,
      work = [], workChain = [], stateChain = [];

  function trim(value) {
    return value.replace(/^\s*/, '').replace(/\s*$/, '');
  }

  // get next non empty token
  function getNext(next) {
    while (!next && i < end) next = trim(tokens[++i]);
    return next;
  }

  // go into tpl / list of arguments
  function goDown(newState, newWork, newWorkKey) {
    stateChain.push(state);
    workChain.push(work);

    if (newWorkKey) {
      work[newWorkKey] = newWork;
    } else {
      work.push(newWork);
    }

    work = newWork;
    state = newState;
  }

  // jump up from tpl / list of arguments
  function goUp() {
    work = workChain.pop();
    state = stateChain.pop();
  }
 
  while ((token = getNext())) {
    //console.log('while...