DownmarkerWPF icon indicating copy to clipboard operation
DownmarkerWPF copied to clipboard

Support ``` notation for code blocks

Open kamranayub opened this issue 13 years ago • 7 comments

Markpad is great for GitHub readme editing, so it'd be nice to support the ``` style code blocks.

var someJs = function () { };

kamranayub avatar Mar 14 '12 21:03 kamranayub

As thats specifically a "GitHub Flavoured Markdown", it'd need to be optional, perhaps a 'filter'/markdown level.

Relates to #4

ghost avatar Mar 14 '12 22:03 ghost

This is how the various backticks are handled by Markpad:

Could this be an upstream issue?

shiftkey avatar Mar 14 '12 22:03 shiftkey

wtf do you mean by 'upstream' issue, @shiftkey?

ghost avatar Mar 14 '12 22:03 ghost

Forking/extending the library we're using to parse markdown

shiftkey avatar Mar 15 '12 00:03 shiftkey

I've tried it with the backticks and then a newline (typical for code blocks) and it messes up.

```js
var some js = function () {

};
```

kamranayub avatar Mar 15 '12 01:03 kamranayub

As I explained to @shiftkey over IM, three backticks on one line is essentially: opencloseopen code closeopenclose.

Introducing newlines doesn't work. We'll have to add different extension points for markdown to allow in 'github flavoured markdown' as there are case when you DONT want that to work (ie, if your markdown processor doesn't use GH)

ghost avatar Mar 15 '12 01:03 ghost

If it helps, I implemented support for this on top of Markdown # myself for my own blog.

The Regex for the block is:

private static Regex _syntaxBlockRx = new Regex(@"^``` ?([^\r\n]+)?\r?\n(.+?)\r?\n```\r?$", RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.Compiled);

I then followed what GitHub does; I evaluate the markdown, replace syntax blocks with an MD5 hash of the langage + code, then after Markdown transformation, replace those MD5 hashes with some HTML that adds in SyntaxHighlighter support. If you want me to share the whole class that does it, let me know.

kamranayub avatar Mar 15 '12 12:03 kamranayub