Highlighting Filepath Strings: Prevent Escapes #33
Labels
🔨 Highlight
Tool: Highlight (syntax highlighter)
💀 bug
Something isn't working
⭐ css
Topic: Custom stylesheets
⭐ syntax highlighting
Topic: Syntax Highlighting
Milestone
Hugo highlighted code: false positive escapes and interpolations in filepath strings.
.noescapes
class to color escapes and interpolations like strings.noescapes
role to all code blocks where the problem occurs.The Problem
Currently, the HL Hugo syntax looks for escapes and interpolations inside all strings, which is a problem when dealing with filepath strings containing Windows paths, where the backslash dir separator can lead to false positive escape sequences and special characters (interpolations in HL syntax).
An example of this can be seen in §12.1 (commit 37d44a0), before the CSS patch (click here for current view):
While the syntax was already fixed to prevent escapes and interpolations inside compiler directive strings for
#include
and#link
, fixing the above problem is turning out trickier than expected.I need to find a way to distinguish between text- and path-strings, by introducing some state tracking variable after keywords like
resource
,image
and all other keywords which are followed by a filepath string.So far, all attempts in this direction failed (i.e. they didn't work for multiple strings, like in the above example).
Real tests for this can be found on the Hugo dev branch of the Highlight Test Suite on GitLab:
syntax_test_filepaths-include.hug
syntax_test_filepaths-resources.hug
A Quick Workaround
As a temporary solution, I can create a
.noescape
CSS rule that colors escape sequences and interpolations with the same color as strings, effectively hiding the problem to the eye.The text was updated successfully, but these errors were encountered: