示例#1
0
        public override bool Match(InlineProcessor processor, ref StringSlice slice)
        {
            if (!ExtensionsHelper.MatchStart(ref slice, StartString, false))
            {
                return(false);
            }

            var href      = StringBuilderCache.Local();
            var c         = slice.CurrentChar;
            var saved     = slice;
            var startChar = '\0';
            int line;
            int column;

            if (c == '\'' || c == '"')
            {
                startChar = c;
                c         = slice.NextChar();
            }

            while (c != startChar && c != '>')
            {
                href.Append(c);
                c = slice.NextChar();
            }

            if (startChar != '\0')
            {
                if (c != startChar)
                {
                    return(false);
                }

                c = slice.NextChar();
            }

            if (c != '>')
            {
                return(false);
            }
            slice.NextChar();

            var xrefInline = new XrefInline
            {
                Href   = href.ToString().Trim(),
                Span   = new SourceSpan(processor.GetSourcePosition(saved.Start, out line, out column), processor.GetSourcePosition(slice.Start - 1)),
                Line   = line,
                Column = column
            };

            var htmlAttributes = xrefInline.GetAttributes();

            htmlAttributes.AddPropertyIfNotExist("data-throw-if-not-resolved", "True");
            processor.Inline = xrefInline;

            return(true);
        }
示例#2
0
        private bool MatchXrefShortcut(InlineProcessor processor, ref StringSlice slice)
        {
            if (!slice.CurrentChar.IsAlpha())
            {
                return(false);
            }

            var saved = slice;
            int line;
            int column;

            var c    = slice.CurrentChar;
            var href = StringBuilderCache.Local();

            while (!c.IsZero())
            {
                //Meet line ends or whitespaces
                if (c.IsWhiteSpaceOrZero() || StopCharacters.Contains(c))
                {
                    break;
                }

                var nextChar = slice.PeekCharExtra(1);
                if (ContinuableCharacters.Contains(c) && (nextChar.IsWhiteSpaceOrZero() || StopCharacters.Contains(nextChar) || ContinuableCharacters.Contains(nextChar)))
                {
                    break;
                }

                href.Append(c);
                c = slice.NextChar();
            }


            var xrefInline = new XrefInline
            {
                Href   = href.ToString(),
                Span   = new SourceSpan(processor.GetSourcePosition(saved.Start, out line, out column), processor.GetSourcePosition(slice.Start - 1)),
                Line   = line,
                Column = column
            };

            var htmlAttributes = xrefInline.GetAttributes();

            var sourceContent = href.Insert(0, '@');

            htmlAttributes.AddPropertyIfNotExist("data-throw-if-not-resolved", "False");
            htmlAttributes.AddPropertyIfNotExist("data-raw-source", sourceContent.ToString());
            processor.Inline = xrefInline;

            return(true);
        }
示例#3
0
        private bool MatchXrefShortcutWithQuote(InlineProcessor processor, ref StringSlice slice)
        {
            var saved = slice;
            int line;
            int column;

            var startChar = slice.CurrentChar;
            var href      = StringBuilderCache.Local();

            var c = slice.NextChar();

            while (c != startChar && !c.IsNewLine() && !c.IsZero())
            {
                href.Append(c);
                c = slice.NextChar();
            }

            if (c != startChar)
            {
                return(false);
            }

            slice.NextChar();

            var xrefInline = new XrefInline
            {
                Href   = href.ToString(),
                Span   = new SourceSpan(processor.GetSourcePosition(saved.Start, out line, out column), processor.GetSourcePosition(slice.Start - 1)),
                Line   = line,
                Column = column
            };

            var htmlAttributes = xrefInline.GetAttributes();

            var sourceContent = href.Insert(0, startChar).Insert(0, '@').Append(startChar);

            htmlAttributes.AddPropertyIfNotExist("data-throw-if-not-resolved", "False");
            htmlAttributes.AddPropertyIfNotExist("data-raw-source", sourceContent.ToString());
            processor.Inline = xrefInline;

            return(true);
        }
示例#4
0
        public override bool Match(InlineProcessor processor, ref StringSlice slice)
        {
            var c = slice.PeekCharExtra(-1);

            if (c == '\\')
            {
                return(false);
            }

            var saved     = slice;
            var startChar = '\0';
            int line;
            int column;

            c = slice.NextChar();

            if (c == '\'' || c == '"')
            {
                startChar = c;
                c         = slice.NextChar();
            }
            else
            {
                return(false);
            }

            if (!c.IsAlpha())
            {
                return(false);
            }

            var href = StringBuilderCache.Local();

            while (c != startChar && c != '\0' && c != '\n')
            {
                href.Append(c);
                c = slice.NextChar();
            }

            if (c != startChar)
            {
                return(false);
            }

            slice.NextChar();


            var xrefInline = new XrefInline
            {
                Href   = href.ToString().Trim(),
                Span   = new SourceSpan(processor.GetSourcePosition(saved.Start, out line, out column), processor.GetSourcePosition(slice.Start - 1)),
                Line   = line,
                Column = column
            };

            var htmlAttributes = xrefInline.GetAttributes();

            var sourceContent = href.Insert(0, startChar).Insert(0, '@').Append(startChar);

            htmlAttributes.AddPropertyIfNotExist("data-throw-if-not-resolved", "False");
            htmlAttributes.AddPropertyIfNotExist("data-raw-source", sourceContent.ToString());
            processor.Inline = xrefInline;
            return(true);
        }