git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: cleaned up handling of dimension arguments.

Allow decimal points, preceding space. Also require text 1.1+.

commit1a679a4d6e99f4bdb19f1f546a0ccf856ba00cf4 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 19 Nov 2018, 00:17 (8 years ago) parentfda3e40
3 files changed+15−9
pandoc.cabal+3−3 src/Text/Pandoc/Readers/LaTeX.hs+1−1 src/Text/Pandoc/Readers/LaTeX/Parsing.hs+11−5
pandoc.cabal+3−3
@@ -361,7 +361,7 @@ library
361361 process >= 1.2.3 && < 1.7,
362362 directory >= 1 && < 1.4,
363363 bytestring >= 0.9 && < 0.11,
364− text >= 0.11 && < 1.3,
364+ text >= 1.1.1.0 && < 1.3,
365365 time >= 1.5 && < 1.10,
366366 safe >= 0.3 && < 0.4,
367367 zip-archive >= 0.2.3.4 && < 0.4,
@@ -643,7 +643,7 @@ test-suite test-pandoc
643643 pandoc-types >= 1.17.5 && < 1.18,
644644 bytestring >= 0.9 && < 0.11,
645645 base64-bytestring >= 0.1 && < 1.1,
646− text >= 0.11 && < 1.3,
646+ text >= 1.1.1.0 && < 1.3,
647647 time >= 1.5 && < 1.10,
648648 directory >= 1 && < 1.4,
649649 filepath >= 1.1 && < 1.5,
@@ -727,7 +727,7 @@ benchmark benchmark-pandoc
727727 build-depends: pandoc,
728728 time, bytestring, containers,
729729 base >= 4.8 && < 5,
730− text >= 0.11 && < 1.3,
730+ text >= 1.1.1.0 && < 1.3,
731731 mtl >= 2.2 && < 2.3,
732732 criterion >= 1.0 && < 1.6
733733 if impl(ghc < 8.0)
src/Text/Pandoc/Readers/LaTeX.hs+1−1
@@ -1301,7 +1301,7 @@ getRawCommand name txt = do
13011301 _ | isFontSizeCommand name -> return ()
13021302 | otherwise -> do
13031303 skipopts
1304− option "" (try (optional sp *> dimenarg))
1304+ option "" (try dimenarg)
13051305 void $ many braced
13061306 return $ T.unpack (txt <> untokenize rawargs)
13071307
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+11−5
@@ -105,7 +105,7 @@ import Text.Pandoc.Error (PandocError (PandocMacroLoop))
105105import Text.Pandoc.Logging
106106import Text.Pandoc.Options
107107import Text.Pandoc.Parsing hiding (blankline, many, mathDisplay, mathInline,
108− optional, space, spaces, withRaw, (<|>))
108+ space, spaces, withRaw, (<|>))
109109import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
110110 ArgSpec (..), Tok (..), TokType (..))
111111import Text.Pandoc.Shared
@@ -668,13 +668,19 @@ parenWrapped parser = try $ do
668668
669669dimenarg :: PandocMonad m => LP m Text
670670dimenarg = try $ do
671+ optional sp
671672 ch <- option False $ True <$ symbol '='
672− Tok _ _ s <- satisfyTok isWordTok
673− guard $ T.take 2 (T.reverse s) `elem`
673+ Tok _ _ s1 <- satisfyTok isWordTok
674+ s2 <- option "" $ try $ do
675+ symbol '.'
676+ Tok _ _ t <- satisfyTok isWordTok
677+ return ("." <> t)
678+ let s = s1 <> s2
679+ guard $ T.takeEnd 2 s `elem`
674680 ["pt","pc","in","bp","cm","mm","dd","cc","sp"]
675− let num = T.take (T.length s - 2) s
681+ let num = T.dropEnd 2 s
676682 guard $ T.length num > 0
677− guard $ T.all isDigit num
683+ guard $ T.all (\c -> isDigit c || c == '.') num
678684 return $ T.pack ['=' | ch] <> s
679685
680686ignore :: (Monoid a, PandocMonad m) => String -> ParserT s u m a