Exemplo n.º 1
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);
        }