Skip to content

markup/highlight: Adjust inline markup #9638

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

Closed
wants to merge 1 commit into from

Conversation

bep
Copy link
Member

@bep bep commented Mar 9, 2022

See #9634
Closes #9635

@bep bep force-pushed the fix/inline-hl-take2-9635 branch from 2f28623 to d3344a4 Compare March 9, 2022 16:22
@bep bep force-pushed the fix/inline-hl-take2-9635 branch from d3344a4 to c235fcf Compare March 9, 2022 16:34
func (h *HightlightResult) Inner() template.HTML {
h.innerInit.Do(func() {
inner := string(h.highlighted[h.innerLow:h.innerHigh])
if h.inline {
Copy link
Member Author

Choose a reason for hiding this comment

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

@kaushalmodi
Copy link
Contributor

kaushalmodi commented Mar 9, 2022

I think this change will work. I would only suggest that the display:flex; regex be made stricter.

If a user does {{< highlight text "hl_inline=true" >}}display:flex;{{< /highlight >}}, it will wipe off the content "display:flex;" as well!

Suggestion:

replaceRE `<span style="display:flex;">` `<span>` ..

or

replaceRE `<span style="(.*?)display:flex;(.*?)">` `<span style="${1}${2}">` ..

With that, even if the user has <span style="display:flex;"> in their inline block content, that will stay safe as that will be HTML escaped first to &lt;span style=&#34;display:flex;&#34;&gt;.

@bep
Copy link
Member Author

bep commented Mar 9, 2022

@kaushalmodi did you say something somewhere about the flex style?

@kaushalmodi
Copy link
Contributor

did you say something somewhere about the flex style?

I haven't yet, but given that the current regex display:flex; doesn't have any special HTML chars like <, it can easily match that in the highlight shortcode content text too.

@kaushalmodi
Copy link
Contributor

@bep I had opened an issue on chroma regarding display:flex;, and I got a reply: alecthomas/chroma#617 (comment)

Does this help from there?

You should also be able to override the line style like this, using chroma.Line class.

inner := string(h.highlighted[h.innerLow:h.innerHigh])
if h.inline {
inner = strings.Replace(inner, `<span class="line">`, `<span class="chroma inline">`, 1)
inner = strings.Replace(inner, "display:flex;", "", -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

@bep am I missing something or would this unconditionally replace the string display:flex; anywhere in the user provided code snippet? For example what happens if I do this?

{{< highlight css "hl_inline=true" >}}.line { display:flex; }{{< /highlight >}}

Copy link
Contributor

Choose a reason for hiding this comment

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

See #9638 (comment) 😄

Copy link
Member Author

@bep bep Mar 10, 2022

Choose a reason for hiding this comment

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

Yea, I will take another look at this today, I had a massive day of "doing everything on my list" yesterday, and this came in late ... I'm sure Chroma has a better API for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@kaushalmodi ah, thankssorry I missed your comment I was just looking at the diffs.

Copy link
Contributor

Choose a reason for hiding this comment

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

@marshall007 You might be interested in alecthomas/chroma#618. After that, these replaceRE hacks won't be needed in Hugo.

@bep
Copy link
Member Author

bep commented Mar 10, 2022

See my comment in alecthomas/chroma#617 (comment)

We need to wait for a fix upstream, so I need to revert this "inline thing", but I'll keep this PR open so I can finish it when time is right.

@kaushalmodi
Copy link
Contributor

kaushalmodi commented Mar 14, 2022

@bep This fix is waiting in the Chroma PR, and will need Hugo to use the new InlineCode option: alecthomas/chroma#618 for Inline highlighting. Can you review that PR?

Thanks.

@kaushalmodi
Copy link
Contributor

@bep This PR was feature complete. Only the regex part was hacky, but those are internal details. Can you please merge this feature in, and then update the internal Chroma API when that gets fixed upstream?

@kaushalmodi
Copy link
Contributor

@bep Can you please take another look at this? The feature was working great with with regex fix 😃 . I'll really appreciate if this feature can go in first. When a proper fix arrives from upstream Chroma, that fix will be transparent to the users.

bep added a commit to bep/hugo that referenced this pull request Jun 15, 2022
@kaushalmodi kaushalmodi mentioned this pull request Jun 15, 2022
bep added a commit to bep/hugo that referenced this pull request Jun 15, 2022
@bep bep closed this in d863dde Jun 15, 2022
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refinement of the highlight hl_inline option
3 participants