Exemple #1
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);
        }
Exemple #2
0
        protected override void Write(NormalizeRenderer renderer, ThematicBreakBlock obj)
        {
            renderer.WriteLine(new string(obj.ThematicChar, obj.ThematicCharCount));

            renderer.FinishBlock(renderer.Options.EmptyLineAfterThematicBreak);
        }
Exemple #3
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);
        }