LaTeX reader: cleaned up handling of dimension arguments.

Allow decimal points, preceding space.

Also require text 1.1+.
This commit is contained in:
John MacFarlane 2018-11-19 00:17:22 -08:00
parent fda3e40163
commit 1a679a4d6e
3 changed files with 15 additions and 9 deletions

View file

@ -361,7 +361,7 @@ library
process >= 1.2.3 && < 1.7,
directory >= 1 && < 1.4,
bytestring >= 0.9 && < 0.11,
text >= 0.11 && < 1.3,
text >= 1.1.1.0 && < 1.3,
time >= 1.5 && < 1.10,
safe >= 0.3 && < 0.4,
zip-archive >= 0.2.3.4 && < 0.4,
@ -643,7 +643,7 @@ test-suite test-pandoc
pandoc-types >= 1.17.5 && < 1.18,
bytestring >= 0.9 && < 0.11,
base64-bytestring >= 0.1 && < 1.1,
text >= 0.11 && < 1.3,
text >= 1.1.1.0 && < 1.3,
time >= 1.5 && < 1.10,
directory >= 1 && < 1.4,
filepath >= 1.1 && < 1.5,
@ -727,7 +727,7 @@ benchmark benchmark-pandoc
build-depends: pandoc,
time, bytestring, containers,
base >= 4.8 && < 5,
text >= 0.11 && < 1.3,
text >= 1.1.1.0 && < 1.3,
mtl >= 2.2 && < 2.3,
criterion >= 1.0 && < 1.6
if impl(ghc < 8.0)

View file

@ -1301,7 +1301,7 @@ getRawCommand name txt = do
_ | isFontSizeCommand name -> return ()
| otherwise -> do
skipopts
option "" (try (optional sp *> dimenarg))
option "" (try dimenarg)
void $ many braced
return $ T.unpack (txt <> untokenize rawargs)

View file

@ -105,7 +105,7 @@ import Text.Pandoc.Error (PandocError (PandocMacroLoop))
import Text.Pandoc.Logging
import Text.Pandoc.Options
import Text.Pandoc.Parsing hiding (blankline, many, mathDisplay, mathInline,
optional, space, spaces, withRaw, (<|>))
space, spaces, withRaw, (<|>))
import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
ArgSpec (..), Tok (..), TokType (..))
import Text.Pandoc.Shared
@ -668,13 +668,19 @@ parenWrapped parser = try $ do
dimenarg :: PandocMonad m => LP m Text
dimenarg = try $ do
optional sp
ch <- option False $ True <$ symbol '='
Tok _ _ s <- satisfyTok isWordTok
guard $ T.take 2 (T.reverse s) `elem`
Tok _ _ s1 <- satisfyTok isWordTok
s2 <- option "" $ try $ do
symbol '.'
Tok _ _ t <- satisfyTok isWordTok
return ("." <> t)
let s = s1 <> s2
guard $ T.takeEnd 2 s `elem`
["pt","pc","in","bp","cm","mm","dd","cc","sp"]
let num = T.take (T.length s - 2) s
let num = T.dropEnd 2 s
guard $ T.length num > 0
guard $ T.all isDigit num
guard $ T.all (\c -> isDigit c || c == '.') num
return $ T.pack ['=' | ch] <> s
ignore :: (Monoid a, PandocMonad m) => String -> ParserT s u m a