git.iko.soy/typeable/pandoc
on master help sign in
RST reader: image attributes
30644b2mb21
src/Text/Pandoc/Readers/RST.hs+14−7
@@ -541,6 +541,12 @@ directive' = do
541 body <- option "" $ try $ blanklines >> indentedBlock
541 body <- option "" $ try $ blanklines >> indentedBlock
542 optional blanklines
542 optional blanklines
543 let body' = body ++ "\n\n"
543 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 -> []
544 case label of
550 case label of
545 "raw" -> return $ B.rawBlock (trim top) (stripTrailingNewlines body)
551 "raw" -> return $ B.rawBlock (trim top) (stripTrailingNewlines body)
546 "role" -> addNewRole top $ map (\(k,v) -> (k, trim v)) fields
552 "role" -> addNewRole top $ map (\(k,v) -> (k, trim v)) fields
@@ -590,15 +596,16 @@ directive' = do
590 "figure" -> do
596 "figure" -> do
591 (caption, legend) <- parseFromString extractCaption body'
597 (caption, legend) <- parseFromString extractCaption body'
592 let src = escapeURI $ trim top
598 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
594 "image" -> do
600 "image" -> do
595 let src = escapeURI $ trim top
601 let src = escapeURI $ trim top
596 let alt = B.str $ maybe "image" trim $ lookup "alt" fields
602 let alt = B.str $ maybe "image" trim $ lookup "alt" fields
603+ let attr = imgAttr "class"
597 return $ B.para
604 return $ B.para
598 $ case lookup "target" fields of
605 $ case lookup "target" fields of
599 Just t -> B.link (escapeURI $ trim t) ""
606 Just t -> B.link (escapeURI $ trim t) ""
600− $ B.image src "" alt
607+ $ B.imageWith attr src "" alt
601− Nothing -> B.image src "" alt
608+ Nothing -> B.imageWith attr src "" alt
602 "class" -> do
609 "class" -> do
603 let attrs = ("", (splitBy isSpace $ trim top), map (\(k,v) -> (k, trimr v)) fields)
610 let attrs = ("", (splitBy isSpace $ trim top), map (\(k,v) -> (k, trimr v)) fields)
604 -- directive content or the first immediately following element
611 -- directive content or the first immediately following element
@@ -812,10 +819,10 @@ substKey = try $ do
812 res <- B.toList <$> directive'
819 res <- B.toList <$> directive'
813 il <- case res of
820 il <- case res of
814 -- use alt unless :alt: attribute on image:
821 -- use alt unless :alt: attribute on image:
815− [Para [Image _ [Str "image"] (src,tit)]] ->
822+ [Para [Image attr [Str "image"] (src,tit)]] ->
816− return $ B.image src tit alt
823+ return $ B.imageWith attr src tit alt
817− [Para [Link _ [Image _ [Str "image"] (src,tit)] (src',tit')]] ->
824+ [Para [Link _ [Image attr [Str "image"] (src,tit)] (src',tit')]] ->
818− return $ B.link src' tit' (B.image src tit alt)
825+ return $ B.link src' tit' (B.imageWith attr src tit alt)
819 [Para ils] -> return $ B.fromList ils
826 [Para ils] -> return $ B.fromList ils
820 _ -> mzero
827 _ -> mzero
821 let key = toKey $ stripFirstAndLast ref
828 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
221,Header 1 ("images",[],[]) [Str "Images"]
221,Header 1 ("images",[],[]) [Str "Images"]
222,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):"]
222,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):"]
223,Para [Image ("",[],[]) [Str "image"] ("lalune.jpg","")]
223,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","")]
225,Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "movie",Space,Image ("",[],[]) [Str "movie"] ("movie.jpg",""),Space,Str "icon."]
225,Para [Str "Here",Space,Str "is",Space,Str "a",Space,Str "movie",Space,Image ("",[],[]) [Str "movie"] ("movie.jpg",""),Space,Str "icon."]
226,Para [Str "And",Space,Str "an",Space,Link ("",[],[]) [Image ("",[],[]) [Str "A movie"] ("movie.jpg","")] ("/url",""),Str "."]
226,Para [Str "And",Space,Str "an",Space,Link ("",[],[]) [Image ("",[],[]) [Str "A movie"] ("movie.jpg","")] ("/url",""),Str "."]
227,Header 1 ("comments",[],[]) [Str "Comments"]
227,Header 1 ("comments",[],[]) [Str "Comments"]