protected override void Write(LatexRenderer renderer, MathBlock obj)
 {
     renderer.EnsureLine();
     renderer.WriteLine("\\begin{equation*}");
     renderer.WriteLeafRawLines(obj, true, false);
     renderer.WriteLine("\\end{equation*}").WriteLine();
 }
 protected override void Write(LatexRenderer renderer, HtmlBlock obj)
 {
     renderer.WriteLeafRawLines(obj, true, false);
 }
Exemple #3
0
        protected override void Write(LatexRenderer renderer, CodeBlock obj)
        {
            renderer.EnsureLine();
            var fencedCodeBlock = obj as FencedCodeBlock;

            if (fencedCodeBlock != null)
            {
                var info     = fencedCodeBlock.Info ?? string.Empty;
                var langFrag = info.Split(':');

                var language = langFrag[0];
                var label    = langFrag.Length > 1 ? langFrag[1] : null;
                var caption  = langFrag.Length > 2 ? langFrag[2] : null;

                var hasOptions = false;

                renderer.Write("\\begin{lstlisting}[");
                if (!String.IsNullOrEmpty(language))
                {
                    renderer.Write("language=");
                    renderer.Write(language);
                    hasOptions = true;
                }
                if (label != null)
                {
                    if (hasOptions)
                    {
                        renderer.Write(",");
                    }
                    renderer.Write("label=");
                    renderer.Write(label);
                    hasOptions = true;
                }
                if (caption != null)
                {
                    if (hasOptions)
                    {
                        renderer.Write(",");
                    }
                    renderer.Write("caption=");
                    renderer.Write(caption);
                }
                renderer.Write("]\n");

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

                renderer.Write("\\end{lstlisting}");
            }

            //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
            //    renderer.Write("<div")
            //        .WriteAttributes(obj.TryGetAttributes(),
            //            cls => cls.StartsWith(infoPrefix) ? cls.Substring(infoPrefix.Length) : cls)
            //        .Write(">");
            //    renderer.WriteLeafRawLines(obj, true, true, true);
            //    renderer.WriteLine("</div>");

            //}
            //else
            //{
            //    renderer.Write("<pre");
            //    if (OutputAttributesOnPre)
            //    {
            //        renderer.WriteAttributes(obj);
            //    }
            //    renderer.Write("><code");
            //    if (!OutputAttributesOnPre)
            //    {
            //        renderer.WriteAttributes(obj);
            //    }
            //    renderer.Write(">");
            //    renderer.WriteLeafRawLines(obj, true, true);
            //    renderer.WriteLine("</code></pre>");
            //}
        }