git.iko.soy/typeable/pandoc
on master help sign in
JATS writer: convert spans to <named-content> elements

Spans with attributes are converted to `<named-content>` elements instead of being wrapped with `<milestone-start/>` and `<milestone-end>` elements. Milestone elements are not allowed in documents using the articleauthoring tag set, so this change ensures the creation of valid documents. Closes: #7211

commit2d60524de43d59ffb1763a33a15cc2ecce613ecf authorAlbert Krewinkel <albert@zeitkraut.de> dateSat 10 Apr 2021, 11:38 (6 years ago) parent051b7ff
2 files changed+22−6
src/Text/Pandoc/Writers/JATS.hs+7−6 test/Tests/Writers/JATS.hs+15
src/Text/Pandoc/Writers/JATS.hs+7−6
@@ -444,18 +444,19 @@ inlineToJATS opts (Note contents) = do
444444 ("rid", "fn" <> tshow notenum)]
445445 $ text (show notenum)
446446inlineToJATS opts (Cite _ lst) =
447− -- TODO revisit this after examining the jats.csl pipeline
448447 inlinesToJATS opts lst
449−inlineToJATS opts (Span ("",_,[]) ils) = inlinesToJATS opts ils
450448inlineToJATS opts (Span (ident,_,kvs) ils) = do
451449 contents <- inlinesToJATS opts ils
452450 let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
453451 [("xml:lang",l) | ("lang",l) <- kvs] ++
454452 [(k,v) | (k,v) <- kvs
455− , k `elem` ["content-type", "rationale",
456− "rid", "specific-use"]]
457− return $ selfClosingTag "milestone-start" attr <> contents <>
458− selfClosingTag "milestone-end" []
453+ , k `elem` ["alt", "content-type", "rid", "specific-use",
454+ "vocab", "vocab-identifier", "vocab-term",
455+ "vocab-term-identifier"]]
456+ return $
457+ if null attr
458+ then contents -- unwrap if no relevant attributes are given
459+ else inTags False "named-content" attr contents
459460inlineToJATS _ (Math t str) = do
460461 let addPref (Xml.Attr q v)
461462 | Xml.qName q == "xmlns" = Xml.Attr q{ Xml.qName = "xmlns:mml" } v
test/Tests/Writers/JATS.hs+15
@@ -142,4 +142,19 @@ tests =
142142 codeWith ("7y",[],[]) "print 5" =?>
143143 "<p><monospace id=\"U0037y\">print 5</monospace></p>"
144144 ]
145+
146+ , testGroup "spans"
147+ [ "unwrapped if no attributes given" =:
148+ spanWith nullAttr "text in span" =?>
149+ "<p>text in span</p>"
150+
151+ , "converted to named-content element" =:
152+ spanWith ("a", ["ignored"], [("alt", "aa")]) "text" =?>
153+ "<p><named-content id=\"a\" alt=\"aa\">text</named-content></p>"
154+
155+ , "unwrapped if named-content element would have no attributes" =:
156+ spanWith ("", ["ignored"], [("hidden", "true")]) "text in span" =?>
157+ "<p>text in span</p>"
158+
159+ ]
145160 ]