mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-21 06:55:46 +00:00
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
This commit is contained in:
@@ -444,18 +444,19 @@ inlineToJATS opts (Note contents) = do
|
||||
("rid", "fn" <> tshow notenum)]
|
||||
$ text (show notenum)
|
||||
inlineToJATS opts (Cite _ lst) =
|
||||
-- TODO revisit this after examining the jats.csl pipeline
|
||||
inlinesToJATS opts lst
|
||||
inlineToJATS opts (Span ("",_,[]) ils) = inlinesToJATS opts ils
|
||||
inlineToJATS opts (Span (ident,_,kvs) ils) = do
|
||||
contents <- inlinesToJATS opts ils
|
||||
let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
|
||||
[("xml:lang",l) | ("lang",l) <- kvs] ++
|
||||
[(k,v) | (k,v) <- kvs
|
||||
, k `elem` ["content-type", "rationale",
|
||||
"rid", "specific-use"]]
|
||||
return $ selfClosingTag "milestone-start" attr <> contents <>
|
||||
selfClosingTag "milestone-end" []
|
||||
, k `elem` ["alt", "content-type", "rid", "specific-use",
|
||||
"vocab", "vocab-identifier", "vocab-term",
|
||||
"vocab-term-identifier"]]
|
||||
return $
|
||||
if null attr
|
||||
then contents -- unwrap if no relevant attributes are given
|
||||
else inTags False "named-content" attr contents
|
||||
inlineToJATS _ (Math t str) = do
|
||||
let addPref (Xml.Attr q v)
|
||||
| Xml.qName q == "xmlns" = Xml.Attr q{ Xml.qName = "xmlns:mml" } v
|
||||
|
||||
@@ -142,4 +142,19 @@ tests =
|
||||
codeWith ("7y",[],[]) "print 5" =?>
|
||||
"<p><monospace id=\"U0037y\">print 5</monospace></p>"
|
||||
]
|
||||
|
||||
, testGroup "spans"
|
||||
[ "unwrapped if no attributes given" =:
|
||||
spanWith nullAttr "text in span" =?>
|
||||
"<p>text in span</p>"
|
||||
|
||||
, "converted to named-content element" =:
|
||||
spanWith ("a", ["ignored"], [("alt", "aa")]) "text" =?>
|
||||
"<p><named-content id=\"a\" alt=\"aa\">text</named-content></p>"
|
||||
|
||||
, "unwrapped if named-content element would have no attributes" =:
|
||||
spanWith ("", ["ignored"], [("hidden", "true")]) "text in span" =?>
|
||||
"<p>text in span</p>"
|
||||
|
||||
]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user