git.iko.soy/typeable/pandoc
on master help sign in
RST reader: image attributes
commit30644b291b7a23c4e41b69611a8ee5c8d386c3c3 authormb21 <mb21@users.noreply.github.com> dateThu 3 Dec 2015, 11:50 (11 years ago) parente4b3da6
2 files changed+15−8
src/Text/Pandoc/Readers/RST.hs+14−7 tests/rst-reader.native+1−1
src/Text/Pandoc/Readers/RST.hs+14−7
@@ -541,6 +541,12 @@ directive' = do
541541 body <- option "" $ try $ blanklines >> indentedBlock
542542 optional blanklines
543543 let body' = body ++ "\n\n"
544+ imgAttr cl = ("", classes, getAtt "width" ++ getAtt "height")
545+ where
546+ classes = words $ maybe "" trim $ lookup cl fields
547+ getAtt k = case lookup k fields of
548+ Just v -> [(k, filter (not . isSpace) v)]
549+ Nothing -> []
544550 case label of
545551 "raw" -> return $ B.rawBlock (trim top) (stripTrailingNewlines body)
546552 "role" -> addNewRole top $ map (\(k,v) -> (k, trim v)) fields
@@ -590,15 +596,16 @@ directive' = do
590596 "figure" -> do
591597 (caption, legend) <- parseFromString extractCaption body'
592598 let src = escapeURI $ trim top
593− return $ B.para (B.image src "fig:" caption) <> legend
599+ return $ B.para (B.imageWith (imgAttr "figclass") src "fig:" caption) <> legend
594600 "image" -> do
595601 let src = escapeURI $ trim top
596602 let alt = B.str $ maybe "image" trim $ lookup "alt" fields
603+ let attr = imgAttr "class"
597604 return $ B.para
598605 $ case lookup "target" fields of
599606 Just t -> B.link (escapeURI $ trim t) ""
600− $ B.image src "" alt
601− Nothing -> B.image src "" alt
607+ $ B.imageWith attr src "" alt
608+ Nothing -> B.imageWith attr src "" alt
602609 "class" -> do
603610 let attrs = ("", (splitBy isSpace $ trim top), map (\(k,v) -> (k, trimr v)) fields)
604611 -- directive content or the first immediately following element
@@ -812,10 +819,10 @@ substKey = try $ do
812819 res <- B.toList <$> directive'
813820 il <- case res of
814821 -- use alt unless :alt: attribute on image:
815− [Para [Image _ [Str "image"] (src,tit)]] ->
816− return $ B.image src tit alt
817− [Para [Link _ [Image _ [Str "image"] (src,tit)] (src',tit')]] ->
818− return $ B.link src' tit' (B.image src tit alt)
822+ [Para [Image attr [Str "image"] (src,tit)]] ->
823+ return $ B.imageWith attr src tit alt
824+ [Para [Link _ [Image attr [Str "image"] (src,tit)] (src',tit')]] ->
825+ return $ B.link src' tit' (B.imageWith attr src tit alt)
819826 [Para ils] -> return $ B.fromList ils
820827 _ -> mzero
821828 let key = toKey $ stripFirstAndLast ref
tests/rst-reader.native+1−1
@@ -221,7 +221,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
221221,Header 1 ("images",[],[]) [Str "Images"]
222222,Para [Str "From",Space,Quoted DoubleQuote [Str "Voyage",Space,Str "dans",Space,Str "la",Space,Str "Lune"],Space,Str "by",Space,Str "Georges",Space,Str "Melies",Space,Str "(1902):"]
223223,Para [Image ("",[],[]) [Str "image"] ("lalune.jpg","")]
224−,Para [Image ("",[],[]) [Str "Voyage dans la Lune"] ("lalune.jpg","")]
224+,Para [Image ("",[],[("height","2343")]) [Str "Voyage dans la Lune"] ("lalune.jpg","")]
225225,Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "movie",Space,Image ("",[],[]) [Str "movie"] ("movie.jpg",""),Space,Str "icon."]
226226,Para [Str "And",Space,Str "an",Space,Link ("",[],[]) [Image ("",[],[]) [Str "A movie"] ("movie.jpg","")] ("/url",""),Str "."]
227227,Header 1 ("comments",[],[]) [Str "Comments"]