code: public final static int readMdLinkId(final StringBuilder out, final String in, final int start)
      {
          int pos = start;
          int counter = 1;
          while (pos < in.length())
          {
              final char ch = in.charAt(pos);
              boolean endReached = false;
              switch (ch)
              {
              case '\n':
                  out.append(' ');
                  break;
              case '[':
                  counter++;
                  out.append(ch);
                  break;
              case ']':
                  counter--;
                  if (counter == 0)
                  {
                      endReached = true;
                  }
                  else
                  {
                      out.append(ch);
                  }
                  break;
              default:
                  out.append(ch);
                  break;
              }
              if (endReached)
              {
                  break;
              }
              pos++;
          }
  
          return (pos == in.length()) ? -1 : pos;
      }
docs: Reads a markdown link ID.
  
  @param out
  The StringBuilder to write to.
  @param in
  Input String.
  @param start
  Starting position.
  @return The new position or -1 if this is no valid markdown link ID.