Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have the option to add a prettify class name to the <pre> tags #62

Open
GoogleCodeExporter opened this issue Jan 27, 2016 · 0 comments
Open

Comments

@GoogleCodeExporter
Copy link

It would be great to be able to configure the classname to be added to the 
<pre> tags to enable prettifying of the code using a syntax highlighter such as 
google-code-prettify.

Here's my take on the solution.

Add this code to MarkdownOptions:

    /// <summary>
    /// Specifies the value set in the class attribute of the <pre> tags
    /// that are wrapped around code segments
    /// e.g. "prettyprint" for google-code-prettify 
    /// http://code.google.com/p/google-code-prettify/
    /// </summary>
    public string PrettifyClass { get; set; }

Modify Markdown constructors:

    public Markdown(bool loadOptionsFromConfigFile):
    {
        //...
        case "MarkDown.PrettifyClass":
            _prettifyClass = settings[key];
            break;
    }

And:

    public Markdown(MarkdownOptions options)
    {
        //...
        _prettifyClass = options.PrettifyClass;
    }

And modify the CodeBlockEvaluator method of the Markdown class:

    private string CodeBlockEvaluator(Match match)
    {
        string codeBlock = match.Groups[1].Value;

        codeBlock = EncodeCode(Outdent(codeBlock));
        codeBlock = _newlinesLeadingTrailing.Replace(codeBlock, "");

        return _prettifyClass.Length > 0
            ? string.Concat("\n\n<pre class=\"" + _prettifyClass + "\"><code>", codeBlock, "\n</code></pre>\n\n")
            : string.Concat("\n\n<pre><code>", codeBlock, "\n</code></pre>\n\n");
    }

Original issue reported on code.google.com by weavers...@gmail.com on 15 Oct 2013 at 1:30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant