diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-11-02 12:20:04 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-11-02 12:20:04 -0700 |
commit | 041cfbd5eeffd2bc79447c4894652fc3c108c40d (patch) | |
tree | c25be079905efba7495e1cab775fa0b188ab443c /src/Text/Pandoc/Readers/LaTeX/Parsing.hs | |
parent | 6c9a20b2d322b3cdd112d4b479014407ef38d86e (diff) | |
download | pandoc-041cfbd5eeffd2bc79447c4894652fc3c108c40d.tar.gz |
LaTeX untokenize: Ensure space between control sequence and following letter.
Closes #5836.
Diffstat (limited to 'src/Text/Pandoc/Readers/LaTeX/Parsing.hs')
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX/Parsing.hs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs index af354843a..14cb408b0 100644 --- a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs +++ b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs @@ -92,6 +92,7 @@ import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..), ArgSpec (..), Tok (..), TokType (..)) import Text.Pandoc.Shared import Text.Parsec.Pos +-- import Debug.Trace newtype DottedNum = DottedNum [Int] deriving (Show) @@ -350,10 +351,21 @@ isLowerHex :: Char -> Bool isLowerHex x = x >= '0' && x <= '9' || x >= 'a' && x <= 'f' untokenize :: [Tok] -> Text -untokenize = mconcat . map untoken +untokenize = foldr untokenAccum mempty + +untokenAccum :: Tok -> Text -> Text +untokenAccum (Tok _ (CtrlSeq _) t) accum = + -- insert space to prevent breaking a control sequence; see #5836 + case (T.unsnoc t, T.uncons accum) of + (Just (_,c), Just (d,_)) + | isLetter c + , isLetter d + -> t <> " " <> accum + _ -> t <> accum +untokenAccum (Tok _ _ t) accum = t <> accum untoken :: Tok -> Text -untoken (Tok _ _ t) = t +untoken t = untokenAccum t mempty toksToString :: [Tok] -> String toksToString = T.unpack . untokenize |