git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #3980 from bfirsh/skip-spaces-in-image-options

Latex reader: Skip spaces in image options

commit8aa972d9df4446edc1e89c908556bb6aac2bb3b6 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 17 Oct 2017, 13:54 (9 years ago) parentc2de9d79046dba
2 files changed+29
src/Text/Pandoc/Readers/LaTeX.hs+2 test/Tests/Readers/LaTeX.hs+27
src/Text/Pandoc/Readers/LaTeX.hs+2
@@ -758,8 +758,10 @@ keyval = try $ do
758758 Tok _ Word key <- satisfyTok isWordTok
759759 let isSpecSym (Tok _ Symbol t) = t `elem` [".",":","-","|","\\"]
760760 isSpecSym _ = False
761+ optional sp
761762 val <- option [] $ do
762763 symbol '='
764+ optional sp
763765 braced <|> (many1 (satisfyTok isWordTok <|> satisfyTok isSpecSym
764766 <|> anyControlSeq))
765767 optional sp
test/Tests/Readers/LaTeX.hs+27
@@ -108,6 +108,33 @@ tests = [ testGroup "basic"
108108 , biblatexCitations
109109 ]
110110
111+ , testGroup "images"
112+ [ "Basic image" =:
113+ "\\includegraphics{foo.png}" =?>
114+ para (image "foo.png" "" (text "image"))
115+ , "Basic image with blank options" =:
116+ "\\includegraphics[]{foo.png}" =?>
117+ para (image "foo.png" "" (text "image"))
118+ , "Image with both width and height" =:
119+ "\\includegraphics[width=17cm,height=5cm]{foo.png}" =?>
120+ para (imageWith ("", [], [("width", "17cm"), ("height", "5cm")]) "foo.png" "" "image")
121+ , "Image with width and height and a bunch of other options" =:
122+ "\\includegraphics[width=17cm,height=5cm,clip,keepaspectratio]{foo.png}" =?>
123+ para (imageWith ("", [], [("width", "17cm"), ("height", "5cm")]) "foo.png" "" "image")
124+ , "Image with just width" =:
125+ "\\includegraphics[width=17cm]{foo.png}" =?>
126+ para (imageWith ("", [], [("width", "17cm")]) "foo.png" "" "image")
127+ , "Image with just height" =:
128+ "\\includegraphics[height=17cm]{foo.png}" =?>
129+ para (imageWith ("", [], [("height", "17cm")]) "foo.png" "" "image")
130+ , "Image width relative to textsize" =:
131+ "\\includegraphics[width=0.6\\textwidth]{foo.png}" =?>
132+ para (imageWith ("", [], [("width", "60%")]) "foo.png" "" "image")
133+ , "Image with options with spaces" =:
134+ "\\includegraphics[width=12cm, height = 5cm]{foo.png}" =?>
135+ para (imageWith ("", [], [("width", "12cm"), ("height", "5cm")]) "foo.png" "" "image")
136+ ]
137+
111138 , let hex = ['0'..'9']++['a'..'f'] in
112139 testGroup "Character Escapes"
113140 [ "Two-character escapes" =: