@@ -21,12 +21,13 @@ module Text.Pandoc.Writers.JATS
2121 , writeJatsPublishing
2222 , writeJatsArticleAuthoring
2323 ) where
24+import Control.Applicative ((<|>))
2425import Control.Monad.Reader
2526import Control.Monad.State
2627import Data.Generics (everywhere, mkT)
2728import Data.List (partition)
2829import qualified Data.Map as M
29−import Data.Maybe (fromMaybe)
30+import Data.Maybe (fromMaybe, listToMaybe)
3031import Data.Time (toGregorian, Day, parseTimeM, defaultTimeLocale, formatTime)
3132import qualified Data.Text as T
3233import Data.Text (Text)
@@ -449,18 +450,33 @@ inlineToJATS opts (Note contents) = do
449450 $ text (show notenum)
450451inlineToJATS opts (Cite _ lst) =
451452 inlinesToJATS opts lst
452−inlineToJATS opts (Span (ident,_,kvs) ils) = do
453+inlineToJATS opts (Span (ident,classes,kvs) ils) = do
453454 contents <- inlinesToJATS opts ils
454− let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
455− [("xml:lang",l) | ("lang",l) <- kvs] ++
456− [(k,v) | (k,v) <- kvs
457− , k `elem` ["alt", "content-type", "rid", "specific-use",
458− "vocab", "vocab-identifier", "vocab-term",
459− "vocab-term-identifier"]]
455+ let commonAttr = [("id", escapeNCName ident) | not (T.null ident)] ++
456+ [("xml:lang",l) | ("lang",l) <- kvs] ++
457+ [(k,v) | (k,v) <- kvs, k `elem` ["alt", "specific-use"]]
458+ -- A named-content element is a good fit for spans, but requires a
459+ -- content-type attribute to be present. We use either the explicit
460+ -- attribute or the first class as content type. If neither is
461+ -- available, then we fall back to using a @styled-content@ element.
462+ let (tag, specificAttr) =
463+ case lookup "content-type" kvs <|> listToMaybe classes of
464+ Just ct -> ( "named-content"
465+ , ("content-type", ct) :
466+ [(k, v) | (k, v) <- kvs
467+ , k `elem` ["rid", "vocab", "vocab-identifier",
468+ "vocab-term", "vocab-term-identifier"]])
469+ -- Fall back to styled-content
470+ Nothing -> ("styled-content"
471+ , [(k, v) | (k,v) <- kvs
472+ , k `elem` ["style", "style-type", "style-detail",
473+ "toggle"]])
474+ let attr = commonAttr ++ specificAttr
475+ -- unwrap if wrapping element would have no attributes
460476 return $
461477 if null attr
462− then contents -- unwrap if no relevant attributes are given
463− else inTags False "named-content" attr contents
478+ then contents
479+ else inTags False tag attr contents
464480inlineToJATS _ (Math t str) = do
465481 let addPref (Xml.Attr q v)
466482 | Xml.qName q == "xmlns" = Xml.Attr q{ Xml.qName = "xmlns:mml" } v