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

Refactor highlighter to allow for configuration #2590

Closed
wants to merge 2 commits into from

Conversation

hexid
Copy link

@hexid hexid commented Jul 12, 2014

I have been working on adding highlighter settings to _config.yml for the past few days. So far I have been able to set default configurations for both Liquid and RedCarpet highlight blocks.

Currently, I am using the following structure in my _config.yml file to add inline line numbers to all highlight blocks:

tags:
  highlight:
    linenos: true

All of the following are affected by the prior configuration (assuming RedCarpet as the markdown engine for the first two):

```ruby
puts "Hello world!"
```

~~~ruby
puts "Hello world!"
~~~

{% highlight ruby %}
puts "Hello world!"
{% endhighlight %}

This, however, is not limited to the linenos options and can also be used with other options that affect the highlight tag, such as hl_lines and linenostart. Granted, this is assuming that you are using pygments as your highlighter.

If anyone could chime in about the below points, along with any concerns you might have, that would be greatly appreciated.

  • Moved highlight code to lib/jekyll/highlighter.rb
  • Allow configuration of Liquid HighlightBlock
  • Allow configuration of RedCarpet markdown highlighting (ref. The linenos support while using ``` #1887)
  • Add tests to make sure everything works
  • Add documentation to the site for these changes
  • Get feedback on configuration structure

@parkr
Copy link
Member

parkr commented Jul 12, 2014

Hey! Thanks for the pull request. Always great to see new avatars around 👊

adding highlighter settings to _config.yml

I'm not sure I entirely understand the motivations behind this nor agree with those I can infer. Would you care to expand on your reasoning behind this?

/cc @benbalter, the configuration 🎄 cop.

@hexid
Copy link
Author

hexid commented Jul 13, 2014

@parkr What I meant by this was that you can provide default configuration values that will be passed to pygments or rouge.

Currently, there is no way to override these options when using RedCarpet's fenced_code_block because they do not allow for options beyond the language for the codeblock.

When using the Liquid HighlightBlock, it is possible to override these options, so that, in the case provided above, all codeblocks will be assigned line numbers and can then be disabled individually.

An example of this would be the following, in which the first code block will not have line numbers, while the rest will:

_config.yml

markdown: redcarpet
highlighter: pygments
tags:
  highlight:
    linenos: true

index.md

{% highlight ruby linenos=false %}
puts "No line numbers!"
{% endhighlight %}

{% highlight ruby %}
puts "Has line numbers!"
{% endhighlight %}

{% highlight ruby linenos=table %}
puts "Tabled line numbers!"
{% endhighlight %}

~~~ ruby
puts "Has line numbers!"
puts "They can't be individually disabled :("
~~~

@doktorbro
Copy link
Member

@hexid Does the refactoring tackle this issue rouge-ruby/rouge#118 too?

@hexid
Copy link
Author

hexid commented Jul 16, 2014

@penibelst I was able to add support for both Pygments and Rouge while using Kramdown

@parkr Should I include these changes in this PR or prep another with those changes?

@jneen
Copy link

jneen commented Oct 7, 2014

👏 👏 👏

@jneen
Copy link

jneen commented Oct 7, 2014

My only concern would be the Makefile hack that we had to add in the redcarpet plugin. I'm not sure if Kramdown has the same behavior, but redcarpet turns all leading tabs into 4 spaces, which completely breaks Makefile syntax. So if that happens (i.e. lexer.tag == 'make'), we simply did a gsub(/^[ ][ ][ ][ ]/, "\t") on the input text.

@ghost
Copy link

ghost commented Oct 7, 2014

I'm not sure if Kramdown has the same behavior, but redcarpet turns all
leading tabs into 4 spaces, which completely breaks Makefile syntax.

@jneen not necessarily

Makefiles without tab characters

@parkr parkr closed this Dec 29, 2014
@ghost
Copy link

ghost commented Dec 29, 2014

@parkr was this fixed?

@parkr
Copy link
Member

parkr commented Dec 29, 2014

No. Having read through the comments again, I'm not convinced it's worth the trouble/maintenance costs/configuration overhead.

@jneen
Copy link

jneen commented Dec 29, 2014

No worries. It turns out the makefile hack isn't necessary in Kramdown anyways, and they have rouge support now.

@parkr
Copy link
Member

parkr commented Dec 29, 2014

they have rouge support now.

Ok cool. What version added that in? We doing the right things to make this available?

@jneen
Copy link

jneen commented Dec 30, 2014

I'm not sure... let me dig it up

@jneen
Copy link

jneen commented Dec 30, 2014

@jekyll jekyll locked and limited conversation to collaborators Feb 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants