lib/stmd.js
function() {
  if (this.peek() != '[') {
    return 0;
  }
  var startpos = this.pos;
  var nest_level = 0;
  if (this.label_nest_level > 0) {
    // If we've already checked to the end of this subject
    // for a label, even with a different starting [, we
    // know we won't find one here and we can just return.
    // This avoids lots of backtracking.
    // Note:  nest level 1 would be: [foo [bar]
    //        nest level 2 would be: [foo [bar [baz]
    this.label_nest_level--;
    return 0;
  }
  this.pos++;  // advance past [
  var c;
  while ((c = this.peek()) && (c != ']' || nest_level > 0)) {
    switch (c) {
      case '`':
        this.parseBackticks([]);
        break;
      case '<':
        this.parseAutolink([]) || this.parseHtmlTag([]) || this.parseString([]);
        break;
      case '[':  // nested []
        nest_level++;
        this.pos++;
        break;
      case ']':  // nested []
        nest_level--;
        this.pos++;
        break;
      case '\\':
        this.parseEscaped([]);
        break;
      default:
        this.parseString([]);
    }
  }
  if (c === ']') {
    this.label_nest_level = 0;
    this.pos++; // advance past ]
    return this.pos - startpos;
  } else {
    if (!c) {
      this.label_nest_level = nest_level;
    }
    this.pos = startpos;
    return 0;
  }
}
function() {
  if (this.peek() != '[') {
    return 0;
  }
  var startpos = this.pos;
  var nest_level = 0;
  if (this.label_nest_level > 0) {
    // If we've already checked to the end of this subject
    // for a label, even with a different starting [, we
    // know we won't find one here and we can just return.
    // This avoids lots of backtracking.
    // Note:  nest level 1 would be: [foo [bar]
    //        nest level 2 would be: [foo [bar [baz]
    this.label_nest_level--;
    return 0;
  }
  this.pos++;  // advance past [
  var c;
  while ((c = this.peek()) && (c != ']' || nest_level > 0)) {
    switch (c) {
      case '`':
        this.parseBackticks([]);
        break;
      case '<':
        this.parseAutolink([]) || this.parseHtmlTag([]) || this.parseString([]);
        break;
      case '[':  // nested []
        nest_level++;
        this.pos++;
        break;
      case ']':  // nested []
        nest_level--;
        this.pos++;
        break;
      case '\\':
        this.parseEscaped([]);
        break;
      default:
        this.parseString([]);
    }
  }
  if (c === ']') {
    this.label_nest_level = 0;
    this.pos++; // advance past ]
    return this.pos - startpos;
  } else {
    if (!c) {
      this.label_nest_level = nest_level;
    }
    this.pos = startpos;
    return 0;
  }
}
function ( ) { if ( this . peek ( ) != '[' ) { return 0 ; } var startpos = this . pos ; var nest_level = 0 ; if ( this . label_nest_level > 0 ) { // If we've already checked to the end of this subject // for a label, even with a different starting [, we // know we won't find one here and we can just return. // This avoids lots of backtracking. // Note:  nest level 1 would be: [foo [bar] //        nest level 2 would be: [foo [bar [baz] this . label_nest_level -- ; return 0 ; } this . pos ++ ; // advance past [ var c ; while ( ( c = this . peek ( ) ) && ( c != ']' || nest_level > 0 ) ) { switch ( c ) { case '`' : this . parseBackticks ( [ ] ) ; break ; case '<' : this . parseAutolink ( [ ] ) || this . parseHtmlTag ( [ ] ) || this . parseString ( [ ] ) ; break ; case '[' : // nested [] nest_level ++ ; this . pos ++ ; break ; case ']' : // nested [] nest_level -- ; this . pos ++ ; break ; case '\\' : this . parseEscaped ( [ ] ) ; break ; default : this . parseString ( [ ] ) ; } } if ( c === ']' ) { this . label_nest_level = 0 ; this . pos ++ ; // advance past ] return this . pos - startpos ; } else { if ( ! c ) { this . label_nest_level = nest_level ; } this . pos = startpos ; return 0 ; } }
Attempt to parse a link label, returning number of characters parsed.
Attempt to parse a link label returning number of characters parsed .