jgm / skylighting

A Haskell syntax highlighting library with tokenizers derived from KDE syntax highlighting descriptions
190 stars 61 forks source link

bash syntax highlighting broken for same-line comments with extra spaces #54

Closed uvtc closed 5 years ago

uvtc commented 5 years ago

Using:

$ pandoc --version
pandoc 2.2.1
Compiled with pandoc-types 1.17.4.2, texmath 0.10.1.1, skylighting 0.6

bash syntax highlighting works for

~~~bash
foo # A comment's here.
barbaz # It's here too.
exit

but breaks if you add more spaces before the `#`:
foo     # A comment's here.
barbaz  # It's here too.
exit

This fails too:
foo    # A comment's here.
barbaz # It's here too.
exit


even though `barbaz` has only one space after it before the comment character.
uvtc commented 5 years ago

Ah, "trailing comments" was the phrase I was looking for.

jgm commented 5 years ago

This patch to bash.xml seems to do the trick. I don't know if it has any other side effects, though. It would be good to test Kate to see if it has this bug, or if there's an issue in skylighting itself.

diff --git a/skylighting-core/xml/bash.xml b/skylighting-core/xml/bash.xml
index cdfdf95..d83d718 100644
--- a/skylighting-core/xml/bash.xml
+++ b/skylighting-core/xml/bash.xml
@@ -482,7 +482,7 @@
       <!-- FindComments consumes shell comments till EOL -->
       <context attribute="Normal Text" lineEndContext="#pop" name="FindComments">
         <DetectChar attribute="Comment" context="Comment" char="#" firstNonSpace="true"/>
-        <RegExpr attribute="Normal Text" context="Comment" String="[\s;](?=#)" />
+        <RegExpr attribute="Normal Text" context="Comment" String="\s*[\s;](?=#)" />
       </context>
       <context attribute="Comment" lineEndContext="#pop" name="Comment">
         <IncludeRules context="##Alerts" />
uvtc commented 3 years ago

Was this change ever made to skylighting? I just noticed that I still have the same issue (using the stock Pandoc that comes with Debian Testing, v2.9.2.1).

uvtc commented 3 years ago

This particularly causes a problem when the trailing comment has an apostrophe in it, which when not in a comment looks like a hard quote to the syntax highlighter.

jgm commented 3 years ago

The version of pandoc in debian testing is very old. Try installing our own debian package from jgm/pandoc Releases.

uvtc commented 3 years ago

Ah. Wonderful. Using 2.14.0.3 now. Easy to install the deb. Works perfectly now. Thanks so much.