diff options
| -rw-r--r-- | src/Text/Pandoc/Readers/JATS.hs | 20 | ||||
| -rw-r--r-- | test/Tests/Readers/JATS.hs | 36 | ||||
| -rw-r--r-- | test/command/5321.md | 8 | ||||
| -rw-r--r-- | test/command/jats-figure-alt-text.md | 7 | ||||
| -rw-r--r-- | test/jats-reader.native | 46 | ||||
| -rw-r--r-- | test/jats-reader.xml | 34 |
6 files changed, 121 insertions, 30 deletions
diff --git a/src/Text/Pandoc/Readers/JATS.hs b/src/Text/Pandoc/Readers/JATS.hs index fd90044af..6cadef306 100644 --- a/src/Text/Pandoc/Readers/JATS.hs +++ b/src/Text/Pandoc/Readers/JATS.hs @@ -138,18 +138,16 @@ trimNl = T.dropAround (== '\n') -- function that is used by both graphic (in parseBlock) -- and inline-graphic (in parseInline) -getGraphic :: PandocMonad m - => Maybe (Inlines, Text) -> Element -> JATS m Inlines -getGraphic mbfigdata e = do +getGraphic :: PandocMonad m => Element -> JATS m Inlines +getGraphic e = do let atVal a = attrValue a e - (ident, title, capt) = - case mbfigdata of - Just (capt', i) -> (i, "fig:" <> atVal "title", capt') - Nothing -> (atVal "id", atVal "title", - text (atVal "alt-text")) + let altText = case filterElement (named "alt-text") e of + Just alt -> textContent alt + Nothing -> mempty + (ident, title, altText') = (atVal "id", atVal "title", text altText) attr = (ident, T.words $ atVal "role", []) imageUrl = atVal "href" - return $ imageWith attr imageUrl title capt + return $ imageWith attr imageUrl title altText' getBlocks :: PandocMonad m => Element -> JATS m Blocks getBlocks e = mconcat <$> @@ -198,7 +196,7 @@ parseBlock (Elem e) = do "table-wrap-foot" -> parseBlockWithHeader "trans-abstract" -> parseBlockWithHeader "verse-group" -> parseBlockWithHeader - "graphic" -> para <$> getGraphic Nothing e + "graphic" -> para <$> getGraphic e "journal-meta" -> parseMetadata e "article-meta" -> parseMetadata e "custom-meta" -> parseMetadata e @@ -622,7 +620,7 @@ parseInline (Elem e) = "code" -> codeWithLang "monospace" -> codeWithLang - "inline-graphic" -> getGraphic Nothing e + "inline-graphic" -> getGraphic e "disp-quote" -> do qt <- gets jatsQuoteType let qt' = if qt == SingleQuote then DoubleQuote else SingleQuote diff --git a/test/Tests/Readers/JATS.hs b/test/Tests/Readers/JATS.hs index b7d36dc00..7a49d5e12 100644 --- a/test/Tests/Readers/JATS.hs +++ b/test/Tests/Readers/JATS.hs @@ -35,6 +35,42 @@ tests = [ testGroup "inline code" , testGroup "images" [ test jats "basic" $ "<graphic mimetype=\"image\" mime-subtype=\"\" xlink:href=\"/url\" xlink:title=\"title\" />" =?> para (image "/url" "title" mempty) + , test jats "alt-text" $ + "<graphic id=\"graphic001\"\n\ + \ xlink:href=\"https://lh3.googleusercontent.com/dB7iirJ3ncQaVMBGE2YX-WCeoAVIChb6NAzoFcKCFChMsrixJvD7ZRbvcaC-ceXEzXYaoH4K5vaoRDsUyBHFkpIDPnsn3bnzovbvi0a2Gg=s660\"\n\ + \ xlink:title=\"This is the title of the graphic\"\n\ + \ xlink:role=\"This is the role of the graphic\">\n\ + \ <alt-text>Alternative text of the graphic</alt-text>\n\ + \ <caption>\n\ + \ <title>This is the title of the caption</title>\n\ + \ <p>Google doodle from 14 March 2003</p></caption>\n\ + \ </graphic>" + =?> Para [ Image + ( "graphic001" + , [ "This" + , "is" + , "the" + , "role" + , "of" + , "the" + , "graphic" + ] + , [] + ) + [ Str "Alternative" + , Space + , Str "text" + , Space + , Str "of" + , Space + , Str "the" + , Space + , Str "graphic" + ] + ( "https://lh3.googleusercontent.com/dB7iirJ3ncQaVMBGE2YX-WCeoAVIChb6NAzoFcKCFChMsrixJvD7ZRbvcaC-ceXEzXYaoH4K5vaoRDsUyBHFkpIDPnsn3bnzovbvi0a2Gg=s660" + , "This is the title of the graphic" + ) + ] ] , test jats "bullet list" $ "<list list-type=\"bullet\">\n\ diff --git a/test/command/5321.md b/test/command/5321.md index 200cd6308..8a665568f 100644 --- a/test/command/5321.md +++ b/test/command/5321.md @@ -4,7 +4,9 @@ <caption> <p>bar</p> </caption> - <graphic xlink:href="foo.png" xlink:alt-text="baz" /> + <graphic xlink:href="foo.png"> + <alt-text>baz</alt-text> + </graphic> </fig> ^D [ Figure @@ -23,7 +25,9 @@ <title>foo</title> <p>bar</p> </caption> - <graphic xlink:href="foo.png" xlink:alt-text="baz" /> + <graphic xlink:href="foo.png"> + <alt-text>baz</alt-text> + </graphic> </fig> ^D [ Figure diff --git a/test/command/jats-figure-alt-text.md b/test/command/jats-figure-alt-text.md index 555d44f16..999e7b9c2 100644 --- a/test/command/jats-figure-alt-text.md +++ b/test/command/jats-figure-alt-text.md @@ -5,8 +5,11 @@ <p>bar</p> </caption> <alt-text>alternative-decription</alt-text> - <graphic xlink:href="foo.png" xlink:alt-text="baz" /> + <graphic xlink:href="foo.png"> + <alt-text>baz</alt-text> + </graphic> </fig> + ^D [ Figure ( "fig-1" , [] , [] ) @@ -16,4 +19,4 @@ [ Image ( "" , [] , [] ) [ Str "baz" ] ( "foo.png" , "" ) ] ] ] -``` +```
\ No newline at end of file diff --git a/test/jats-reader.native b/test/jats-reader.native index d1c36405d..51048dd5a 100644 --- a/test/jats-reader.native +++ b/test/jats-reader.native @@ -745,6 +745,8 @@ Pandoc , Para [ Str "Einstein" , Space + , Str "definitely" + , Space , Str "showed" , Space , Str "that" @@ -754,10 +756,29 @@ Pandoc [ Para [ Str "Abstract" , Space , Str "text" ] , Para [ Image - ( "" , [] , [] ) - [] + ( "graphic001" + , [ "This" + , "is" + , "the" + , "role" + , "of" + , "the" + , "graphic" + ] + , [] + ) + [ Str "Alternative" + , Space + , Str "text" + , Space + , Str "of" + , Space + , Str "the" + , Space + , Str "graphic" + ] ( "https://lh3.googleusercontent.com/dB7iirJ3ncQaVMBGE2YX-WCeoAVIChb6NAzoFcKCFChMsrixJvD7ZRbvcaC-ceXEzXYaoH4K5vaoRDsUyBHFkpIDPnsn3bnzovbvi0a2Gg=s660" - , "" + , "This is the title of the graphic" ) ] , Para [ Math DisplayMath "e=mc^2" ] @@ -802,11 +823,14 @@ Pandoc [ Para [ Str "Abstract" , Space , Str "text" ] , Para [ Image - ( "" , [] , [] ) - [] - ( "https://lh3.googleusercontent.com/dB7iirJ3ncQaVMBGE2YX-WCeoAVIChb6NAzoFcKCFChMsrixJvD7ZRbvcaC-ceXEzXYaoH4K5vaoRDsUyBHFkpIDPnsn3bnzovbvi0a2Gg=s660" - , "" - ) + ( "graphic003" , [] , [] ) + [ Str "Alternative" + , Space + , Str "text" + , Space + , Str "1" + ] + ( "Title 3" , "" ) ] , Para [ Math DisplayMath "e=mc^2" ] ] @@ -821,6 +845,12 @@ Pandoc , Space , Str "because\8230" ] + , Figure + ( "fig-1" , [] , [] ) + (Caption Nothing [ Plain [ Str "bar" ] ]) + [ Plain [ Str "alternative-decription" ] + , Para [ Image ( "" , [] , [] ) [] ( "foo.png" , "" ) ] + ] , Header 1 ( "code-blocks" , [] , [] ) diff --git a/test/jats-reader.xml b/test/jats-reader.xml index 3fbf98d9d..ce8708ba8 100644 --- a/test/jats-reader.xml +++ b/test/jats-reader.xml @@ -193,19 +193,26 @@ <title>Formulae with miscelaneus elements</title> <p>Regardless of whether or not they are inside a paragraph, should be wrapped in a div, and displayed in a block:</p> <p><bold>Inside a paragraph:</bold></p> - <p>Einstein showed that + <p>Einstein definitely showed that <disp-formula> <abstract> <p>Abstract text</p> </abstract> - <graphic xlink:href="https://lh3.googleusercontent.com/dB7iirJ3ncQaVMBGE2YX-WCeoAVIChb6NAzoFcKCFChMsrixJvD7ZRbvcaC-ceXEzXYaoH4K5vaoRDsUyBHFkpIDPnsn3bnzovbvi0a2Gg=s660"> - <alt-text>Alternative text 1</alt-text> - <caption><p>Google doodle from 14 March 2003</p></caption> + <graphic id="graphic001" + xlink:href="https://lh3.googleusercontent.com/dB7iirJ3ncQaVMBGE2YX-WCeoAVIChb6NAzoFcKCFChMsrixJvD7ZRbvcaC-ceXEzXYaoH4K5vaoRDsUyBHFkpIDPnsn3bnzovbvi0a2Gg=s660" + xlink:title="This is the title of the graphic" + xlink:role="This is the role of the graphic"> + <alt-text>Alternative text of the graphic</alt-text> + <caption> + <title>This is the title of the caption</title> + <p>Google doodle from 14 March 2003</p></caption> </graphic> <alternatives> <tex-math><![CDATA[e=mc^2]]></tex-math> <mml:math display="block" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:mi>e</mml:mi><mml:mo>=</mml:mo><mml:mi>m</mml:mi><mml:msup><mml:mi>c</mml:mi><mml:mn>2</mml:mn></mml:msup></mml:mrow></mml:math> - <graphic xlink:href="https://lh3.googleusercontent.com/dB7iirJ3ncQaVMBGE2YX-WCeoAVIChb6NAzoFcKCFChMsrixJvD7ZRbvcaC-ceXEzXYaoH4K5vaoRDsUyBHFkpIDPnsn3bnzovbvi0a2Gg=s660"> + <graphic id="graphic001" + xlink:href="https://lh3.googleusercontent.com/dB7iirJ3ncQaVMBGE2YX-WCeoAVIChb6NAzoFcKCFChMsrixJvD7ZRbvcaC-ceXEzXYaoH4K5vaoRDsUyBHFkpIDPnsn3bnzovbvi0a2Gg=s660" + xlink:title="Title 2"> <alt-text>Alternative text 2</alt-text> <caption><p>Google doodle from 14 March 2003</p></caption> </graphic> @@ -218,14 +225,18 @@ <abstract> <p>Abstract text</p> </abstract> - <graphic xlink:href="https://lh3.googleusercontent.com/dB7iirJ3ncQaVMBGE2YX-WCeoAVIChb6NAzoFcKCFChMsrixJvD7ZRbvcaC-ceXEzXYaoH4K5vaoRDsUyBHFkpIDPnsn3bnzovbvi0a2Gg=s660"> + <graphic id="graphic003" + xlink:href="https://lh3.googleusercontent.com/dB7iirJ3ncQaVMBGE2YX-WCeoAVIChb6NAzoFcKCFChMsrixJvD7ZRbvcaC-ceXEzXYaoH4K5vaoRDsUyBHFkpIDPnsn3bnzovbvi0a2Gg=s660" + xlink:href="Title 3"> <alt-text>Alternative text 1</alt-text> <caption><p>Google doodle from 14 March 2003</p></caption> </graphic> <alternatives> <tex-math><![CDATA[e=mc^2]]></tex-math> <mml:math display="block" xmlns:mml="http://www.w3.org/1998/Math/MathML"><mml:mrow><mml:mi>e</mml:mi><mml:mo>=</mml:mo><mml:mi>m</mml:mi><mml:msup><mml:mi>c</mml:mi><mml:mn>2</mml:mn></mml:msup></mml:mrow></mml:math> - <graphic xlink:href="https://lh3.googleusercontent.com/dB7iirJ3ncQaVMBGE2YX-WCeoAVIChb6NAzoFcKCFChMsrixJvD7ZRbvcaC-ceXEzXYaoH4K5vaoRDsUyBHFkpIDPnsn3bnzovbvi0a2Gg=s660"> + <graphic id="graphic004" + xlink:href="https://lh3.googleusercontent.com/dB7iirJ3ncQaVMBGE2YX-WCeoAVIChb6NAzoFcKCFChMsrixJvD7ZRbvcaC-ceXEzXYaoH4K5vaoRDsUyBHFkpIDPnsn3bnzovbvi0a2Gg=s660" + xlink:href="Title 4"> <alt-text>Alternative text 2</alt-text> <caption><p>Google doodle from 14 March 2003</p></caption> </graphic> @@ -234,6 +245,15 @@ <p>This formula is important becauseā¦</p> </sec> </sec> +<sec id="figures"> + <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> +</sec> <sec id="code-blocks"> <title>Code Blocks</title> <p>Code:</p> |
