toptensoftware / markdowndeep

Open-source implementation of Markdown for C# and Javascript
268 stars 120 forks source link

Support GitHub Style Code Blocks #37

Open rprouse opened 10 years ago

rprouse commented 10 years ago

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,

``` ruby
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.

dtewinkel commented 10 years ago

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

nightroman commented 10 years ago

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

jgauffin commented 9 years ago

+1

toptensoftware commented 9 years ago

Is this not covered by this:

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

rprouse commented 9 years ago

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

kodfodrasz commented 9 years ago

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

jgauffin commented 9 years ago

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 commented 9 years ago

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.

dprothero commented 8 years ago

@jgauffin Thanks for sharing your solution!

FransBouma commented 8 years ago

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.