public void ShouldReadWhenBIsPrioritaryAndIntersectType3()
        {
            InlineParser parser;
            Column       column;

            Inline[] inlines;


            column = new Column()
            {
                Name = "C1"
            };
            column.InlineFormats.Add("B");
            column.InlineFormats.Add("A");

            parser = new InlineParser(Utils.EmptyRegexBuilder);
            parser.Add("NS", new InlineFormat()
            {
                Name = "B", Pattern = "6789"
            });
            parser.Add("NS", new InlineFormat()
            {
                Name = "A", Pattern = "2345678"
            });

            inlines = parser.Parse("01234567890").ToArray();
            Assert.AreEqual(3, inlines.Length);
            Assert.AreEqual("012345", inlines[0].Value);
            Assert.AreEqual("6789", inlines[1].Value);
            Assert.AreEqual("0", inlines[2].Value);
        }
Exemple #2
0
 protected DelimiterInline(InlineParser parser)
 {
     if (parser is null)
     {
         ThrowHelper.ArgumentNullException(nameof(parser));
     }
     Parser   = parser;
     IsActive = true;
 }
Exemple #3
0
 protected DelimiterInline(InlineParser parser)
 {
     if (parser == null)
     {
         throw new ArgumentNullException(nameof(parser));
     }
     Parser   = parser;
     IsActive = true;
 }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EmphasisDelimiterInline" /> class.
 /// </summary>
 /// <param name="parser">The parser.</param>
 /// <param name="descriptor">The descriptor.</param>
 /// <exception cref="System.ArgumentNullException"></exception>
 public EmphasisDelimiterInline(InlineParser parser, EmphasisDescriptor descriptor) : base(parser)
 {
     if (descriptor == null)
     {
         throw new ArgumentNullException(nameof(descriptor));
     }
     Descriptor    = descriptor;
     DelimiterChar = descriptor.Character;
 }
Exemple #5
0
        internal override bool onMatch(InlineParser parser, Match match)
        {
            var el = Element.withTag("input");

            el.attributes["type"]     = "checkbox";
            el.attributes["disabled"] = "true";
            el.attributes["checked"]  = match.Groups[1].Value.ToLower();
            parser.addNode(el);
            return(true);
        }
        public void ShouldReadHoleAtEnd()
        {
            InlineParser parser;
            Column       column;

            Inline[] inlines;


            column = new Column()
            {
                Name = "C1"
            };
            column.InlineFormats.Add("Red");
            column.InlineFormats.Add("Green");
            column.InlineFormats.Add("Blue");
            column.InlineFormats.Add("White");
            column.InlineFormats.Add("Black");

            parser = new InlineParser(Utils.EmptyRegexBuilder);
            parser.Add("NS", new InlineFormat()
            {
                Name = "Red", Pattern = "Red"
            });
            parser.Add("NS", new InlineFormat()
            {
                Name = "Green", Pattern = "Green"
            });
            parser.Add("NS", new InlineFormat()
            {
                Name = "Blue", Pattern = "Blue"
            });
            parser.Add("NS", new InlineFormat()
            {
                Name = "White", Pattern = "White"
            });
            parser.Add("NS", new InlineFormat()
            {
                Name = "Black", Pattern = "Black"
            });

            inlines = parser.Parse("Red_Green_Blue_Black_White__").ToArray();
            Assert.AreEqual(10, inlines.Length);
            Assert.AreEqual("Red", inlines[0].Value);
            Assert.AreEqual("_", inlines[1].Value);
            Assert.AreEqual("Green", inlines[2].Value);
            Assert.AreEqual("_", inlines[3].Value);
            Assert.AreEqual("Blue", inlines[4].Value);
            Assert.AreEqual("_", inlines[5].Value);
            Assert.AreEqual("Black", inlines[6].Value);
            Assert.AreEqual("_", inlines[7].Value);
            Assert.AreEqual("White", inlines[8].Value);
            Assert.AreEqual("__", inlines[9].Value);
        }
Exemple #7
0
        /// Parses the given inline Markdown [text] to a series of AST nodes.
        List <Node> parseInline(string text)
        {
            try
            {
                var parser = new InlineParser(text, this);
                var nodes  = parser.parse();
                return(nodes);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }

            return(null);
        }
        public void ShouldReadOrderedContiguous()
        {
            InlineParser parser;
            Column       column;

            Inline[] inlines;


            column = new Column()
            {
                Name = "C1"
            };
            column.InlineFormats.Add("Red");
            column.InlineFormats.Add("Green");
            column.InlineFormats.Add("Blue");
            column.InlineFormats.Add("White");
            column.InlineFormats.Add("Black");

            parser = new InlineParser(Utils.EmptyRegexBuilder);
            parser.Add("NS", new InlineFormat()
            {
                Name = "Red", Pattern = "Red"
            });
            parser.Add("NS", new InlineFormat()
            {
                Name = "Green", Pattern = "Green"
            });
            parser.Add("NS", new InlineFormat()
            {
                Name = "Blue", Pattern = "Blue"
            });
            parser.Add("NS", new InlineFormat()
            {
                Name = "White", Pattern = "White"
            });
            parser.Add("NS", new InlineFormat()
            {
                Name = "Black", Pattern = "Black"
            });

            inlines = parser.Parse("RedGreenBlueBlackWhite").ToArray();
            Assert.AreEqual(5, inlines.Length);
            Assert.AreEqual("Red", inlines[0].Value);
            Assert.AreEqual("Green", inlines[1].Value);
            Assert.AreEqual("Blue", inlines[2].Value);
            Assert.AreEqual("Black", inlines[3].Value);
            Assert.AreEqual("White", inlines[4].Value);
        }
        public void ShouldIgnoreCase()
        {
            InlineParser parser;
            Column       column;

            Inline[] inlines;


            column = new Column()
            {
                Name = "C1"
            };
            column.InlineFormats.Add("Red");
            column.InlineFormats.Add("Green");
            column.InlineFormats.Add("Blue");
            column.InlineFormats.Add("White");
            column.InlineFormats.Add("Black");

            parser = new InlineParser(Utils.EmptyRegexBuilder);
            parser.Add("NS", new InlineFormat()
            {
                Name = "Red", Pattern = "red", IgnoreCase = true
            });
            parser.Add("NS", new InlineFormat()
            {
                Name = "Green", Pattern = "grEen", IgnoreCase = true
            });
            parser.Add("NS", new InlineFormat()
            {
                Name = "Blue", Pattern = "blUE", IgnoreCase = true
            });
            parser.Add("NS", new InlineFormat()
            {
                Name = "White", Pattern = "wHitE", IgnoreCase = true
            });
            parser.Add("NS", new InlineFormat()
            {
                Name = "Black", Pattern = "BLACK", IgnoreCase = true
            });

            inlines = parser.Parse("RedGreenBlueBlackWhite").ToArray();
            Assert.AreEqual(5, inlines.Length);
            Assert.AreEqual("Red", inlines[0].Value);
            Assert.AreEqual("Green", inlines[1].Value);
            Assert.AreEqual("Blue", inlines[2].Value);
            Assert.AreEqual("Black", inlines[3].Value);
            Assert.AreEqual("White", inlines[4].Value);
        }
        public void Codeblock()
        {
            /* given */
            var text = new StringRange("`bool IsCode = true;`");
            var parser = new InlineParser();

            /* when */
            var result = parser.Parse(text).ToList();

            /* then */
            result.Should().HaveCount(1);
            result.Should().OnlyContain(span => span is CodeblockSpan);

            // verify link details
            var codeSpan = result.First() as CodeblockSpan;
            codeSpan.ToString().ShouldBeEquivalentTo("bool IsCode = true;");
        }
        public void Text()
        {
            /* given */
            var text = new StringRange("random");
            var parser = new InlineParser();

            /* when */
            List<Span> result = parser.Parse(text).ToList();

            /* then */
            result.Should().HaveCount(1);
            result.Should().ContainItemsAssignableTo<TextSpan>();

            // verify span details
            var span = result.Single() as TextSpan;
            span.Length.ShouldBeEquivalentTo(text.Length);
        }
        public void Link()
        {
            /* given */
            var text = new StringRange("[title](http://something.com)");
            var parser = new InlineParser();

            /* when */
            var result = parser.Parse(text).ToList();

            /* then */
            result.Should().HaveCount(1);
            result.Should().OnlyContain(span => span is LinkSpan);

            // verify link details
            var linkSpan = result.First() as LinkSpan;
            linkSpan.Title.ShouldBeEquivalentTo(new StringRange(text, 1, 5));
            linkSpan.Url.ShouldBeEquivalentTo(new StringRange(text, 8, 27));
        }
        public void TextAndLink()
        {
            /* given */
            var text = new StringRange("0123 [title](http://something.com)");
            var parser = new InlineParser();

            /* when */
            var result = parser.Parse(text).ToList();

            /* then */
            result.Should().HaveCount(2);
            result.First().Should().BeOfType<TextSpan>();
            result.Last().Should().BeOfType<LinkSpan>();

            // verify link details
            var linkSpan = result.Last() as LinkSpan;
            linkSpan.Title.ShouldBeEquivalentTo(new StringRange(text, 6, 10));
            linkSpan.Url.ShouldBeEquivalentTo(new StringRange(text, 13, 32));
        }
Exemple #14
0
        public IInlineParser CreateParser(string DefaultNameSpace, Column Column)
        {
            InlineParser inlineParser;
            InlineFormat inlineColoringRule;

            if (!AssertParameterNotNull(DefaultNameSpace, "DefaultNameSpace"))
            {
                return(null);
            }
            if (!AssertParameterNotNull(Column, "Column"))
            {
                return(null);
            }

            inlineParser = new InlineParser(regexBuilder);
            foreach (string ruleName in Column.InlineFormats)
            {
                try
                {
                    inlineColoringRule = inlineFormatLibraryModule.GetItem(DefaultNameSpace, ruleName);
                }
                catch (Exception ex)
                {
                    Log(LogLevels.Warning, ex.Message);
                    continue;
                }
                try
                {
                    inlineParser.Add(DefaultNameSpace, inlineColoringRule);
                }
                catch (Exception ex)
                {
                    Log(LogLevels.Warning, ex.Message);
                    continue;
                }
            }

            return(inlineParser);
        }
        public static IEnumerable <TResult> Parse <TSource, TResult>(
            this IEnumerable <TSource> source,
            Func <ParserQueryContext <TSource, TSource, IParser <TSource, TSource> >,
                  ParserQueryContext <TSource, TSource, IParser <TSource, TResult> > > grammarSelector)
        {
            Contract.Requires(source != null);
            Contract.Requires(grammarSelector != null);
            Contract.Ensures(Contract.Result <IEnumerable <TResult> >() != null);

            var parser      = new InlineParser <TSource, TResult>();
            var proxyParser = (IParser <TSource, TSource>)parser;

            // The proxy allows the grammar author to use base methods such as Success and Failure
            // while still allowing type inference to work correctly; i.e., the Parse method is unavailable
            // and thus the type of the proxy is based solely on TSource, without requiring TResult to
            // be in an input position in grammarSelector.
            var context = new ParserQueryContext <TSource, TSource, IParser <TSource, TSource> >(
                proxyParser,
                parser.Next);

            var grammar = grammarSelector(context);

            Contract.Assume(grammar != null);

            IParser <TSource, TResult> start = grammar.Value;

            Contract.Assume(start != null);

            // enableBranchOptimizations must be false: See the comments in the first Parse extension for details.
            using (var cursor = source.ToCursor(forwardOnly: true, enableBranchOptimizations: false))
            {
                foreach (var result in parser.Parse(cursor, start))
                {
                    yield return(result);
                }
            }
        }
        public Parsers()
        {
            // Create inline parsers
            LineBreakParser        = new LineBreakParser();
            BacktickParser         = new BacktickParser();
            InlineCodeParser       = new InlineCodeParser();
            EscapedCharParser      = new EscapedCharParser();
            EntityParser           = new EntityParser();
            StrWithEntitiesParser  = new StrWithEntitiesParser(this);
            EscapedStringParser    = new EscapedStringParser(this);
            AutolinkParser         = new AutolinkParser(this);
            AutolinkEmailParser    = new AutolinkEmailParser(this);
            RawHtmlParser          = new RawHtmlParser();
            LinkLabelParser        = new LinkLabelParser(this);
            LinkDestinationParser  = new LinkDestinationParser(this);
            LinkTitleParser        = new LinkTitleParser(this);
            LinkReferenceParser    = new LinkReferenceParser(this);
            LinkParser             = new LinkParser(this);
            ImageParser            = new ImageParser(this);
            ImageReferenceParser   = new ImageReferenceParser(this);
            LinkDefinitionParser   = new LinkDefinitionParser(this);
            EmphasisParser         = new EmphasisParser(this);
            InlineParser           = new InlineParser(this);
            CommonMarkInlineParser = new CommonMarkInlineParser(this);

            // Create block parsers
            IndentedCodeParser = new IndentedCodeParser();
            LazyParagraphContinuationParser = new LazyParagraphContinuationParser();
            BlockQuoteParser     = new BlockQuoteParser();
            ATXHeaderParser      = new ATXHeaderParser();
            FencedCodeParser     = new FencedCodeParser();
            HtmlBlockParser      = new HtmlBlockParser();
            SetExtHeaderParser   = new SetExtHeaderParser();
            HorizontalRuleParser = new HorizontalRuleParser();
            ListParser           = new ListParser();
        }
        public Parsers()
        {
            // Create inline parsers
            LineBreakParser = new LineBreakParser();
            BacktickParser = new BacktickParser();
            InlineCodeParser = new InlineCodeParser();
            EscapedCharParser = new EscapedCharParser();
            EntityParser = new EntityParser();
            StrWithEntitiesParser = new StrWithEntitiesParser(this);
            EscapedStringParser = new EscapedStringParser(this);
            AutolinkParser = new AutolinkParser(this);
            AutolinkEmailParser = new AutolinkEmailParser(this);
            RawHtmlParser = new RawHtmlParser();
            LinkLabelParser = new LinkLabelParser(this);
            LinkDestinationParser = new LinkDestinationParser(this);
            LinkTitleParser = new LinkTitleParser(this);
            LinkReferenceParser = new LinkReferenceParser(this);
            LinkParser = new LinkParser(this);
            ImageParser = new ImageParser(this);
            ImageReferenceParser = new ImageReferenceParser(this);
            LinkDefinitionParser = new LinkDefinitionParser(this);
            EmphasisParser = new EmphasisParser(this);
            InlineParser = new InlineParser(this);
            CommonMarkInlineParser = new CommonMarkInlineParser(this);

            // Create block parsers
            IndentedCodeParser = new IndentedCodeParser();
            LazyParagraphContinuationParser = new LazyParagraphContinuationParser();
            BlockQuoteParser = new BlockQuoteParser();
            ATXHeaderParser = new ATXHeaderParser();
            FencedCodeParser = new FencedCodeParser();
            HtmlBlockParser = new HtmlBlockParser();
            SetExtHeaderParser = new SetExtHeaderParser();
            HorizontalRuleParser = new HorizontalRuleParser();
            ListParser = new ListParser();
        }
 /// <summary>
 /// Finds a parser with the provided type and replaces it with the new parser
 /// </summary>
 /// <typeparam name="T">The type to replace</typeparam>
 /// <param name="parser">The parser to replace the provided one with</param>
 /// <returns>The builder for chaining</returns>
 public ParserPipelineBuilder Replace <T>(InlineParser parser)
     where T : InlineParser
 {
     Replace <T, InlineParser>(InlineParsers, parser);
     return(this);
 }
        public void StrongEmphasis()
        {
            /* given */
            var text = new StringRange("**something important here**");
            var parser = new InlineParser();

            /* when */
            var result = parser.Parse(text).ToList();

            /* then */
            result.Should().HaveCount(3);

            result.First().Should().BeOfType<StrongEmphasis>();
            result.First().Start.ShouldBeEquivalentTo(0);

            result.ElementAt(1).Start.ShouldBeEquivalentTo(2);
            result.ElementAt(1).End.ShouldBeEquivalentTo(25);

            result.Last().Start.ShouldBeEquivalentTo(26);
            result.Last().End.ShouldBeEquivalentTo(27);
            result.Last().Should().BeOfType<StrongEmphasis>();
        }
        public void ReferenceLink()
        {
            /* given */
            var text = new StringRange("[title][0]");
            var parser = new InlineParser();

            /* when */
            var result = parser.Parse(text).ToList();

            /* then */
            result.Should().HaveCount(1);
            result.Should().OnlyContain(span => span is ReferenceLinkSpan);

            // verify link details
            var linkSpan = result.First() as ReferenceLinkSpan;
            linkSpan.Title.ShouldBeEquivalentTo(new StringRange(text, 1, 5));
            linkSpan.Key.ShouldBeEquivalentTo(new StringRange(text, 8, 8));
        }
        public void Image()
        {
            /* given */
            var text = new StringRange("![title](http://something.com)");
            var parser = new InlineParser();

            /* when */
            var result = parser.Parse(text).ToList();

            /* then */
            result.Should().HaveCount(1);
            result.Should().OnlyContain(span => span is ImageSpan);

            // verify link details
            var image = result.First() as ImageSpan;
            image.Title.ShouldBeEquivalentTo(new StringRange(text, 2, 6));
            image.Url.ShouldBeEquivalentTo(new StringRange(text, 9, 28));
        }
        public void Combined()
        {
            /* given */
            var text = new StringRange("emphasis *1234*, **1234**, link [title](link), image ![title](http)");
            var parser = new InlineParser();

            /* when */
            var result = parser.Parse(text).ToList();

            /* then */
            result.Should().HaveCount(12);
        }
Exemple #23
0
 public LinkDelimiterInline(InlineParser parser) : base(parser)
 {
 }
 public PipeTableDelimiterInline(InlineParser parser) : base(parser)
 {
 }
 public OrderedListBuilder()
 {
     _expression = new Regex(@"\G([0-9]{1,3})(\.)(\s)(.*)(\n)");
     _inlineParser = new InlineParser();
 }
 public ParagraphBuilder()
 {
     _inlineParser = new InlineParser();
 }
Exemple #27
0
        internal override void ParseInline(Dictionary <string, LinkReferenceDefinition> linkDefinitions)
        {
            var parser = new InlineParser(parserConfig, linkDefinitions);

            inlines.AddRange(parser.ParseInlineElements(content));
        }
 /// <summary>
 /// Finds a parser with the provided type and adds the new parser before it
 /// </summary>
 /// <typeparam name="T">The type to replace</typeparam>
 /// <param name="parser">The parser to add before</param>
 /// <returns>The builder for chaining</returns>
 public ParserPipelineBuilder AddBefore <T>(InlineParser parser)
     where T : InlineParser
 {
     AddBefore <T, InlineParser>(InlineParsers, parser);
     return(this);
 }
 public UnorderedListBuilder(char startsWith)
 {
     _startsWith = startsWith;
     _inlineParser = new InlineParser();
 }
Exemple #30
0
 public TripleColonInline(InlineParser parser) : base()
 {
 }
Exemple #31
0
        public List <Node> parseInline(string text)
        {
            var parser = new InlineParser(text, this);

            return(parser.parse());
        }