Skip to content

Allow marking specific highlighted lines via Liquid#9138

Merged
jekyllbot merged 15 commits intojekyll:masterfrom
lylo:support-line-highlighting
Nov 3, 2022
Merged

Allow marking specific highlighted lines via Liquid#9138
jekyllbot merged 15 commits intojekyll:masterfrom
lylo:support-line-highlighting

Conversation

@lylo
Copy link
Copy Markdown
Contributor

@lylo lylo commented Sep 30, 2022

This is a 🙋 feature or enhancement.

Summary

Support for highlighting lines of code was added to Rouge in rouge-ruby/rouge@d7b60c0. This PR adds support to Jekyll for this feature.

Screenshot 2022-09-30 at 14 29 09

Resolves #8621 (albeit partially)

@lylo lylo force-pushed the support-line-highlighting branch from 2bd03cc to 928f558 Compare September 30, 2022 13:56
@ashmaroli ashmaroli requested a review from a team September 30, 2022 14:13
@ashmaroli
Copy link
Copy Markdown
Member

Thank you for submitting this proposal, @lylo.
This looks good to me at first glance save for a small correction to the documentation. I suggest you specify the need for "double-quoted" value instead of just a quoted value since our parser isn't super-flexible as of now.

@lylo
Copy link
Copy Markdown
Contributor Author

lylo commented Sep 30, 2022

Thank you for submitting this proposal, @lylo. This looks good to me at first glance save for a small correction to the documentation. I suggest you specify the need for "double-quoted" value instead of just a quoted value since our parser isn't super-flexible as of now.

Good spot, thanks @ashmaroli. I've updated this in 7cfd1fa

@lylo
Copy link
Copy Markdown
Contributor Author

lylo commented Oct 21, 2022

Hey 👋 I just wondered whether there was anything I could do to push this PR forward, or is it just a matter of waiting for someone on core to find it and take a look?

@parkr
Copy link
Copy Markdown
Member

parkr commented Oct 21, 2022

I could have sworn we had this feature like 8 years ago. Was it a Pygments-only feature that Rouge only recently included?

@ashmaroli ashmaroli added this to the 4.4 milestone Oct 24, 2022
@ashmaroli
Copy link
Copy Markdown
Member

@lylo Pinging you to inform you that this enhancement will land in the next minor release (v4.4.0).
I do have some issues the overall code in the branch but it is not your fault since you were just acting based on surrounding code. I will get back to this after Jekyll v4.3.1 ships.

@lylo
Copy link
Copy Markdown
Contributor Author

lylo commented Oct 24, 2022

Thanks @ashmaroli 🙏

ashmaroli
ashmaroli previously approved these changes Oct 27, 2022
Copy link
Copy Markdown
Member

@ashmaroli ashmaroli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Member

@parkr parkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One quick comment about testing the class customization.

@ashmaroli ashmaroli dismissed their stale review October 27, 2022 07:15

Needs some more changes

@ashmaroli
Copy link
Copy Markdown
Member

@lylo Thank you for adding the new features. Needs some minor edits:

  • The Scenario keyword for last scenario is intended incorrectly.
  • I feel testing for "Liquid Exception: Syntax error" would be better.

Since you mentioned "succinct", I would like to request you to make the following change to cucumber scenarios you have added:

  • There really is no need to have the kramdown code block with triple backticks and the configuration entry for kramdown.input. They are principally unrelated to your changes.
    (I didn't want to burden you with this earlier since you were only repeating the pattern in existing code, but since the diff has gotten bigger now, It's best not adding more noise.)

@ashmaroli
Copy link
Copy Markdown
Member

P.S. to above comment 👆:
I have edited the features/highlighting.feature on the base branch (master: 94028e7) to give a better idea of what I meant by "noise" in the earlier comment.

@ashmaroli
Copy link
Copy Markdown
Member

Why have you renamed the sample file to "test.rb" from "index.html"?

@lylo
Copy link
Copy Markdown
Contributor Author

lylo commented Oct 27, 2022

Why have you renamed the sample file to "test.rb" from "index.html"?

You can ignore that, it was reverted in a later commit

@ashmaroli
Copy link
Copy Markdown
Member

Buddy, you have made things harder for yourself by cherry-picking my commit from the master. Now you will have to undo that action before this gets merged...... The best route is to rebase to current master now.

Locally run in terminal:

git fetch upstream master
git rebase upstream/master

@lylo
Copy link
Copy Markdown
Contributor Author

lylo commented Oct 27, 2022

@ashmaroli I have a clean branch locally I can put a fresh PR up for if you prefer. I think that would be best in this circumstance, but I'll defer to you. Apologies for the additional work I've created here.

@lylo
Copy link
Copy Markdown
Contributor Author

lylo commented Oct 27, 2022

  • Incorrect expectation -- Tag should expect a (double-)quoted string of numbers, not an array for hl_lines. Array of integers is a result of preliminary internal processing, not user-given.

Fixed in 03a68ea

  • Insufficient -- hl_class gets flagged when quoted only if the string consists of non-numbers. What if the parser doesn't catch it? For example: highlight_line_class="2 3 4"?

I've addressed this in 289421a by relaxing the rules of the parser. So while the correct format for declaring highlight_line_class is still:

{% highlight ruby highlight_lines="1 2" highlight_line_class=one_two %}

This change will be forgiving and do the expected thing if somebody did try and pass in a double-quoted list of integers, so this:

{% highlight ruby highlight_lines="1 2" highlight_line_class="1 2" %}

Will result in a class name of "1 2"

I'm happy to be less forgiving and raise a syntax error instead if you prefer.

The main problem I'm having here is the overarching strict parsing rules and regexes. It could really do with a full overhaul. I'm just trying to work within it's constraints.

@ashmaroli
Copy link
Copy Markdown
Member

@lylo Found multiple issues with the latest implementation. I guess you couldn't give 100% focus into this due to the various moving parts and inputs from my end. I therefore took the liberty of cleaning the branch up directly instead of first pointing out all the issues.
Do run git pull origin support-line-highlighting to update your local copy.

@ashmaroli ashmaroli requested a review from parkr October 28, 2022 06:21
@ashmaroli
Copy link
Copy Markdown
Member

@parkr Requesting a fresh round of review on this pull request. Thanks.

@ashmaroli
Copy link
Copy Markdown
Member

Hello @lylo, It just dawned on me that there's a possibility that users may get confused by the proposed line-highlighter parameter names.

Tl;dr

Can you think of better prefixes for the new proposed options?

Details

The tag itself is named highlight to convey the notion of syntax-highlighting.
Now if we were to ship options named highlight_lines, users may think it's a directive to apply syntax-highlighting only to the declared lines. Similar being the confusion with highlight_class.

My brain came up with using mark_* instead (akin to the HTML tag mark), but I feel its too technical and may not be intuitive for lay-users.

@lylo
Copy link
Copy Markdown
Contributor Author

lylo commented Oct 31, 2022

@ashmaroli I used highlight_lines and highlight_line_class because this is what's used in Rouge itself, but it's a fair question to ask – internal class names in a dependency doesn't necessarily make sense from a user perspective.

If we're avoiding highlight I think mark_lines and mark_class would be good alterntives. I can't think of anything better right now. emphasize is another word that would make sense.

Happy to change to one of these if you agree?

@ashmaroli
Copy link
Copy Markdown
Member

@lylo I understand your perspective and that the current implementation is simpler because of it. I guess we will have to settle for mark_* then because emphasis has a different meaning in HTML and it's a lot more keystrokes than mark.
I am sorry that your first contribution to Jekyll got a bit more complicated now.

Copy link
Copy Markdown
Member

@parkr parkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I don't have a strong opinion on the naming – whatever you feel is best for a non-technical user. Thanks!

#{markup}

Valid syntax: highlight <lang> [linenos]
Valid syntax: highlight <lang> [linenos] [highlight_lines="3 4 5"] [highlight_line_class=class_name]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a strong reason to customize the highlight line class? Couldn't a user simply apply the styles they want to .hll?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having the same thought today! I think we should remove this option for the time being. If we find it's a problem for people in the future, we can always add it. Feels like a premature optimisation right now.

I'll fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 8a202c5


Valid syntax: highlight <lang> [linenos]
Valid syntax: highlight <lang> [linenos] [highlight_lines="3 4 5"] [highlight_line_class=class_name]
MSG
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be an interesting opportunity to link out to the jekyllrb.com page for this tag so users have a direct line to a helpful webpage with more information on the matter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8a202c5

@lylo
Copy link
Copy Markdown
Contributor Author

lylo commented Nov 1, 2022

@lylo I understand your perspective and that the current implementation is simpler because of it. I guess we will have to settle for mark_* then because emphasis has a different meaning in HTML and it's a lot more keystrokes than mark.
I am sorry that your first contribution to Jekyll got a bit more complicated now.

It's no problem, I'm enjoying the journey and learning a lot.

In 8a202c5 I've changed this to mark_lines. I've also removed the class option as per suggestion from @parkr which simplifies the code.

@ashmaroli ashmaroli changed the title Allow line highlighting via the highlight_lines Rouge feature Allow marking specific highlighted lines via Liquid Nov 3, 2022
@ashmaroli
Copy link
Copy Markdown
Member

Thank you @lylo.
If you're interested, you may submit another PR to initialize the upstream HTMLTable formatter using keywords instead of a Ruby Hash.

@jekyllbot: merge +minor

@ashmaroli
Copy link
Copy Markdown
Member

@jekyllbot: merge +minor

@jekyllbot jekyllbot merged commit 7558ecb into jekyll:master Nov 3, 2022
jekyllbot added a commit that referenced this pull request Nov 3, 2022
github-actions bot pushed a commit that referenced this pull request Nov 3, 2022
Olly Headey: Allow marking specific highlighted lines via Liquid (#9138)

Merge pull request 9138
@lylo
Copy link
Copy Markdown
Contributor Author

lylo commented Nov 13, 2022

Thank you @lylo. If you're interested, you may submit another PR to initialize the upstream HTMLTable formatter using keywords instead of a Ruby Hash.

Hey @ashmaroli, do you mean changing from:

Rouge::Formatters::HTMLTable.new(
  formatter,
  :css_class    => "highlight",
  :gutter_class => "gutter",
  :code_class   => "code"
)

to:

Rouge::Formatters::HTMLTable.new(
  formatter,
  css_class: "highlight",
  gutter_class: "gutter",
  code_class: "code"
 )

@ashmaroli
Copy link
Copy Markdown
Member

@lylo I did mean that, but I have already made the changes to master.

big-andy-coates added a commit to big-andy-coates/jekyll that referenced this pull request Nov 15, 2022
The use of `mark_lines` in the `highlight` liquid tag is merged, but not yet released. (See jekyll#9138).

It took me some digging to work out why it wasn't working ;)

I'm not sure if this is the correct approach, but this PR tags the feature as released in the upcoming `4.4.0` release...
big-andy-coates added a commit to big-andy-coates/jekyll that referenced this pull request Nov 15, 2022
…l#9138, is merged but not yet released.

The docs on the live site have been updated to reflect this new, but unreleased functionality: https://jekyllrb.com/docs/liquid/tags/#marking-specific-lines. This could be confusing to people... it took me some digging to work out why it wasn't working ;)

I'm not sure if this is the correct approach, but this PR tags the feature in the docs as requiring the upcoming `4.4.0` release...
@jekyll jekyll locked and limited conversation to collaborators Nov 13, 2023
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.

feat: Add line(s) highlighting option

4 participants