Esempio n. 1
0
        public Inline Parse(ParserContext context, Subject subject)
        {
            if (!CanParse(subject))
            {
                return(null);
            }

            var saved    = subject.Save();
            var emphChar = subject.Char;
            int startCount;
            int endCount;

            if (CanOpen(subject, emphChar, out startCount))
            {
                subject.Advance(startCount);
                var inlines = new List <Inline>();
                while (!subject.EndOfString)
                {
                    if (CanClose(subject, emphChar, startCount, out endCount))
                    {
                        if (startCount == 1)
                        {
                            subject.Advance(1);
                            return(new Emphasis(inlines));
                        }
                        else if (startCount == 2)
                        {
                            subject.Advance(2);
                            return(new StrongEmphasis(inlines));
                        }
                        else
                        {
                            subject.Advance(endCount);
                            if (endCount == 1)
                            {
                                var emphasis = new Emphasis(inlines);
                                inlines.Clear();
                                inlines.Add(emphasis);
                                startCount = 2;
                            }
                            else if (endCount == 2)
                            {
                                var strongEmphasis = new StrongEmphasis(inlines);
                                inlines.Clear();
                                inlines.Add(strongEmphasis);
                                startCount = 1;
                            }
                            else
                            {
                                return(new StrongEmphasis(new Emphasis(inlines)));
                            }
                        }
                    }
                    if (subject.EndOfString)
                    {
                        break;
                    }
                    else
                    {
                        var inline = Parsers.CommonMarkInlineParser.Parse(context, subject);
                        if (inline == null)
                        {
                            saved.Restore();
                            return(null);
                        }
                        inlines.Add(inline);
                    }
                }
            }

            saved.Restore();
            return(new InlineString(subject.TakeWhile(emphChar)));
        }
Esempio n. 2
0
 public virtual void Visit(StrongEmphasis inline)
 {
     Write("<strong>");
     Write(inline.Inlines);
     Write("</strong>");
 }
 public virtual void Visit(StrongEmphasis inline)
 {
     WriteStartTag(inline, "strong");
     Write(inline.Inlines);
     WriteEndTag(inline, "strong");
 }