Skip to content

A few enhancements to make this a documentation browser #11

Description

@kamranayub

With a few enhancements, MM could easily be used as a documentation browser for our source code.

The three enhancements I'm thinking of:

  • Custom stylesheet/layout, on a per-solution basis. Just a way to make the preview prettier and add boilerplate HTML
  • Handle relative links correctly. In my Markdown, if I have a link to test.md it should tell VS to open that file if it exists. This will make it MM acts as a browser almost within VS. It will open extra tabs, but then you can use VS' built in back/forward to navigate between docs.
  • Switch to using Pandoc to generate HTML

Markdown# is cool, but I've had better luck packaging Pandoc.exe and executing it against markdown files to generate HTML. Here's a sample in C#:

// Process to output dir
var pandocStart = new ProcessStartInfo();
pandocStart.FileName = "pandoc";

// Standalone HTML generation using a template file
// Use Github Markdown processing!
pandocStart.Arguments = "pandoc -r markdown_github --highlight-style=kate --template=template.html --toc";
pandocStart.RedirectStandardError = true;
pandocStart.RedirectStandardOutput = true;
pandocStart.RedirectStandardInput = true;
pandocStart.UseShellExecute = false;
pandocStart.CreateNoWindow = true;
pandocStart.WindowStyle = ProcessWindowStyle.Hidden;

using (var pandoc = Process.Start(pandocStart))
{
    var rawText = File.ReadToEnd(markdownFile);
    string html;

    using (StreamWriter writer = pandoc.StandardInput)
    {
        await writer.WriteAsync(rawText);
    }

    using (StreamReader reader = pandoc.StandardOutput)
    {
        html = await reader.ReadToEndAsync();
    }

    using (StreamReader reader = pandoc.StandardError)
    {
        var error = await reader.ReadToEndAsync();

        if (!String.IsNullOrEmpty(error))
        {
            throw new Exception(error);
        }
    }

    // Do something with the HTML generated by Pandoc
}

I think this is better than using M# because it supports all sorts of extensions including tables, fenced code blocks, auto ID generation, and more (documented by Pandoc). Even cooler, it supports Pandoc title blocks or MultiMarkdown title blocks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions