Skip to content

Commit

Permalink
Capture alt-text in JATS figures
Browse files Browse the repository at this point in the history
  • Loading branch information
argent0 committed Sep 9, 2021
1 parent 899e0c0 commit 6dc0e1f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Text/Pandoc/Readers/JATS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/command/jats-figure-alt-text.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
```
% 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:")]]
```

0 comments on commit 6dc0e1f

Please sign in to comment.