public int parseReference(String s){
  this.input=s;
  this.index=0;
  String dest;
  String title;
  int matchChars;
  int startIndex=index;
  matchChars=parseLinkLabel();
  if (matchChars == 0) {
    return 0;
  }
  String rawLabel=input.substring(0,matchChars);
  if (peek() != ':') {
    return 0;
  }
  index++;
  spnl();
  dest=parseLinkDestination();
  if (dest == null || dest.length() == 0) {
    return 0;
  }
  int beforeTitle=index;
  spnl();
  title=parseLinkTitle();
  if (title == null) {
    index=beforeTitle;
  }
  boolean atLineEnd=true;
  if (index != input.length() && match(LINE_END) == null) {
    if (title == null) {
      atLineEnd=false;
    }
 else {
      title=null;
      index=beforeTitle;
      atLineEnd=match(LINE_END) != null;
    }
  }
  if (!atLineEnd) {
    return 0;
  }
  String normalizedLabel=Escaping.normalizeReference(rawLabel);
  if (normalizedLabel.isEmpty()) {
    return 0;
  }
  if (!referenceMap.containsKey(normalizedLabel)) {
    Link link=new Link(dest,title);
    referenceMap.put(normalizedLabel,link);
  }
  return index - startIndex;
}

public int parseReference ( String s ) { this . input = s ; this . index = 0 ; String dest ; String title ; int matchChars ; int startIndex = index ; matchChars = parseLinkLabel ( ) ; if ( matchChars == 0 ) { return 0 ; } String rawLabel = input . substring ( 0 , matchChars ) ; if ( peek ( ) != ':' ) { return 0 ; } index ++ ; spnl ( ) ; dest = parseLinkDestination ( ) ; if ( dest == null || dest . length ( ) == 0 ) { return 0 ; } int beforeTitle = index ; spnl ( ) ; title = parseLinkTitle ( ) ; if ( title == null ) { index = beforeTitle ; } boolean atLineEnd = true ; if ( index != input . length ( ) && match ( LINE_END ) == null ) { if ( title == null ) { atLineEnd = false ; } else { title = null ; index = beforeTitle ; atLineEnd = match ( LINE_END ) != null ; } } if ( ! atLineEnd ) { return 0 ; } String normalizedLabel = Escaping . normalizeReference ( rawLabel ) ; if ( normalizedLabel . isEmpty ( ) ) { return 0 ; } if ( ! referenceMap . containsKey ( normalizedLabel ) ) { Link link = new Link ( dest , title ) ; referenceMap . put ( normalizedLabel , link ) ; } return index - startIndex ; }
attempt to parse a link reference , modifying the internal reference map .
