Ejemplo n.º 1
0
        private static void AggregateCheatSheet(Container container)
        {
            Dictionary <string, string> cheatSheetByExtensionName = container
                                                                    .GetAllInstances <IExtensionInfo>()
                                                                    .ToDictionary(x => x.Name, x => x.CheatSheet);
            var    sb               = new StringBuilder();
            int    i                = 1;
            var    body             = new StringBuilder();
            string cssHeader        = null;
            string javascriptHeader = null;

            using (ThreadScopedLifestyle.BeginScope(container))
            {
                foreach (var entry in cheatSheetByExtensionName)
                {
                    var markdown = entry.Value;
                    var writer   = new StringWriter();
                    var pipeline = CreatePipeline(container);
                    var document = Markdown.Parse(markdown, pipeline);
                    var renderer = new ExtensionHtmlRenderer(writer, document, new RenderSettings(), pipeline);
                    pipeline.Setup(renderer);
                    RegisterBlocks(renderer);
                    renderer.Parse(container);
                    // validate errors
                    renderer.Transform();
                    // run validations
                    renderer.Render(document);
                    writer.Flush();

                    cssHeader        = renderer.RenderCssHeader();
                    javascriptHeader = renderer.RenderJavascriptHeader();

                    string isChecked = i == 1 ? "checked" : "";
                    string name      = entry.Key;
                    string md        = entry.Value;
                    string html      = writer.ToString();

                    var tab = $@"
						<section>
							<input type='radio' name='sections' id='option{i}' {isChecked}>
							<label for='option{i}'>{name}</label>
							<article>{html}</article>
						</section>"                        ;
                    body.AppendLine(tab);
                    i += 1;
                }
            }
            var htmlDocument = $@"
				<html>
					<head>
						{javascriptHeader}
						{cssHeader}
					</head>
					<body>
						<div class='tabordion'>
							{body}
						</div>
					</body>
				</html>"                ;

            System.IO.File.WriteAllText("CheatSheet.html", htmlDocument);
        }
Ejemplo n.º 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);
        }