Github Flavored Markdown Fenced Code Blocks #20

Closed
AlainODea opened this Issue May 20, 2011 · 15 comments

Comments

Projects
None yet
8 participants

It would be exceptionally great if the plugin supported Github Flavored Markdown's Fenced Code Blocks as well as the PHP Markdown Extra's approach.

Github Flavored Markdown allows:

```scala
class Example(name: String) {
  val field: Option[Int] = None
}
```

To render as:

class Example(name: String) {
  val field: Option[Int] = None
}

It would be awesome if pegdown could treat blocks like this the same as:

~~~
class Example(name: String) {
  val field: Option[Int] = None
}
~~~

and render as:

class Example(name: String) {
  val field: Option[Int] = None
}

Syntax highlighting is a bigger deal and IMHO better delegated to SyntaxHighlighter on the client-side.

Pegdown is great and thank you for building it :)

talios commented May 20, 2011

"Syntax highlighting is a bigger deal and IMHO better delegated to SyntaxHighlighter on the client-side."

I'd actually like to see that optional, having the syntax highlghting embedded IN the generated HTML is better when your target of the HTML isn't actually a browser, or something with Javascript support such as an HTML->PDF generator.

+1 on the request tho.

Owner

sirthias commented May 20, 2011

Thanks for the proposal.
I think it's a valid request and not hard to implement.
Will go in.
Additionally I'll add the option to supply a custom transformer for code source to the PegDownProcessor. If you supply one all code block content will be fed through the transformer, who is free to do whatever it wants with the code sources. One option would be conversion to syntax-highlighting HTML, another code formatting. I'll add a second issue for this...

Awesome! Thank you :)

On 2011-05-20, at 6:10, sirthiasreply@reply.github.com wrote:

Thanks for the proposal.
I think it's a valid request and not hard to implement.
Will go in.
Additionally I'll add the option to supply a custom transformer for code source to the PegDownProcessor. If you supply one all code block content will be fed through the transformer, who is free to do whatever it wants with the code sources. One option would be conversion to syntax-highlighting HTML, another code formatting. I'll add a second issue for this...

Reply to this email directly or view it on GitHub:
#20 (comment)

@sirthias sirthias closed this in 4ddd146 Jul 5, 2011

Owner

sirthias commented Jul 5, 2011

Also see issue #21 for more info on how to supply your own custom code transformer.

clintel commented Aug 19, 2011

I'd not been able to find sufficient doco on how to do fenced code blocks inside ordered/unordered (i.e. bullet) lists. I tried so many different combinations with backticks and indenting, and finally figured out the trick: https://gist.github.com/1155906

Maybe this is obvious to a veteran, but I couldn't find any clues from the GitHub Flavored Markdown intro. Likewise, I haven't been able to find a list of all the languages supported for syntax highlighting. For example, is Apache config supported? What about shell scripts? I could assume "apache" and "shell" respectively, but couldn't find a list to check.

clintel commented Aug 19, 2011

Re syntax highlighting supported languages with GFM (GitHub Flavored Markdown), I've found the answer:

It uses Pygments. There's a language list, but more importantly there's a list of identifiers for those languages

Owner

sirthias commented Aug 19, 2011

Clintel,
code blocks in lists are a standard markdown feature: Just indent the respective block once more than the enclosing list item and you are set. Fenced code blocks work on the same indentation level as the surrounding content but (as every other block element) need to be separated by blank lines.
Thanks for your gist, it shows off these features nicely...

taichi commented Apr 4, 2012

Please keep GFM code type identifier.
I try to syntax-highlighting HTML but identifier is dropped, so i can't.

I want to extends ToHtmlSerializer, look like this

public class MyToHtmlSerializer extends ToHtmlSerializer {
    public void visit(VerbatimNode node) {
        printer.println().print("<pre><code class=\"brush: " + node.getCodeIdentifier() + "\">");

        String text = node.getText();
        // print HTML breaks for all initial newlines
        while(text.charAt(0) == '\n') {
            printer.print("<br/>");
            text = text.substring(1);
        }
        printer.printEncoded(text);
        printer.print("</code></pre>");
    }
}

because some of syntax-highlighting libraries wants language identifier.

@sirthias sirthias reopened this Apr 4, 2012

Owner

sirthias commented Apr 4, 2012

Ok, fair point.
Thanks for pointing this out.

taichi commented Apr 5, 2012

Thank you !!

charleso pushed a commit to charleso/pegdown that referenced this issue Aug 19, 2012

Hi @sirthias - I've pushed a small fix for this. I hope I've done this properly, but I'm happy to tweak my patch to meet your coding standards. Let me know what you think. :)

(For example - not sure if I should have introduced a different VerbatimNode, or added an extra field as I did)

taichi commented Aug 22, 2012

cool work !!

gpicron added a commit to Arboratum-Open/pegdown that referenced this issue Oct 20, 2012

Merge pull request #1 from charleso/issue-20-code-types
Issue #20: Capture GFM code types for fenced blocks

sirthias added a commit that referenced this issue Oct 26, 2012

Merge pull request #60 from charleso/issue-20-code-types
Issue #20: Capture GFM code types for fenced blocks

@sirthias sirthias closed this Oct 26, 2012

which version is this implemented in?

git tag --contains 109cf6624352e445b9fabdb98bab0051eeed4fb6
1.2.0
1.2.1

It's on 1.2.0 and later.

danizen commented Mar 27, 2015

I'm trying to figure out how best to get my Atlassian Stash/Confluence to highlight github fenced code blocks. I see this ticket, I see my github fenced code blocks are gray/black. What I'm really looking for is syntax highlighting on the back-end. They may say its not them, but pegdown, that needs an enhancement.

I need to know whether to tell them to upgrade pegdown or write their own HTML formatter ;) I need to know which firefox plugins/chrome extensions to use if this is not part of pegdown.

Any advice?

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