コード例 #1
0
        protected override void Write(HtmlRenderer renderer, ParagraphBlock obj)
        {
            if (!renderer.ImplicitParagraph && renderer.EnableHtmlForBlock)
            {
                if (!renderer.IsFirstInContainer)
                {
                    renderer.EnsureLine();
                }

                renderer.Write("<div").WriteAttributes(obj).Write(">");
            }

            renderer.WriteLeafInline(obj);
            if (!renderer.ImplicitParagraph && renderer.EnableHtmlForBlock)
            {
                renderer.WriteLine("</div>");
                if (!renderer.IsLastInContainer)
                {
                    renderer.WriteLine("<div><br/></div>");
                }
                else
                {
                    renderer.EnsureLine();
                }
            }
        }
コード例 #2
0
        protected override void Write(HtmlRenderer renderer, CodeBlock obj)
        {
            renderer.EnsureLine();

            var fencedCodeBlock = obj as FencedCodeBlock;

            if (fencedCodeBlock?.Info != null && BlocksAsDiv.Contains(fencedCodeBlock.Info))
            {
                var infoPrefix = (obj.Parser as FencedCodeBlockParser)?.InfoPrefix ??
                                 FencedCodeBlockParser.DefaultInfoPrefix;

                // We are replacing the HTML attribute `language-mylang` by `mylang` only for a div block
                // NOTE that we are allocating a closure here

                if (renderer.EnableHtmlForBlock)
                {
                    renderer.Write("<div")
                    .WriteAttributes(obj.TryGetAttributes(),
                                     cls => cls.StartsWith(infoPrefix) ? cls.Substring(infoPrefix.Length) : cls)
                    .Write(">");
                }

                renderer.WriteLeafRawLines(obj, true, true, true);

                if (renderer.EnableHtmlForBlock)
                {
                    renderer.WriteLine("</div>");
                }
            }
            else
            {
                if (renderer.EnableHtmlForBlock)
                {
                    renderer.Write("<pre");

                    if (OutputAttributesOnPre)
                    {
                        renderer.WriteAttributes(obj);
                    }

                    renderer.Write("><code");

                    if (!OutputAttributesOnPre)
                    {
                        renderer.WriteAttributes(obj);
                    }

                    renderer.Write(">");
                }

                renderer.WriteLeafRawLines(obj, true, true);

                if (renderer.EnableHtmlForBlock)
                {
                    renderer.WriteLine("</code></pre>");
                }
            }

            renderer.EnsureLine();
        }
コード例 #3
0
ファイル: ListRenderer.cs プロジェクト: olesar/Altaxo
        protected override void Write(HtmlRenderer renderer, ListBlock listBlock)
        {
            renderer.EnsureLine();
            if (renderer.EnableHtmlForBlock)
            {
                if (listBlock.IsOrdered)
                {
                    renderer.Write("<ol");
                    if (listBlock.BulletType != '1')
                    {
                        renderer.Write(" type=\"").Write(listBlock.BulletType).Write("\"");
                    }

                    if (listBlock.OrderedStart != null && (listBlock.OrderedStart != "1"))
                    {
                        renderer.Write(" start=\"").Write(listBlock.OrderedStart).Write("\"");
                    }
                    renderer.WriteAttributes(listBlock);
                    renderer.WriteLine(">");
                }
                else
                {
                    renderer.Write("<ul");
                    renderer.WriteAttributes(listBlock);
                    renderer.WriteLine(">");
                }
            }

            foreach (var item in listBlock)
            {
                var listItem         = (ListItemBlock)item;
                var previousImplicit = renderer.ImplicitParagraph;
                renderer.ImplicitParagraph = !listBlock.IsLoose;

                renderer.EnsureLine();
                if (renderer.EnableHtmlForBlock)
                {
                    renderer.Write("<li").WriteAttributes(listItem).Write(">");
                }

                renderer.WriteChildren(listItem);

                if (renderer.EnableHtmlForBlock)
                {
                    renderer.WriteLine("</li>");
                }

                renderer.EnsureLine();
                renderer.ImplicitParagraph = previousImplicit;
            }

            if (renderer.EnableHtmlForBlock)
            {
                renderer.WriteLine(listBlock.IsOrdered ? "</ol>" : "</ul>");
            }

            renderer.EnsureLine();
        }
コード例 #4
0
        protected override void Write(HtmlRenderer renderer, CodeBlock obj)
        {
            renderer.EnsureLine();

            var fencedCodeBlock = obj as FencedCodeBlock;

            if (fencedCodeBlock?.Info != null && BlocksAsDiv.Contains(fencedCodeBlock.Info))
            {
                var infoPrefix = (obj.Parser as FencedCodeBlockParser)?.InfoPrefix ??
                                 FencedCodeBlockParser.DefaultInfoPrefix;

                if (renderer.EnableHtmlForBlock)
                {
                    renderer.Write("<div")
                    .WriteAttributes(obj.TryGetAttributes(),
                                     cls => cls.StartsWith(infoPrefix, StringComparison.Ordinal) ? cls.Substring(infoPrefix.Length) : cls)
                    .Write('>');
                }

                renderer.WriteLeafRawLines(obj, true, true, true);

                if (renderer.EnableHtmlForBlock)
                {
                    renderer.WriteLine("</div>");
                }
            }
            else
            {
                if (renderer.EnableHtmlForBlock)
                {
                    renderer.Write("<pre ");

                    if (OutputAttributesOnPre)
                    {
                        renderer.WriteAttributes(obj);
                    }

                    WriteHighlightedCodeLines(renderer, fencedCodeBlock);

                    if (!OutputAttributesOnPre)
                    {
                        renderer.WriteAttributes(obj);
                    }

                    renderer.Write('>');
                }

                renderer.WriteLeafRawLines(obj, true, true);

                if (renderer.EnableHtmlForBlock)
                {
                    renderer.WriteLine("</code></pre>");
                }
            }

            renderer.EnsureLine();
        }
コード例 #5
0
    protected override void Write(HtmlRenderer renderer, HeadingBlock obj)
    {
        int    index       = obj.Level - 1;
        string headingText = (uint)index < (uint)HeadingTexts.Length
                        ? HeadingTexts[index]
                        : $"h{obj.Level.ToString(CultureInfo.InvariantCulture)}";

        if (renderer.EnableHtmlForBlock)
        {
            renderer.Write("<").Write(headingText).WriteAttributes(obj).Write('>');
            renderer.Write(HeaderTextTag);
        }

        renderer.WriteLeafInline(obj);

        if (renderer.EnableHtmlForBlock)
        {
            renderer.Write("</span>");
            // Append Hash permalink to ID if one exists.
            string?id = obj.TryGetAttributes()?.Id;
            if (!string.IsNullOrEmpty(id))
            {
                renderer.Write("<a class=\"header-permalink\" onclick=\"loadHash('#").Write(id).Write("')\">#</a>");
            }

            renderer.Write("</").Write(headingText).WriteLine(">");
        }

        renderer.EnsureLine();
    }
コード例 #6
0
        protected override void Write(HtmlRenderer renderer, MathBlock obj)
        {
            bool addBegin  = false;
            var  firstLine = obj.Lines.ToString();

            if (!firstLine.TrimStart().StartsWith("\\begin"))
            {
                addBegin = true;
            }

            renderer.EnsureLine();
            renderer.Write("<div").WriteAttributes(obj).Write(">");

            if (addBegin)
            {
                renderer.WriteLine("\\begin{equation}");
            }
            renderer.WriteLeafRawLines(obj, true, true);
            if (addBegin)
            {
                renderer.WriteLine("\n\\end{equation}");
            }

            renderer.WriteLine("</div>");
        }
コード例 #7
0
        protected override void Write(HtmlRenderer renderer, HeadingBlock obj)
        {
            int    index        = obj.Level - 1;
            int    d2lHeadingId = Math.Min(index, D2lHeadings.Length);
            string headingText  = "h" + obj.Level.ToString();
            var    attributes   = obj.GetAttributes();

            attributes.AddClass(D2lHeadings[d2lHeadingId]);
            attributes.AddClass("doc-fragment-heading");

            if (renderer.EnableHtmlForBlock)
            {
                renderer.Write("<").Write(headingText).WriteAttributes(obj).Write(">");
                renderer.Write(linkTemplate.Replace("{id}", attributes.Id));
            }

            renderer.WriteLeafInline(obj);

            if (renderer.EnableHtmlForBlock)
            {
                renderer.Write("</").Write(headingText).WriteLine(">");
            }

            renderer.EnsureLine();
        }
コード例 #8
0
 protected override void Write(HtmlRenderer renderer, MathBlock obj)
 {
     renderer.EnsureLine();
     renderer.Write("<pre").WriteAttributes(obj).WriteLine(">");
     renderer.WriteLeafRawLines(obj, true, true);
     renderer.WriteLine("</pre>");
 }
        protected override void Write(HtmlRenderer renderer, CodeBlock codeBlock)
        {
            renderer.EnsureLine();
            renderer.Write("<pre");

            var    attributes = codeBlock.TryGetAttributes();
            string cssClass   = attributes?.Classes.FirstOrDefault();

            if (cssClass != null)
            {
                string langAttributeValue = TranslateCodeClass(cssClass);
                renderer.Write(" lang=\"");
                renderer.WriteEscape(langAttributeValue);
                renderer.Write("\" ");
            }

            if (attributes?.Id != null)
            {
                renderer.Write(" id=\"").WriteEscape(attributes.Id).Write("\" ");
            }

            renderer.Write(">");

            renderer.WriteLeafRawLines(codeBlock, true, true);
            renderer.WriteLine("</pre>");
        }
コード例 #10
0
        protected override void Write(HtmlRenderer renderer, CustomContainer obj)
        {
            renderer.EnsureLine();

            if (obj.Info == "image")
            {
                //just take alt-text and source from obj.Arguments
                //html should be src and alt
                //img ends with just >
                if (renderer.EnableHtmlForBlock)
                {
                    (string alt, string src, string border) = extractParamatersFromImage(obj.Arguments);
                    renderer
                    .Write("<p><img ")
                    .Write(string.IsNullOrEmpty(alt) ? "" : "alt=" + alt + " ")
                    .Write("src=" + src + " ")
                    .Write("border=" + border)
                    .Write("/></p>");
                }
                renderer.WriteChildren(obj);
            }
            else
            {
                if (renderer.EnableHtmlForBlock)
                {
                    renderer.Write("<div").WriteAttributes(obj).Write(">");
                }
                // We don't escape a CustomContainer
                renderer.WriteChildren(obj);
                if (renderer.EnableHtmlForBlock)
                {
                    renderer.WriteLine("</div>");
                }
            }
        }
コード例 #11
0
        protected override void Write(HtmlRenderer renderer, QuoteSectionNoteBlock obj)
        {
            renderer.EnsureLine();
            switch (obj.QuoteType)
            {
            case QuoteSectionNoteType.MarkdownQuote:
                WriteQuote(renderer, obj);
                break;

            case QuoteSectionNoteType.DFMSection:
                WriteSection(renderer, obj);
                break;

            case QuoteSectionNoteType.DFMNote:
                WriteNote(renderer, obj);
                break;

            case QuoteSectionNoteType.DFMVideo:
                WriteVideo(renderer, obj);
                break;

            default:
                break;
            }
        }
コード例 #12
0
 protected override void Write(HtmlRenderer renderer, FigureCaption obj)
 {
     renderer.EnsureLine();
     renderer.Write("<figcaption").WriteAttributes(obj).Write(">");
     renderer.WriteLeafInline(obj);
     renderer.WriteLine("</figcaption>");
 }
コード例 #13
0
        protected override void Write(HtmlRenderer renderer, CodeBlock obj)
        {
            renderer.EnsureLine();

            if (_blocksAsDiv is not null && (obj as FencedCodeBlock)?.Info is string info && _blocksAsDiv.Contains(info))
            {
                var infoPrefix = (obj.Parser as FencedCodeBlockParser)?.InfoPrefix ??
                                 FencedCodeBlockParser.DefaultInfoPrefix;

                // We are replacing the HTML attribute `language-mylang` by `mylang` only for a div block
                // NOTE that we are allocating a closure here

                if (renderer.EnableHtmlForBlock)
                {
                    renderer.Write("<div")
                    .WriteAttributes(obj.TryGetAttributes(),
                                     cls => cls.StartsWith(infoPrefix, StringComparison.Ordinal) ? cls.Substring(infoPrefix.Length) : cls)
                    .WriteRaw('>');
                }

                renderer.WriteLeafRawLines(obj, true, true, true);

                if (renderer.EnableHtmlForBlock)
                {
                    renderer.WriteLine("</div>");
                }
            }
コード例 #14
0
ファイル: RCodeBlockRenderer.cs プロジェクト: skrutsick/RTVS
        protected override void Write(HtmlRenderer renderer, CodeBlock codeBlock)
        {
            renderer.EnsureLine();

            var fencedCodeBlock = codeBlock as FencedCodeBlock;
            var info            = fencedCodeBlock?.Info;

            if (info != null && (info.StartsWithIgnoreCase("{r") || info.StartsWithIgnoreCase("{ r")))
            {
                var text       = fencedCodeBlock.GetText();
                var rCodeBlock = new RCodeBlock(_blockNumber, text, fencedCodeBlock.Arguments);

                var result = GetCachedResult(_blockNumber, rCodeBlock.Hash, fencedCodeBlock);
                if (result != null)
                {
                    WriteBlockContent(renderer, _blockNumber, text);
                    renderer.Write(result);
                }
                else
                {
                    var elementId = rCodeBlock.HtmlElementId;
                    _blocks.Add(rCodeBlock);

                    WriteBlockContent(renderer, _blockNumber, text);
                    // Write placeholder first. We will insert actual data when the evaluation is done.
                    renderer.Write(GetBlockPlaceholder(elementId, text));
                }
                _blockNumber++;
            }
        }
コード例 #15
0
 protected override void Write(HtmlRenderer renderer, Figure obj)
 {
     renderer.EnsureLine();
     renderer.Write("<figure").WriteAttributes(obj).WriteLine(">");
     renderer.WriteChildren(obj);
     renderer.WriteLine("</figure>");
 }
コード例 #16
0
ファイル: HeadingRenderer.cs プロジェクト: xoofx/markdig
        protected override void Write(HtmlRenderer renderer, HeadingBlock obj)
        {
            int index = obj.Level - 1;

            string[] headings    = HeadingTexts;
            string   headingText = ((uint)index < (uint)headings.Length)
                ? headings[index]
                : $"h{obj.Level}";

            if (renderer.EnableHtmlForBlock)
            {
                renderer.Write('<');
                renderer.WriteRaw(headingText);
                renderer.WriteAttributes(obj);
                renderer.WriteRaw('>');
            }

            renderer.WriteLeafInline(obj);

            if (renderer.EnableHtmlForBlock)
            {
                renderer.Write("</");
                renderer.WriteRaw(headingText);
                renderer.WriteLine('>');
            }

            renderer.EnsureLine();
        }
コード例 #17
0
 protected override void Write(HtmlRenderer renderer, Table table)
 {
     renderer.EnsureLine();
     renderer.WriteLine("<div class=\"table-responsive\">");
     base.Write(renderer, table);
     renderer.WriteLine("</div>");
 }
コード例 #18
0
 protected override void Write(HtmlRenderer renderer, CustomContainer obj)
 {
     renderer.EnsureLine();
     renderer.Write("<div").WriteAttributes(obj).Write(">");
     // We don't escape a CustomContainer
     renderer.WriteChildren(obj);
     renderer.WriteLine("</div>");
 }
コード例 #19
0
ファイル: QuoteBlockRenderer.cs プロジェクト: ywscr/markdig
        protected override void Write(HtmlRenderer renderer, QuoteBlock obj)
        {
            renderer.EnsureLine();
            if (renderer.EnableHtmlForBlock)
            {
                renderer.Write("<blockquote").WriteAttributes(obj).WriteLine(">");
            }
            var savedImplicitParagraph = renderer.ImplicitParagraph;

            renderer.ImplicitParagraph = false;
            renderer.WriteChildren(obj);
            renderer.ImplicitParagraph = savedImplicitParagraph;
            if (renderer.EnableHtmlForBlock)
            {
                renderer.WriteLine("</blockquote>");
            }
            renderer.EnsureLine();
        }
コード例 #20
0
        protected override void Write(HtmlRenderer renderer, CodeBlock obj)
        {
            renderer.EnsureLine();

            var fencedCodeBlock = obj as FencedCodeBlock;

            if (fencedCodeBlock?.Info != null)
            {
                renderer.Write($"<pre class=\"brush: {fencedCodeBlock.Info}; gutter: false; toolbar: false; \">");
                renderer.EnsureLine();
                renderer.WriteLeafRawLines(obj, true, true);
                renderer.WriteLine("</pre>");
            }
            else
            {
                originalCodeBlockRenderer.Write(renderer, obj);
            }
        }
コード例 #21
0
        protected override void Write(HtmlRenderer renderer, FooterBlock footer)
        {
            renderer.EnsureLine();
            renderer.Write("<footer").WriteAttributes(footer).Write(">");
            var implicitParagraph = renderer.ImplicitParagraph;

            renderer.ImplicitParagraph = true;
            renderer.WriteChildren(footer);
            renderer.ImplicitParagraph = implicitParagraph;
            renderer.WriteLine("</footer>");
        }
コード例 #22
0
        protected override void Write(HtmlRenderer renderer, QuoteSectionNoteBlock obj)
        {
            renderer.EnsureLine();
            bool savedImplicitParagraph;

            switch (obj.QuoteType)
            {
            case QuoteSectionNoteType.MarkdownQuote:
                renderer.Write("<blockquote").WriteAttributes(obj).WriteLine(">");
                savedImplicitParagraph     = renderer.ImplicitParagraph;
                renderer.ImplicitParagraph = false;
                renderer.WriteChildren(obj);
                renderer.ImplicitParagraph = savedImplicitParagraph;
                renderer.WriteLine("</blockquote>");
                break;

            case QuoteSectionNoteType.DFMSection:
                string attribute = string.IsNullOrEmpty(obj.SectionAttributeString) ?
                                   string.Empty :
                                   $" {obj.SectionAttributeString}";
                renderer.Write("<div").Write(attribute).WriteAttributes(obj).WriteLine(">");
                savedImplicitParagraph     = renderer.ImplicitParagraph;
                renderer.ImplicitParagraph = false;
                renderer.WriteChildren(obj);
                renderer.ImplicitParagraph = savedImplicitParagraph;
                renderer.WriteLine("</div>");
                break;

            case QuoteSectionNoteType.DFMNote:
                string noteHeading = string.Empty;
                if (_tokens?.TryGetValue(obj.NoteTypeString.ToLower(), out noteHeading) != true)
                {
                    noteHeading = $"<h5>{obj.NoteTypeString.ToUpper()}</h5>";
                }
                ;
                renderer.Write("<div").Write($" class=\"{obj.NoteTypeString.ToUpper()}\"").WriteAttributes(obj).WriteLine(">");
                savedImplicitParagraph     = renderer.ImplicitParagraph;
                renderer.ImplicitParagraph = false;
                renderer.WriteLine(noteHeading);
                renderer.WriteChildren(obj);
                renderer.ImplicitParagraph = savedImplicitParagraph;
                renderer.WriteLine("</div>");
                break;

            case QuoteSectionNoteType.DFMVideo:
                renderer.Write("<div class=\"embeddedvideo\"").WriteAttributes(obj).Write(">");
                renderer.Write($"<iframe src=\"{obj.VideoLink}\" frameborder=\"0\" allowfullscreen=\"true\"></iframe>");
                renderer.WriteLine("</div>");
                break;

            default:
                break;
            }
        }
コード例 #23
0
 protected override void Write(HtmlRenderer renderer, NoteParagraphBlock obj)
 {
     if (!renderer.ImplicitParagraph && renderer.EnableHtmlForBlock)
     {
         if (!renderer.IsFirstInContainer)
         {
             renderer.EnsureLine();
         }
         renderer.Write("<p class='note' ").WriteAttributes(obj).Write(">");
     }
     renderer.WriteLeafInline(obj);
     if (!renderer.ImplicitParagraph)
     {
         if (renderer.EnableHtmlForBlock)
         {
             renderer.WriteLine("</p>");
         }
         renderer.EnsureLine();
     }
 }
コード例 #24
0
    /// <summary>
    /// Writes the specified Markdown object to the renderer.
    /// </summary>
    /// <param name="renderer">The renderer.</param>
    /// <param name="block">The markdown object.</param>
    protected override void Write(HtmlRenderer renderer, TableOfContentsBlock block)
    {
        if (block.Headings is null || block.Headings.Count == 0)
        {
            return;
        }

        renderer.EnsureLine();
        if (renderer.EnableHtmlForBlock)
        {
            renderer.WriteLine("<div class=\"toc\" role=\"navigation\">");
            renderer.PushIndent(Tab);
            renderer.Write("<h2 class=\"toc-title\">");
        }
        renderer.Write(block.Title);
        if (renderer.EnableHtmlForBlock)
        {
            renderer.WriteLine("</h2>");
            renderer.Write("<ul>");
            renderer.PushIndent(Tab);
        }

        var ords      = new List <int>(0);
        var ordLevel  = 0;
        var headings  = block.Headings.OrderBy(x => x.Line).ToList();
        var childList = 0;

        for (var i = 0; i < headings.Count; i++)
        {
            var adjustedLevel = headings[i].Level - block.LevelOffset - (block.StartingLevel - 1);

            renderer.EnsureLine();

            while (ordLevel > adjustedLevel)
            {
                ords.RemoveAt(ords.Count - 1);
                ordLevel--;
            }
            if (ordLevel == adjustedLevel)
            {
                var ord = ords[^ 1] + 1;
コード例 #25
0
        protected override void Write(HtmlRenderer renderer, LineBreakInline obj)
        {
            if (renderer.EnableHtmlForInline)
            {
                if (obj.IsHard || RenderAsHardlineBreak)
                {
                    renderer.WriteLine("<br />");
                }
            }

            renderer.EnsureLine();
        }
コード例 #26
0
        protected override void Write(HtmlRenderer renderer, Table table)
        {
            if (renderer == null)
            {
                throw new ArgumentNullException(nameof(renderer));
            }

            renderer.EnsureLine();
            renderer.WriteLine("<div class=\"table-wrapper\">");
            base.Write(renderer, table);
            renderer.WriteLine("</div>");
        }
コード例 #27
0
 protected override void Write(HtmlRenderer renderer, ParagraphBlock obj)
 {
     if (!renderer.IsFirstInContainer)
     {
         renderer.EnsureLine();
     }
     renderer.WriteLeafInline(obj);
     if (!renderer.IsLastInContainer)
     {
         renderer.WriteLine("<br />");
         renderer.WriteLine("<br />");
     }
 }
コード例 #28
0
 protected override void Write(HtmlRenderer renderer, CustomContainer obj)
 {
     renderer.EnsureLine();
     if (renderer.EnableHtmlForBlock)
     {
         renderer.Write("<div").WriteAttributes(obj).Write('>');
     }
     // We don't escape a CustomContainer
     renderer.WriteChildren(obj);
     if (renderer.EnableHtmlForBlock)
     {
         renderer.WriteLine("</div>");
     }
 }
コード例 #29
0
 protected override void Write(HtmlRenderer renderer, ParagraphBlock obj)
 {
     if (!renderer.ImplicitParagraph)
     {
         if (!renderer.IsFirstInContainer)
         {
             renderer.EnsureLine();
         }
         renderer.Write("<p").WriteAttributes(obj).Write(">");
     }
     renderer.WriteLeafInline(obj);
     if (!renderer.ImplicitParagraph)
     {
         renderer.WriteLine("</p>");
     }
 }
コード例 #30
0
        protected override void Write(HtmlRenderer renderer, MathBlock obj)
        {
            renderer.EnsureLine();
            if (renderer.EnableHtmlForBlock)
            {
                renderer.Write("<div").WriteAttributes(obj).WriteLine(">");
                renderer.WriteLine("\\[");
            }

            renderer.WriteLeafRawLines(obj, true, renderer.EnableHtmlEscape);

            if (renderer.EnableHtmlForBlock)
            {
                renderer.Write("\\]");
                renderer.WriteLine("</div>");
            }
        }