aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-10-17 13:54:09 -0400
committerGitHub <noreply@github.com>2017-10-17 13:54:09 -0400
commit8aa972d9df4446edc1e89c908556bb6aac2bb3b6 (patch)
treeb9d5f2b52fbbba67f2f8153f3ca0f7258b522d75
parentc2de9d749cbc21386e153a4f9efc3049a299cecc (diff)
parent9046dbadb1147a4d9e2b114a2afc1a0292ef7762 (diff)
downloadpandoc-8aa972d9df4446edc1e89c908556bb6aac2bb3b6.tar.gz
Merge pull request #3980 from bfirsh/skip-spaces-in-image-options
Latex reader: Skip spaces in image options
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs2
-rw-r--r--test/Tests/Readers/LaTeX.hs27
2 files changed, 29 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 8c6c7d0ff..b3c637748 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -758,8 +758,10 @@ keyval = try $ do
Tok _ Word key <- satisfyTok isWordTok
let isSpecSym (Tok _ Symbol t) = t `elem` [".",":","-","|","\\"]
isSpecSym _ = False
+ optional sp
val <- option [] $ do
symbol '='
+ optional sp
braced <|> (many1 (satisfyTok isWordTok <|> satisfyTok isSpecSym
<|> anyControlSeq))
optional sp
diff --git a/test/Tests/Readers/LaTeX.hs b/test/Tests/Readers/LaTeX.hs
index 1486ba415..ba9b8e289 100644
--- a/test/Tests/Readers/LaTeX.hs
+++ b/test/Tests/Readers/LaTeX.hs
@@ -108,6 +108,33 @@ tests = [ testGroup "basic"
, biblatexCitations
]
+ , testGroup "images"
+ [ "Basic image" =:
+ "\\includegraphics{foo.png}" =?>
+ para (image "foo.png" "" (text "image"))
+ , "Basic image with blank options" =:
+ "\\includegraphics[]{foo.png}" =?>
+ para (image "foo.png" "" (text "image"))
+ , "Image with both width and height" =:
+ "\\includegraphics[width=17cm,height=5cm]{foo.png}" =?>
+ para (imageWith ("", [], [("width", "17cm"), ("height", "5cm")]) "foo.png" "" "image")
+ , "Image with width and height and a bunch of other options" =:
+ "\\includegraphics[width=17cm,height=5cm,clip,keepaspectratio]{foo.png}" =?>
+ para (imageWith ("", [], [("width", "17cm"), ("height", "5cm")]) "foo.png" "" "image")
+ , "Image with just width" =:
+ "\\includegraphics[width=17cm]{foo.png}" =?>
+ para (imageWith ("", [], [("width", "17cm")]) "foo.png" "" "image")
+ , "Image with just height" =:
+ "\\includegraphics[height=17cm]{foo.png}" =?>
+ para (imageWith ("", [], [("height", "17cm")]) "foo.png" "" "image")
+ , "Image width relative to textsize" =:
+ "\\includegraphics[width=0.6\\textwidth]{foo.png}" =?>
+ para (imageWith ("", [], [("width", "60%")]) "foo.png" "" "image")
+ , "Image with options with spaces" =:
+ "\\includegraphics[width=12cm, height = 5cm]{foo.png}" =?>
+ para (imageWith ("", [], [("width", "12cm"), ("height", "5cm")]) "foo.png" "" "image")
+ ]
+
, let hex = ['0'..'9']++['a'..'f'] in
testGroup "Character Escapes"
[ "Two-character escapes" =: