Skip to content

Commit

Permalink
ConTeXt: fix handling of spaces in non-normal tokens
Browse files Browse the repository at this point in the history
This ensures that multiple spaces won't be collapsed into a single
space.
  • Loading branch information
tarleb authored and jgm committed Feb 14, 2023
1 parent ddbe3ba commit 71a1081
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion skylighting-format-context/src/Skylighting/Format/ConTeXt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ tokenToConTeXt :: Token -> Text
tokenToConTeXt (NormalTok, txt)
| Text.all isSpace txt = escapeConTeXt txt
tokenToConTeXt (toktype, txt) = "/BTEX\\" <>
(Text.pack (show toktype) <> "{" <> escapeConTeXt txt <> "}/ETEX")
(Text.pack (show toktype) <> "{" <> fixSpaces (escapeConTeXt txt) <> "}/ETEX")
where
-- Always place the second of two consecutive spaces in a group. The
-- ConTeXt parser would otherwise collapse all spaces into a single
-- space.
fixSpaces = Text.replace " " " { }"

escapeConTeXt :: Text -> Text
escapeConTeXt = Text.concatMap escapeConTeXtChar
Expand Down

0 comments on commit 71a1081

Please sign in to comment.