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

Question about syntax highlighting with fenced code blocks #622

Closed
ajwann opened this issue Jul 16, 2017 · 1 comment
Closed

Question about syntax highlighting with fenced code blocks #622

ajwann opened this issue Jul 16, 2017 · 1 comment

Comments

@ajwann
Copy link

ajwann commented Jul 16, 2017

I'm using redcarpet with the HTML renderer and :highlight => true is turned on.

When I create a code block like so:
```ruby
class Foo
end
```
I don't see any syntax higlighting. I do however see in my browser that the code block was given class="ruby".

Should I be expecting to see syntax highlighting? Or does redcarpet just assign a class equal to whatever language I specified, leaving me to style the class myself?

@robin850
Copy link
Collaborator

Hello @ajwann,

Actually, the :highlight option allows you to write ==something== and get <mark>something</mark> once it's parsed.

Redcarpet doesn't come with syntax highlighting out of the box because people have different needs or sometimes don't need it at all. You can easily highlight code with Rouge. Once it's installed, you can do something like:

require 'redcarpet'
require 'rouge'
require 'rouge/plugins/redcarpet'

class CustomRender < Redcarpet::Render::HTML
  include Rouge::Plugins::Redcarpet
end

parser = Redcarpet::Markdown.new(CustomRender, fenced_code_blocks: true)
parser.render("Your Markdown ...")

And then include a style-sheet provided by Rouge to properly show syntax highlighting on your page.

I hope this answers your question, feel free to ask if something isn't clear ! :-)

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

2 participants