markdowndeep icon indicating copy to clipboard operation
markdowndeep copied to clipboard

Support GitHub Style Code Blocks

Open rprouse opened this issue 10 years ago • 10 comments

Markdowndeep and Github support indented blocks as <pre> or code blocks. Github also has the Syntax Highlighting format.

```ruby
require 'redcarpet' 
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
```

Which produces this,

require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html

MarkdownDeep doesn't need to do the syntax highlighting, but it should at least treat it like a code block.

rprouse avatar Mar 06 '14 03:03 rprouse

+1 I need this too. I now need to send it through Pandoc to get my Markdown to HTML conversion.

dtewinkel avatar Apr 07 '14 17:04 dtewinkel

+1 here, too. Yes, this would be very useful.

nightroman avatar Apr 07 '14 17:04 nightroman

+1

jgauffin avatar Dec 02 '14 12:12 jgauffin

Is this not covered by this:

https://github.com/toptensoftware/markdowndeep/commit/4faf39fe06f49571d20dce65a5c08d8a874f6a0d

toptensoftware avatar Dec 09 '14 04:12 toptensoftware

@toptensoftware I don't think it is covered. It looks like that commit covers the single backtick around inline code like this code. I don't think it covers the code blocks which start with three backticks and optionally a language identifier ```C# on a line and then ended by three backticks.

rprouse avatar Dec 09 '14 12:12 rprouse

I think it is covered, at least in the C# version, because you can hook the FormatCodeBlock extension point to handle the language identifier.

kodfodrasz avatar Jun 03 '15 04:06 kodfodrasz

No it's not covered as the FormatCodeBlock only get the actual code and not any language specifier.

// Callback to format a code block (ie: apply syntax highlighting)
// string FormatCodeBlock(code)
// Code = code block content (ie: the code to format)
// Return the formatted code, including <pre> and <code> tags
public Func<Markdown, string, string> FormatCodeBlock;

I've solved it by using a pre processor which runs before MarkdownDeep get's the source code: https://github.com/jgauffin/markdownweb/blob/master/src/MarkdownWeb/PreFilters/GithubCodeBlocks.cs

jgauffin avatar Jun 03 '15 06:06 jgauffin

It would have helped if t least the position in the complete text block had been specified, as then you could manually found the backticks and the language specifier.

jgauffin avatar Jun 03 '15 06:06 jgauffin

@jgauffin Thanks for sharing your solution!

dprothero avatar Nov 27 '15 20:11 dprothero

I implemented this in my fork of MarkdownDeep which is part of DocNet (https://github.com/FransBouma/DocNet/tree/master/src/MarkdownDeep) server side only.

FransBouma avatar Feb 22 '16 11:02 FransBouma