Skip to content

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

Description

@GoogleCodeExporter
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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions