summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/LaTeX.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-12-08 16:33:29 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2017-12-08 16:34:15 -0800
commit67b6abc8065a290517ff1486d09b4e57fce19733 (patch)
tree2c7125ad85ab3d3954b99ffed8a21d633627709f /src/Text/Pandoc/Readers/LaTeX.hs
parent677ff2aaea256b0793ab471aded7fdc72d47046f (diff)
LaTeX reader: fix \ before newline.
This should be a nonbreaking space, as long as it's not followed by a blank line. This has been fixed at the tokenizer level. Closes #4134.
Diffstat (limited to 'src/Text/Pandoc/Readers/LaTeX.hs')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index d1d9682c3..90d0fe5d1 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -332,9 +332,20 @@ totoks pos t =
in Tok pos (CtrlSeq ws) ("\\" <> ws <> ss)
: totoks (incSourceColumn pos
(1 + T.length ws + T.length ss)) rest'''
- | d == '\t' || d == '\n' ->
- Tok pos Symbol "\\"
- : totoks (incSourceColumn pos 1) rest
+ | isSpaceOrTab d || d == '\n' ->
+ let (w1, r1) = T.span isSpaceOrTab rest
+ (w2, (w3, r3)) = case T.uncons r1 of
+ Just ('\n', r2)
+ -> (T.pack "\n",
+ T.span isSpaceOrTab r2)
+ _ -> (mempty, (w1, r1))
+ in case T.uncons r3 of
+ Just ('\n', _) ->
+ Tok pos (CtrlSeq " ") ("\\" <> w1)
+ : totoks (incSourceColumn pos 1) r1
+ _ ->
+ Tok pos (CtrlSeq " ") ("\\" <> w1 <> w2 <> w3)
+ : totoks (incSourceColumn pos 1) r3
| otherwise ->
Tok pos (CtrlSeq (T.singleton d)) (T.pack [c,d])
: totoks (incSourceColumn pos 2) rest'