Skip to content

Commit 6dc0e1f

Browse files
committed
Capture alt-text in JATS figures
1 parent 899e0c0 commit 6dc0e1f

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/Text/Pandoc/Readers/JATS.hs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import Text.Pandoc.XML.Light
3535
import qualified Data.Set as S (fromList, member)
3636
import Data.Set ((\\))
3737
import Text.Pandoc.Sources (ToSources(..), sourcesToText)
38+
import qualified Data.Foldable as DF
3839

3940
type JATS m = StateT JATSState m
4041

@@ -226,9 +227,19 @@ parseBlock (Elem e) =
226227
mapM getInlines
227228
(filterChildren (const True) t)
228229
Nothing -> return mempty
229-
img <- getGraphic (Just (capt, attrValue "id" e)) g
230-
return $ para img
230+
231+
let figAttributes = DF.toList $
232+
("alt", ) . strContent <$>
233+
filterChild (named "alt-text") e
234+
235+
return $ simpleFigureWith
236+
(attrValue "id" e, [], figAttributes)
237+
capt
238+
(attrValue "href" g)
239+
(attrValue "title" g)
240+
231241
_ -> divWith (attrValue "id" e, ["fig"], []) <$> getBlocks e
242+
232243
parseTable = do
233244
let isCaption x = named "title" x || named "caption" x
234245
capt <- case filterChild isCaption e of
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```
2+
% pandoc -f jats -t native
3+
<fig id="fig-1">
4+
<caption>
5+
<p>bar</p>
6+
</caption>
7+
<alt-text>alternative-decription</alt-text>
8+
<graphic xlink:href="foo.png" xlink:alt-text="baz" />
9+
</fig>
10+
^D
11+
[Para [Image ("fig-1",[],[("alt","alternative-decription")]) [Str "bar"] ("foo.png","fig:")]]
12+
```

0 commit comments

Comments
 (0)