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

Highlighting Filepath Strings: Prevent Escapes #33

Open
3 of 4 tasks
tajmone opened this issue Nov 12, 2019 · 0 comments
Open
3 of 4 tasks

Highlighting Filepath Strings: Prevent Escapes #33

tajmone opened this issue Nov 12, 2019 · 0 comments
Labels
🔨 Highlight Tool: Highlight (syntax highlighter) 💀 bug Something isn't working ⭐ css Topic: Custom stylesheets ⭐ syntax highlighting Topic: Syntax Highlighting
Milestone

Comments

@tajmone
Copy link
Owner

tajmone commented Nov 12, 2019

Hugo highlighted code: false positive escapes and interpolations in filepath strings.

  • Temporary CSS workaround:
    • Create .noescapes class to color escapes and interpolations like strings.
    • Add noescapes role to all code blocks where the problem occurs.
  • Fix the Hugo syntax for Highlight.

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):

resource "GAMERES1"
{
    "c:\hugo\graphics\logo.jpg"
    "h:\data\scenic panorama.jpg"
    "h:\data\background.jpg"       <- \b highlighted as "bold end"
    "c:\music\intro_theme.s3m"     <- \i highlighted as "italic end"
    "c:\music\theme2.xm"
    "c:\sounds\sample1.wav"
    "c:\sounds\sample2.wav"
}

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:

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.

@tajmone tajmone added 💀 bug Something isn't working ⭐ syntax highlighting Topic: Syntax Highlighting 🔨 Highlight Tool: Highlight (syntax highlighter) labels Nov 12, 2019
@tajmone tajmone added the ⭐ css Topic: Custom stylesheets label Nov 13, 2019
tajmone added a commit that referenced this issue Nov 13, 2019
Provide a temporary workaround for escape sequences showing up inside
file path strings (see: #33):

* Create CSS class `.noescapes` that colours escapes and interpolations
  like strings, to visually hide the problem.
* Apply `role="noescapes"` to Hugo code blocks with the problem.
  (i.e.: a single example in §12.1)
@tajmone tajmone pinned this issue Nov 13, 2019
@tajmone tajmone added this to the hugo code milestone Nov 13, 2019
@tajmone tajmone unpinned this issue Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 Highlight Tool: Highlight (syntax highlighter) 💀 bug Something isn't working ⭐ css Topic: Custom stylesheets ⭐ syntax highlighting Topic: Syntax Highlighting
Projects
None yet
Development

No branches or pull requests

1 participant