markup/rst: Make syntax highlighting configurable#14841
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
|
Hi, The new integration test uses Severity: remediation recommended | Category: security How to fix: Anchor allow-list pattern Agent prompt to fix - you can give this to your LLM of choice:
We noticed a couple of other issues in this PR as well - happy to share if helpful. Found by Qodo code review |
|
Addressed in 22984f4: updated test config to use anchored allow-list regex (^rst2html$). |
|
Agreed, thanks @bep. The previous test used a fake rst2html only to verify the added flag, but I agree that this is better covered with the real executable. Updated the test to use the real rst2html path installed in CI and added Pygments to the CI setup so the syntax-highlight output is actually exercised. |
|
Follow-up CI note: the current failure is unrelated to this RST PR. It is the existing TestNPMGlobalInstalls failure already present on master, caused by an exact Tailwind CSS byte-size assertion changing from 4557 to 4479. I opened #14860 separately to fix that CI fragility, and its checks are green. Keeping this PR scoped to the RST change. |
| - name: Install docutils | ||
| run: | | ||
| pip install docutils | ||
| pip install docutils Pygments |
There was a problem hiding this comment.
I will have to get back to this later, but if this patch requires pygments (I suspect it's lowercase?), I think we need to reconsider doing this as the new default (as many may not want it) ... We could add a config struct for rst similar to what we have for the other markup engines with a sensible option with a comment that you would need to install pygments for it to work. I'm not totally sure about this, though.
There was a problem hiding this comment.
Good point, thanks.
I changed this to avoid making --syntax-highlight=short the new default. The PR now adds an explicit markup.rst.syntaxHighlight setting instead, with Docutils' default long preserved.
The CI setup also no longer installs pygments; the integration test uses syntaxHighlight = "none" so it verifies the Hugo/rst2html configuration path without adding a new CI dependency. The docs mention that Docutils needs Pygments available when users want highlighted code blocks.
So the short class names are now opt-in via:
[markup.rst]
syntaxHighlight = "short"There was a problem hiding this comment.
@bep Highlighted code classes require the Pygments library. This is an existing requirement (not related to this PR) if you want to perform syntax highlighting, but since pip install docutils doesn’t include it by default (unlike the python3-docutils apt package), our CI currently lacks it. Without Pygments in CI, we can't run affirmative integration tests for this PR.
Add markup.rst.syntaxHighlight and pass Docutils' --syntax-highlight option only when configured away from the rst2html default. Fixes gohugoio#5349
6e9de20 to
d0ff51b
Compare
|
Although the configuration key [markup.rst.highlight]
classNaming = 'long'With this description:
|
|
@bep were you able to verify this PR? Do you think it needs any adjustments? |
|
See my previous comments. This should not be merged. |
Fixes #5349
Supersedes #14659
Summary
markup.rst.syntaxHighlightwith Docutils' CLI default (long)--syntax-highlightonly when configured asshortornonerst2htmlrender path without requiring PygmentsNotes
longsyntax classes.rst2html/rst2html.pyon Unix-like systems,python/python.exeon Windows.Tests
go test ./hugolib -run TestRSTSyntaxHighlightConfigIssue5349 -count=1./check.sh ./markup/rst/..../check.sh ./markup/markup_config/..../check.sh ./hugolib/...AI assistance disclosure: