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

Line highlighting like pygments hl_lines #264

Closed
bcbroom opened this issue May 12, 2015 · 12 comments
Closed

Line highlighting like pygments hl_lines #264

bcbroom opened this issue May 12, 2015 · 12 comments
Labels
enhancement-request A request for an enhancement to be developed.

Comments

@bcbroom
Copy link

bcbroom commented May 12, 2015

I'm looking for the ability to highlight lines, either to call attention to specific code in a tutorial, or note added code in a running example.

Pygments offers the hl_lines option, such as hl_lines="3 4 5". This adds span element w css class of "hll" to the generated html for that line.

Is this something that has been talked about or planned?

@jneen
Copy link
Member

jneen commented May 19, 2015

Hi! This should be much easier after the formatter refactor for 2.0.

@citizenmatt
Copy link
Contributor

I'm also interested in line highlights - is it worth a temp implementation before 2.0 is available? Happy to have a go and send a PR.

lucidbee pushed a commit to BonsaiAI/rouge that referenced this issue Mar 16, 2017
@dmfigol
Copy link

dmfigol commented Oct 28, 2017

Hi @jneen
Any plans to have this implemented? PR #422 for adding this functionality to <2.0 was rejected, but I can't find in docs that this feature was actually implemented in 2.0.

@aalvrz
Copy link
Contributor

aalvrz commented Nov 4, 2017

Would love this as well....

@ijean
Copy link

ijean commented Sep 23, 2018

Hello @jneen ,

first I want to say that Rouge seems to be a lot faster (when used from Ruby) than the old Pygments option.

It will be great if you can implement the hl_lines option. I've just migrated from an older Jekyll version that was using Pygments to the latest Jekyll which uses Rouge and half of my posts are broken because of this feature missing.

Thanks,
Jean

@mojavelinux
Copy link
Contributor

I went ahead and tried to implement this, but hit a problem with line numbering. The HTMLTable formatter, which provides table-based line numbering, delegates to the wrong method on the inner formatter. Instead of delegating to the stream method, it delegates to the span method. This makes it impossible to put a line-wise formatter in between the HTMLTable and HTML formatter. If it delegated to the stream method instead, it would work.

I'll open an issue to address this. Once fixed, I can submit an HTMLHighlightLines formatter (like Pygments).

@mojavelinux
Copy link
Contributor

See #1083.

@mojavelinux
Copy link
Contributor

Also related is #1084, which is 80% of what is needed for the linewise highlighter.

@stale
Copy link

stale bot commented Feb 3, 2020

This issue has been automatically marked as stale because it has not had any activity for more than a year. It will be closed if no additional activity occurs within the next 14 days.

If you would like this issue to remain open, please reply and let us know if the issue is still reproducible.

@stale stale bot added the stale-issue There has been no activity for a year. label Feb 3, 2020
@mojavelinux
Copy link
Contributor

The related issues have been addressed, so I'll see if I can dig up my patch and submit it.

@stale stale bot removed the stale-issue There has been no activity for a year. label Feb 3, 2020
mojavelinux added a commit to mojavelinux/rouge that referenced this issue Feb 5, 2020
- add line highlighting option to HTMLLinewise formatter
- add dedicated formatted to add line highlighting (only mark highlighted lines)
mojavelinux added a commit to mojavelinux/rouge that referenced this issue Feb 5, 2020
- add line highlighting option to HTMLLinewise formatter
- add dedicated formatter to add line highlighting (only marks highlighted lines)
@mojavelinux
Copy link
Contributor

mojavelinux commented Feb 5, 2020

I submitted a PR (#1426). In the PR, I'm proposing both a new formatter (HTMLLineHighligher) and an enhancement to the HTMLLinewise formatter. The difference is that the HTMLLineHighlighter only wraps the lines specified by the highlight_lines option, whereas the HTMLLinewise formatter wraps all lines (as it currently does) and only adds the additional highlight line class to the highlighted lines. If you think the additional formatter is unnecessary, I can remove it.

@mojavelinux
Copy link
Contributor

Pygments offers the hl_lines option, such as hl_lines="3 4 5"

Since Rouge works in the API space, I felt it was most appropriate for the option (highlight_lines) to be a numeric array.

@pyrmont pyrmont added the enhancement-request A request for an enhancement to be developed. label Feb 16, 2020
mojavelinux added a commit to mojavelinux/rouge that referenced this issue Aug 26, 2020
- add line highlighting option to HTMLLinewise formatter
- add dedicated formatter to add line highlighting (only marks highlighted lines)
@jneen jneen closed this as completed in d7b60c0 Oct 2, 2020
mattt pushed a commit to NSHipster/rouge that referenced this issue May 19, 2021
- add line highlighting option to HTMLLinewise formatter
- add dedicated formatter to add line highlighting (only marks highlighted lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement-request A request for an enhancement to be developed.
Projects
None yet
Development

No branches or pull requests

8 participants