code: public final static int readMdLink(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);
              if (ch == '\\' && pos + 1 < in.length())
              {
                  pos = escape(out, in.charAt(pos + 1), pos);
              }
              else
              {
                  boolean endReached = false;
                  switch (ch)
                  {
                  case '(':
                      counter++;
                      break;
                  case ' ':
                      if (counter == 1)
                      {
                          endReached = true;
                      }
                      break;
                  case ')':
                      counter--;
                      if (counter == 0)
                      {
                          endReached = true;
                      }
                      break;
                  }
                  if (endReached)
                  {
                      break;
                  }
                  out.append(ch);
              }
              pos++;
          }
  
          return (pos == in.length()) ? -1 : pos;
      }
docs: Reads a markdown link.
  
  @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.