lib/stmd.js
function(inlines) {
  var startpos = this.pos;
  var reflabel;
  var n;
  var dest;
  var title;

  n = this.parseLinkLabel();
  if (n === 0) {
    return 0;
  }
  var afterlabel = this.pos;
  var rawlabel = this.subject.substr(startpos, n);

  // if we got this far, we've parsed a label.
  // Try to parse an explicit link: [label](url "title")
  if (this.peek() == '(') {
    this.pos++;
    if (this.spnl() &&
        ((dest = this.parseLinkDestination()) !== null) &&
        this.spnl() &&
        // make sure there's a space before the title:
        (/^\s/.test(this.subject.charAt(this.pos - 1)) &&
         (title = this.parseLinkTitle() || '') || true) &&
        this.spnl() &&
        this.match(/^\)/)) {
        inlines.push({ t: 'Link',
                       destination: dest,
                       title: title,
                       label: parseRawLabel(rawlabel) });
        return this.pos - startpos;
     } else {
        this.pos = startpos;
        return 0;
     }
  }
  // If we're here, it wasn't an explicit link. Try to parse a reference link.
  // first, see if there's another label
  var savepos = this.pos;
  this.spnl();
  var beforelabel = this.pos;
  n = this.parseLinkLabel();
  if (n == 2) {
    // empty second label
    reflabel = rawlabel;
  } else if (n > 0) {
    reflabel = this.subject.slice(beforelabel, beforelabel + n);
  } else {
    this.pos = savepos;
    reflabel = rawlabel;
  }
  // lookup rawlabel in refmap
  var link = this.refmap[normalizeReference(reflabel)];
  if (link) {
    inlines.push({t: 'Link',
                  destination: link.destination,
                  title: link.title,
                  label: parseRawLabel(rawlabel) });
    return this.pos - startpos;
  } else {
    this.pos = startpos;
    return 0;
  }
  // Nothing worked, rewind:
  this.pos = startpos;
  return 0;
}
function(inlines) {
  var startpos = this.pos;
  var reflabel;
  var n;
  var dest;
  var title;

  n = this.parseLinkLabel();
  if (n === 0) {
    return 0;
  }
  var afterlabel = this.pos;
  var rawlabel = this.subject.substr(startpos, n);

  // if we got this far, we've parsed a label.
  // Try to parse an explicit link: [label](url "title")
  if (this.peek() == '(') {
    this.pos++;
    if (this.spnl() &&
        ((dest = this.parseLinkDestination()) !== null) &&
        this.spnl() &&
        // make sure there's a space before the title:
        (/^\s/.test(this.subject.charAt(this.pos - 1)) &&
         (title = this.parseLinkTitle() || '') || true) &&
        this.spnl() &&
        this.match(/^\)/)) {
        inlines.push({ t: 'Link',
                       destination: dest,
                       title: title,
                       label: parseRawLabel(rawlabel) });
        return this.pos - startpos;
     } else {
        this.pos = startpos;
        return 0;
     }
  }
  // If we're here, it wasn't an explicit link. Try to parse a reference link.
  // first, see if there's another label
  var savepos = this.pos;
  this.spnl();
  var beforelabel = this.pos;
  n = this.parseLinkLabel();
  if (n == 2) {
    // empty second label
    reflabel = rawlabel;
  } else if (n > 0) {
    reflabel = this.subject.slice(beforelabel, beforelabel + n);
  } else {
    this.pos = savepos;
    reflabel = rawlabel;
  }
  // lookup rawlabel in refmap
  var link = this.refmap[normalizeReference(reflabel)];
  if (link) {
    inlines.push({t: 'Link',
                  destination: link.destination,
                  title: link.title,
                  label: parseRawLabel(rawlabel) });
    return this.pos - startpos;
  } else {
    this.pos = startpos;
    return 0;
  }
  // Nothing worked, rewind:
  this.pos = startpos;
  return 0;
}
function ( inlines ) { var startpos = this . pos ; var reflabel ; var n ; var dest ; var title ; n = this . parseLinkLabel ( ) ; if ( n === 0 ) { return 0 ; } var afterlabel = this . pos ; var rawlabel = this . subject . substr ( startpos , n ) ; // if we got this far, we've parsed a label. // Try to parse an explicit link: [label](url "title") if ( this . peek ( ) == '(' ) { this . pos ++ ; if ( this . spnl ( ) && ( ( dest = this . parseLinkDestination ( ) ) !== null ) && this . spnl ( ) && // make sure there's a space before the title: ( / ^\s / . test ( this . subject . charAt ( this . pos - 1 ) ) && ( title = this . parseLinkTitle ( ) || '' ) || true ) && this . spnl ( ) && this . match ( / ^\) / ) ) { inlines . push ( { t : 'Link' , destination : dest , title : title , label : parseRawLabel ( rawlabel ) } ) ; return this . pos - startpos ; } else { this . pos = startpos ; return 0 ; } } // If we're here, it wasn't an explicit link. Try to parse a reference link. // first, see if there's another label var savepos = this . pos ; this . spnl ( ) ; var beforelabel = this . pos ; n = this . parseLinkLabel ( ) ; if ( n == 2 ) { // empty second label reflabel = rawlabel ; } else if ( n > 0 ) { reflabel = this . subject . slice ( beforelabel , beforelabel + n ) ; } else { this . pos = savepos ; reflabel = rawlabel ; } // lookup rawlabel in refmap var link = this . refmap [ normalizeReference ( reflabel ) ] ; if ( link ) { inlines . push ( { t : 'Link' , destination : link . destination , title : link . title , label : parseRawLabel ( rawlabel ) } ) ; return this . pos - startpos ; } else { this . pos = startpos ; return 0 ; } // Nothing worked, rewind: this . pos = startpos ; return 0 ; }
Attempt to parse a link.  If successful, add the link to inlines.
Attempt to parse a link . If successful add the link to inlines .