Example #1
0
        // Process '*', '**' or '_', '__'
        // This is horrible and probably much better done through regex, but I'm stubborn.
        // For normal cases this routine works as expected.  For unusual cases (eg: overlapped
        // strong and emphasis blocks), the behaviour is probably not the same as the original
        // markdown scanner.

        /*
         *      public Token ProcessEmphasisOld(ref Token prev_single, ref Token prev_double)
         *      {
         *              // Check whitespace before/after
         *              bool bSpaceBefore = !bof && IsLineSpace(CharAtOffset(-1));
         *              bool bSpaceAfter = IsLineSpace(CharAtOffset(1));
         *
         *              // Ignore if surrounded by whitespace
         *              if (bSpaceBefore && bSpaceAfter)
         *              {
         *                      return null;
         *              }
         *
         *              // Save the current character and skip it
         *              char ch = current;
         *              Skip(1);
         *
         *              // Do we have a previous matching single star?
         *              if (!bSpaceBefore && prev_single != null)
         *              {
         *                      // Yes, match them...
         *                      prev_single.type = TokenType.open_em;
         *                      prev_single = null;
         *                      return CreateToken(TokenType.close_em, position - 1, 1);
         *              }
         *
         *              // Is this a double star/under
         *              if (current == ch)
         *              {
         *                      // Skip second character
         *                      Skip(1);
         *
         *                      // Space after?
         *                      bSpaceAfter = IsLineSpace(current);
         *
         *                      // Space both sides?
         *                      if (bSpaceBefore && bSpaceAfter)
         *                      {
         *                              // Ignore it
         *                              return CreateToken(TokenType.Text, position - 2, 2);
         *                      }
         *
         *                      // Do we have a previous matching double
         *                      if (!bSpaceBefore && prev_double != null)
         *                      {
         *                              // Yes, match them
         *                              prev_double.type = TokenType.open_strong;
         *                              prev_double = null;
         *                              return CreateToken(TokenType.close_strong, position - 2, 2);
         *                      }
         *
         *                      if (!bSpaceAfter)
         *                      {
         *                              // Opening double star
         *                              prev_double = CreateToken(TokenType.Text, position - 2, 2);
         *                              return prev_double;
         *                      }
         *
         *                      // Ignore it
         *                      return CreateToken(TokenType.Text, position - 2, 2);
         *              }
         *
         *              // If there's a space before, we can open em
         *              if (!bSpaceAfter)
         *              {
         *                      // Opening single star
         *                      prev_single = CreateToken(TokenType.Text, position - 1, 1);
         *                      return prev_single;
         *              }
         *
         *              // Ignore
         *              Skip(-1);
         *              return null;
         *      }
         */

        // Process auto links eg: <google.com>
        Token ProcessAutoLink()
        {
            if (DisableLinks)
            {
                return(null);
            }

            // Skip the angle bracket and remember the start
            SkipForward(1);
            Mark();

            bool ExtraMode = m_Markdown.ExtraMode;

            // Allow anything up to the closing angle, watch for escapable characters
            while (!eof)
            {
                char ch = current;

                // No whitespace allowed
                if (char.IsWhiteSpace(ch))
                {
                    break;
                }

                // End found?
                if (ch == '>')
                {
                    string url = Utils.UnescapeString(Extract(), ExtraMode);

                    LinkInfo li = null;
                    if (Utils.IsEmailAddress(url))
                    {
                        string link_text;
                        if (url.StartsWith("mailto:"))
                        {
                            link_text = url.Substring(7);
                        }
                        else
                        {
                            link_text = url;
                            url       = "mailto:" + url;
                        }

                        li = new LinkInfo(new LinkDefinition("auto", url, null), link_text);
                    }
                    else if (Utils.IsWebAddress(url))
                    {
                        li = new LinkInfo(new LinkDefinition("auto", url, null), url);
                    }

                    if (li != null)
                    {
                        SkipForward(1);
                        return(CreateToken(TokenType.link, li));
                    }

                    return(null);
                }

                this.SkipEscapableChar(ExtraMode);
            }

            // Didn't work
            return(null);
        }