Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code highlighting #10

Closed
piranha opened this issue Feb 24, 2012 · 8 comments
Closed

Code highlighting #10

piranha opened this issue Feb 24, 2012 · 8 comments

Comments

@piranha
Copy link

piranha commented Feb 24, 2012

It would be nice to be able to highlight code on server-side instead of doing that on client-side (right now I'm thinking about HTML and not Latex output). I see two possibilities here:

  • get blocks of code from the resulting HTML (by parsing it), highlight them and inject back,
  • provide (optional) highlighting function to blackfriday which will be called during rendering parts of the code.

I believe that latter is better option both API- and performance-wise. Do you have any thoughts/opinion about this?

@phrozen
Copy link

phrozen commented Mar 1, 2012

I think there should be a branch for the next version of blackfriday that 1) supports weekly, and 2) follow the steps of Sundown (evolved from original Upskirt) -> https://github.com/tanoku/sundown

Sundown actually broke the way most markdown processors work exactly to achieve what this issue is all about. It is now what powers Github's syntax highlighting is pretty efficient and allows for multiple outputs by pipelining the rendering. Blackfriday is amazing, but it would be more awesome if it stays current with Sundown/Redcarpet (Ruby interface to the Sundown library by Github).

@cespare
Copy link
Contributor

cespare commented Nov 24, 2012

I hacked up Blackfriday to do syntax highlighting by introducing a callback for processing Github-style code blocks. You can see my changes over on my fork. My method is pretty hacky and I'm not happy with it as a general solution, so I'm not going to open a pull request for it.

Ideally, I think you'd be able to take the existing HTML renderer and selectively override certain functions. This is the way that Redcarpet does it and it works really well.

(By the way, you can see how I hooked up pygmentize to my fork of blackfriday over here).

@yonderblue
Copy link

👍 for a future server side highlight :)

@dmitshur
Copy link
Collaborator

dmitshur commented Jun 1, 2015

The github_flavored_markdown renderer already does server-side highlighting for Go, diff file format and potentially other languages:

image

It uses these Go packages for performing server-side highlighting:

I think it's out of scope for blackfriday itself to be importing those packages. However, another higher-level package can import blackfriday and aforementioned highlighter packages and perform markdown rendering with code server-side highlighting.

@yonderblue
Copy link

I see the complete html page example here https://godoc.org/github.com/shurcooL/github_flavored_markdown#example-Markdown--CompleteHtmlPage but doesn't that rely on non existing .../github-flavored-markdown.css file?

@dmitshur
Copy link
Collaborator

dmitshur commented Jun 4, 2015

Yes, a .css with a highlighting scheme is needed. GitHub API provides a Markdown rendering endpoint, but it also seems to expect you to bring .css yourself.

Edit in 2017: The CSS for GitHub-Flavored Markdown highlighting is now available at https://github.com/primer/primer-css/tree/master/modules/primer-markdown.

@egorsmkv
Copy link

egorsmkv commented Oct 2, 2017

@alecthomas created a nice library https://github.com/alecthomas/chroma

It remains only to make the integration.

@depado
Copy link

depado commented Oct 9, 2017

As shown in #396 I finally came up with this : https://github.com/Depado/bfchroma
(Hope that helps)

rtfb added a commit that referenced this issue Oct 11, 2017
Chroma is a general purpose code highlighting library, and bfchroma
provides an easy to use glue layer for Blackfriday to interface with
Chroma.

Fixes #10.
@rtfb rtfb closed this as completed in #400 Aug 4, 2018
rtfb added a commit that referenced this issue Aug 4, 2018
Chroma is a general purpose code highlighting library, and bfchroma
provides an easy to use glue layer for Blackfriday to interface with
Chroma.

Fixes #10.
willdollman pushed a commit to willdollman/blackfriday that referenced this issue Feb 27, 2021
Chroma is a general purpose code highlighting library, and bfchroma
provides an easy to use glue layer for Blackfriday to interface with
Chroma.

Fixes russross#10.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants