Ejemplo n.º 1
0
        public override bool Match(InlineProcessor processor, ref StringSlice slice)
        {
            var startPosition = processor.GetSourcePosition(slice.Start, out var line, out var column);

            if (!ExtensionsHelper.MatchStart(ref slice, StartString, false))
            {
                return(false);
            }

            if (slice.CurrentChar == '-')
            {
                slice.NextChar();
            }

            string title = null, path = null;

            if (!ExtensionsHelper.MatchLink(ref slice, ref title, ref path) || !ExtensionsHelper.MatchInclusionEnd(ref slice))
            {
                return(false);
            }

            processor.Inline = new InclusionInline
            {
                Title            = title,
                IncludedFilePath = path,
                Line             = line,
                Column           = column,
                Span             = new SourceSpan(startPosition, processor.GetSourcePosition(slice.Start - 1)),
                IsClosed         = true,
            };

            return(true);
        }
Ejemplo n.º 2
0
        public override BlockState TryOpen(BlockProcessor processor)
        {
            if (processor.IsCodeIndent)
            {
                return(BlockState.None);
            }

            // [!include[<title>](<filepath>)]
            var column  = processor.Column;
            var line    = processor.Line;
            var command = line.ToString();

            if (!ExtensionsHelper.MatchStart(ref line, StartString, false))
            {
                return(BlockState.None);
            }
            else
            {
                if (line.CurrentChar == '+')
                {
                    line.NextChar();
                }
            }

            string title = null, path = null;

            if (!ExtensionsHelper.MatchLink(ref line, ref title, ref path) || !ExtensionsHelper.MatchInclusionEnd(ref line))
            {
                return(BlockState.None);
            }

            while (line.CurrentChar.IsSpaceOrTab())
            {
                line.NextChar();
            }
            if (line.CurrentChar != '\0')
            {
                return(BlockState.None);
            }

            processor.NewBlocks.Push(new InclusionBlock(this)
            {
                Title            = title,
                IncludedFilePath = path,
                Line             = processor.LineIndex,
                Column           = column,
            });

            return(BlockState.BreakDiscard);
        }