diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2021-11-20 18:48:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-20 09:48:01 -0800 |
commit | 96a4bbe264b6eba8d334df0177d17a75e269bb47 (patch) | |
tree | 2772f3cdf7befe3447127ae0820818a760e0cc6d | |
parent | db9a73c84259beb8679a838ed4cd44fbdf45c568 (diff) | |
download | pandoc-96a4bbe264b6eba8d334df0177d17a75e269bb47.tar.gz |
Capture `alt-text` in JATS figures (#7703)
Co-authored-by: Aner Lucero <4rgento@gmail.com>
-rw-r--r-- | src/Text/Pandoc/Readers/JATS.hs | 15 | ||||
-rw-r--r-- | test/command/jats-figure-alt-text.md | 18 |
2 files changed, 31 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/JATS.hs b/src/Text/Pandoc/Readers/JATS.hs index 9cdbf1611..37e0d13bc 100644 --- a/src/Text/Pandoc/Readers/JATS.hs +++ b/src/Text/Pandoc/Readers/JATS.hs @@ -35,6 +35,7 @@ import Text.Pandoc.XML.Light import qualified Data.Set as S (fromList, member) import Data.Set ((\\)) import Text.Pandoc.Sources (ToSources(..), sourcesToText) +import qualified Data.Foldable as DF type JATS m = StateT JATSState m @@ -226,9 +227,19 @@ parseBlock (Elem e) = mapM getInlines (filterChildren (const True) t) Nothing -> return mempty - img <- getGraphic (Just (capt, attrValue "id" e)) g - return $ para img + + let figAttributes = DF.toList $ + ("alt", ) . strContent <$> + filterChild (named "alt-text") e + + return $ simpleFigureWith + (attrValue "id" e, [], figAttributes) + capt + (attrValue "href" g) + (attrValue "title" g) + _ -> divWith (attrValue "id" e, ["fig"], []) <$> getBlocks e + parseTable = do let isCaption x = named "title" x || named "caption" x capt <- case filterChild isCaption e of diff --git a/test/command/jats-figure-alt-text.md b/test/command/jats-figure-alt-text.md new file mode 100644 index 000000000..229e52eda --- /dev/null +++ b/test/command/jats-figure-alt-text.md @@ -0,0 +1,18 @@ +``` +% pandoc -f jats -t native +<fig id="fig-1"> + <caption> + <p>bar</p> + </caption> + <alt-text>alternative-decription</alt-text> + <graphic xlink:href="foo.png" xlink:alt-text="baz" /> +</fig> +^D +[ Para + [ Image + ( "fig-1" , [] , [ ( "alt" , "alternative-decription" ) ] ) + [ Str "bar" ] + ( "foo.png" , "fig:" ) + ] +] +``` |