Пример #1
0
        protected override void Write(NormalizeRenderer renderer, QuoteBlock obj)
        {
            var quoteIndent = renderer.Options.SpaceAfterQuoteBlock ? obj.QuoteChar + " " : obj.QuoteChar.ToString();

            renderer.PushIndent(quoteIndent);
            renderer.WriteChildren(obj);
            renderer.PopIndent();

            renderer.FinishBlock(true);
        }
Пример #2
0
        protected override void Write(NormalizeRenderer renderer, HeadingBlock obj)
        {
            var headingText = obj.Level > 0 && obj.Level <= 6
                ? HeadingTexts[obj.Level - 1]
                : new string('#', obj.Level);

            renderer.Write(headingText).Write(' ');
            renderer.WriteLeafInline(obj);

            renderer.FinishBlock(renderer.Options.EmptyLineAfterHeading);
        }
        protected override void Write(NormalizeRenderer renderer, LinkReferenceDefinition linkDef)
        {
            renderer.EnsureLine();
            renderer.Write('[');
            renderer.Write(linkDef.Label);
            renderer.Write("]: ");

            renderer.Write(linkDef.Url);

            if (linkDef.Title != null)
            {
                renderer.Write(" \"");
                renderer.Write(linkDef.Title.Replace("\"", "\\\""));
                renderer.Write('"');
            }
            renderer.FinishBlock(false);
        }
Пример #4
0
        protected override void Write(NormalizeRenderer renderer, CodeBlock obj)
        {
            var fencedCodeBlock = obj as FencedCodeBlock;

            if (fencedCodeBlock != null)
            {
                var opening = new string(fencedCodeBlock.FencedChar, fencedCodeBlock.FencedCharCount);
                renderer.Write(opening);
                if (fencedCodeBlock.Info != null)
                {
                    renderer.Write(fencedCodeBlock.Info);
                }
                if (!string.IsNullOrEmpty(fencedCodeBlock.Arguments))
                {
                    renderer.Write(" ").Write(fencedCodeBlock.Arguments);
                }

                /* TODO do we need this causes a empty space and would render html attributes to markdown.
                 * var attributes = obj.TryGetAttributes();
                 * if (attributes != null)
                 * {
                 *  renderer.Write(" ");
                 *  renderer.Write(attributes);
                 * }
                 */
                renderer.WriteLine();

                renderer.WriteLeafRawLines(obj, true);
                renderer.Write(opening);
            }
            else
            {
                renderer.WriteLeafRawLines(obj, false, true);
            }

            renderer.FinishBlock(renderer.Options.EmptyLineAfterCodeBlock);
        }
Пример #5
0
 protected override void Write(NormalizeRenderer renderer, HtmlBlock obj)
 {
     renderer.WriteLeafRawLines(obj, true, false);
 }
Пример #6
0
        protected override void Write(NormalizeRenderer renderer, ThematicBreakBlock obj)
        {
            renderer.WriteLine(new string(obj.ThematicChar, obj.ThematicCharCount));

            renderer.FinishBlock(renderer.Options.EmptyLineAfterThematicBreak);
        }
Пример #7
0
 protected override void Write(NormalizeRenderer renderer, ParagraphBlock obj)
 {
     renderer.WriteLeafInline(obj);
     renderer.FinishBlock(!renderer.CompactParagraph);
 }
Пример #8
0
 protected override void Write(NormalizeRenderer renderer, LinkReferenceDefinitionGroup obj)
 {
     renderer.EnsureLine();
     renderer.WriteChildren(obj);
     renderer.FinishBlock(false);
 }
Пример #9
0
        protected override void Write(NormalizeRenderer renderer, ListBlock listBlock)
        {
            renderer.EnsureLine();
            var compact = renderer.CompactParagraph;

            renderer.CompactParagraph = !listBlock.IsLoose;
            if (listBlock.IsOrdered)
            {
                int index = 0;
                if (listBlock.OrderedStart != null)
                {
                    switch (listBlock.BulletType)
                    {
                    case '1':
                        int.TryParse(listBlock.OrderedStart, out index);
                        break;
                    }
                }
                for (var i = 0; i < listBlock.Count; i++)
                {
                    var item     = listBlock[i];
                    var listItem = (ListItemBlock)item;
                    renderer.EnsureLine();

                    renderer.Write(index.ToString(CultureInfo.InvariantCulture));
                    renderer.Write(listBlock.OrderedDelimiter);
                    renderer.Write(' ');
                    renderer.PushIndent(new string(' ', IntLog10Fast(index) + 3));
                    renderer.WriteChildren(listItem);
                    renderer.PopIndent();
                    switch (listBlock.BulletType)
                    {
                    case '1':
                        index++;
                        break;
                    }
                    if (i + 1 < listBlock.Count && listBlock.IsLoose)
                    {
                        renderer.EnsureLine();
                        renderer.WriteLine();
                    }
                }
            }
            else
            {
                for (var i = 0; i < listBlock.Count; i++)
                {
                    var item     = listBlock[i];
                    var listItem = (ListItemBlock)item;
                    renderer.EnsureLine();
                    renderer.Write(renderer.Options.ListItemCharacter ?? listBlock.BulletType);
                    renderer.Write(' ');
                    renderer.PushIndent("  ");
                    renderer.WriteChildren(listItem);
                    renderer.PopIndent();
                    if (i + 1 < listBlock.Count && listBlock.IsLoose)
                    {
                        renderer.EnsureLine();
                        renderer.WriteLine();
                    }
                }
            }
            renderer.CompactParagraph = compact;

            renderer.FinishBlock(true);
        }