File: JATS.hs

package info (click to toggle)
haskell-pandoc 3.1.11.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,052 kB
  • sloc: haskell: 81,285; xml: 3,855; makefile: 13
file content (180 lines) | stat: -rw-r--r-- 7,519 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
{-# LANGUAGE OverloadedStrings #-}
{- |
   Module      : Tests.Readers.JATS
   Copyright   : © 2017 Hamish Mackenzie
   License     : GNU GPL, version 2 or above

   Maintainer  : Hamish Mackenzie <Hamish.K.Mackenzie@googlemail.com>
   Stability   : alpha
   Portability : portable

Tests for the JATS reader.
-}
module Tests.Readers.JATS (tests) where

import Data.Text (Text)
import Test.Tasty
import Tests.Helpers
import Text.Pandoc
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder

import qualified Data.Text as T

jats :: Text -> Pandoc
jats = purely $ readJATS def

tests :: [TestTree]
tests = [ testGroup "inline code"
          [ test jats "basic" $ "<p>\n  <monospace>@&amp;</monospace>\n</p>" =?> para (code "@&")
          ]
        , testGroup "block code"
          [ test jats "basic" $ "<preformat>@&amp;</preformat>" =?> codeBlock "@&"
          , test jats "lang" $ "<code language=\"c\">@&amp;</code>" =?> codeBlockWith ("", ["c"], []) "@&"
          ]
        , 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\
                            \  <list-item>\n\
                            \    <p>\n\
                            \      first\n\
                            \    </p>\n\
                            \  </list-item>\n\
                            \  <list-item>\n\
                            \    <p>\n\
                            \      second\n\
                            \    </p>\n\
                            \  </list-item>\n\
                            \  <list-item>\n\
                            \    <p>\n\
                            \      third\n\
                            \    </p>\n\
                            \  </list-item>\n\
                            \</list>"
                =?> bulletList [ para $ text "first"
                               , para $ text "second"
                               , para $ text "third"
                               ]
        , testGroup "definition lists"
          [ test jats "with internal link" $
            "<def-list>\n\
            \  <def-item>\n\
            \    <term>\n\
            \      <xref alt=\"testing\" rid=\"go\">testing</xref>\n\
            \    </term>\n\
            \    <def>\n\
            \      <p>\n\
            \        hi there\n\
            \      </p>\n\
            \    </def>\n\
            \  </def-item>\n\
            \</def-list>"
            =?> definitionList [(link "#go" "" (str "testing"),
                [para (text "hi there")])]
          ]
        , testGroup "math"
          [ test jats "escape |" $
            "<p>\n\
            \  <inline-formula><alternatives>\n\
            \  <tex-math><![CDATA[\\sigma|_{\\{x\\}}]]></tex-math>\n\
            \  <mml:math display=\"inline\" xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"><mml:mrow><mml:mi>σ</mml:mi><mml:msub><mml:mo stretchy=\"false\" form=\"prefix\">|</mml:mo><mml:mrow><mml:mo stretchy=\"false\" form=\"prefix\">{</mml:mo><mml:mi>x</mml:mi><mml:mo stretchy=\"false\" form=\"postfix\">}</mml:mo></mml:mrow></mml:msub></mml:mrow></mml:math></alternatives></inline-formula>\n\
            \</p>"
            =?> para (math "\\sigma|_{\\{x\\}}")
          , test jats "tex-math only" $
            "<p>\n\
            \  <inline-formula><alternatives>\n\
            \  <tex-math><![CDATA[\\sigma|_{\\{x\\}}]]></tex-math>\n\
            \  </alternatives></inline-formula>\n\
            \</p>"
            =?> para (math "\\sigma|_{\\{x\\}}")
          , test jats "math ml only" $
            "<p>\n\
            \  <inline-formula><alternatives>\n\
            \  <mml:math display=\"inline\" xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"><mml:mrow><mml:mi>σ</mml:mi><mml:msub><mml:mo stretchy=\"false\" form=\"prefix\">|</mml:mo><mml:mrow><mml:mo stretchy=\"false\" form=\"prefix\">{</mml:mo><mml:mi>x</mml:mi><mml:mo stretchy=\"false\" form=\"postfix\">}</mml:mo></mml:mrow></mml:msub></mml:mrow></mml:math></alternatives></inline-formula>\n\
            \</p>"
            =?> para (math "\\sigma|_{\\{ x\\}}")
          ]
        , testGroup "headers"
-- TODO fix footnotes in headers
--          [ test jats "unnumbered header" $
--            "<sec>\n\
--            \  <title>Header 1<fn>\n\
--            \    <p>\n\
--            \      note\n\
--            \    </p>\n\
--            \  </fn></title>\n\
--            \</sec>"
--            =?> header 1
--                (text "Header 1" <> note (plain $ text "note"))
          [ test jats "unnumbered sub header" $
            "<sec id=\"foo\">\n\
            \  <title>Header</title>\n\
            \  <sec id=\"foo2\">\n\
            \    <title>Sub-Header</title>\n\
            \  </sec>\n\
            \</sec>"
            =?> headerWith ("foo", [], []) 1
                  (text "Header")
                <> headerWith  ("foo2", [], []) 2
                  (text "Sub-Header")
          , test jats "containing image" $
            "<sec>\n\
            \  <title><inline-graphic mimetype=\"image\" mime-subtype=\"jpeg\" xlink:href=\"imgs/foo.jpg\" /></title>\n\
            \</sec>"
            =?> header 1 (image "imgs/foo.jpg" "" mempty)
          ]

        , testGroup "metadata"
          [ test jats "abstract" $
            T.unlines [ "<front>"
                      , "<article-meta>"
                      , "<abstract>"
                      , "<p>Paragraph 1</p>"
                      , "<p>Paragraph 2</p>"
                      , "</abstract>"
                      , "</article-meta>"
                      , "</front>"
                      ] =?>
            let abstract = para "Paragraph 1" <> para "Paragraph 2"
            in setMeta "abstract" abstract $ doc mempty
          ]
        ]