public override void Render(ExtensionHtmlRenderer renderer, TableOfContent model, IFormatState formatState)
        {
            List <Heading> headings = renderer.ContainerBlock.GetHeadings();
            var            sb       = new StringBuilder();

            sb.AppendLine("<nav>");
            sb.AppendLine("<div class='title'>Contents</div>");
            foreach (var heading in headings)
            {
                var id = HtmlHelper.Unescape(heading.HeadingBlock.GetAttributes().Id);
                sb.AppendLine($@"<a href='#{id}' class='nav-level-{heading.Level}'>{heading.Title}</a>");
            }
            sb.AppendLine("</nav>");
            renderer.Write(sb.ToString());

            var dynamicCss = GenerateCss(model);

            if (dynamicCss != null)
            {
                renderer.RegisterDynamicCss(dynamicCss);
            }
        }
Пример #2
0
        private static void File(string fullFilePath, Container container, RenderSettings settings)
        {
            string body         = null;
            string summaries    = null;
            string cssHeader    = null;
            string jsHeader     = null;
            var    sourceFolder = new AbsoluteFolder(Path.GetDirectoryName(fullFilePath));

            if (settings == null)
            {
                settings = RenderSettings.DefaultWiki(sourceFolder);
            }

            using (var scope = ThreadScopedLifestyle.BeginScope(container))
                using (var writer = new StringWriter())
                {
                    MarkdownPipeline pipeline = CreatePipeline(container);
                    var markdown         = System.IO.File.ReadAllText(fullFilePath);
                    var markdownDocument = Markdown.Parse(markdown, pipeline);
                    var renderer         = new ExtensionHtmlRenderer(writer, markdownDocument, settings, pipeline);
                    renderer.RegisterDynamicCss(new Code("markdown-extensions", "0.0.1", () =>
                                                         Assembly.GetExecutingAssembly().GetFileContent("vscode-markdown.css")));

                    pipeline.Setup(renderer);
                    RegisterBlocks(renderer);

                    renderer.Parse(container);
                    renderer.Validate(container);
                    renderer.Transform();
                    renderer.Render(markdownDocument);
                    var fileName = Path.GetFileName(fullFilePath);
                    renderer.RenderMarkdown(fileName, markdownDocument);
                    writer.Flush();
                    body = writer.ToString();

                    using (var summaryWriter = new StringWriter())
                    {
                        // a bit of a hack to use different writer for summaries
                        renderer.Writer = summaryWriter;
                        renderer.RenderSummaries(markdownDocument);
                        summaryWriter.Flush();
                        summaries = summaryWriter.ToString();
                    }

                    cssHeader = renderer.RenderCssHeader();
                    jsHeader  = renderer.RenderJavascriptHeader();
                }
            var    document = $@"
				<html>
					<head>
						{jsHeader}
						{cssHeader}
					</head>
					<body>
						{summaries}
						<main>
						{body}
						</main>
					</body>
				</html>"                ;
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullFilePath);
            var    file = new File(settings.OutputFolder, fileNameWithoutExtension + ".html");

            System.IO.File.WriteAllText(file.AbsolutePath, document);
        }
Пример #3
0
 public void Render(ExtensionHtmlRenderer renderer, Note model, IFormatState formatState)
 {
     renderer.RegisterDynamicCss(Css.First());
 }