@@ -239,7 +239,7 @@ languageFor classes =
239239codeAttr :: Attr -> (Text, [(Text, Text)])
240240codeAttr (ident,classes,kvs) = (lang, attr)
241241 where
242− attr = [("id",ident) | not (T.null ident)] ++
242+ attr = [("id", escapeNCName ident) | not (T.null ident)] ++
243243 [("language",lang) | not (T.null lang)] ++
244244 [(k,v) | (k,v) <- kvs, k `elem` ["code-type",
245245 "code-version", "executable",
@@ -251,7 +251,8 @@ codeAttr (ident,classes,kvs) = (lang, attr)
251251blockToJATS :: PandocMonad m => WriterOptions -> Block -> JATS m (Doc Text)
252252blockToJATS _ Null = return empty
253253blockToJATS opts (Div (id',"section":_,kvs) (Header _lvl _ ils : xs)) = do
254− let idAttr = [("id", writerIdentifierPrefix opts <> id') | not (T.null id')]
254+ let idAttr = [ ("id", writerIdentifierPrefix opts <> escapeNCName id')
255+ | not (T.null id')]
255256 let otherAttrs = ["sec-type", "specific-use"]
256257 let attribs = idAttr ++ [(k,v) | (k,v) <- kvs, k `elem` otherAttrs]
257258 title' <- inlinesToJATS opts ils
@@ -260,7 +261,7 @@ blockToJATS opts (Div (id',"section":_,kvs) (Header _lvl _ ils : xs)) = do
260261 inTagsSimple "title" title' $$ contents
261262-- Bibliography reference:
262263blockToJATS opts (Div (ident,_,_) [Para lst]) | "ref-" `T.isPrefixOf` ident =
263− inTags True "ref" [("id", ident)] .
264+ inTags True "ref" [("id", escapeNCName ident)] .
264265 inTagsSimple "mixed-citation" <$>
265266 inlinesToJATS opts lst
266267blockToJATS opts (Div ("refs",_,_) xs) = do
@@ -271,14 +272,14 @@ blockToJATS opts (Div ("refs",_,_) xs) = do
271272 return $ inTagsIndented "ref-list" contents
272273blockToJATS opts (Div (ident,[cls],kvs) bs) | cls `elem` ["fig", "caption", "table-wrap"] = do
273274 contents <- blocksToJATS opts bs
274− let attr = [("id", ident) | not (T.null ident)] ++
275+ let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
275276 [("xml:lang",l) | ("lang",l) <- kvs] ++
276277 [(k,v) | (k,v) <- kvs, k `elem` ["specific-use",
277278 "content-type", "orientation", "position"]]
278279 return $ inTags True cls attr contents
279280blockToJATS opts (Div (ident,_,kvs) bs) = do
280281 contents <- blocksToJATS opts bs
281− let attr = [("id", ident) | not (T.null ident)] ++
282+ let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
282283 [("xml:lang",l) | ("lang",l) <- kvs] ++
283284 [(k,v) | (k,v) <- kvs, k `elem` ["specific-use",
284285 "content-type", "orientation", "position"]]
@@ -296,7 +297,7 @@ blockToJATS opts (Para [Image (ident,_,kvs) txt
296297 let capt = if null txt
297298 then empty
298299 else inTagsSimple "caption" $ inTagsSimple "p" alt
299− let attr = [("id", ident) | not (T.null ident)] ++
300+ let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
300301 [(k,v) | (k,v) <- kvs, k `elem` ["fig-type", "orientation",
301302 "position", "specific-use"]]
302303 let graphicattr = [("mimetype",maintype),
@@ -307,7 +308,7 @@ blockToJATS opts (Para [Image (ident,_,kvs) txt
307308 capt $$ selfClosingTag "graphic" graphicattr
308309blockToJATS _ (Para [Image (ident,_,kvs) _ (src, tit)]) = do
309310 let (maintype, subtype) = imageMimeType src kvs
310− let attr = [("id", ident) | not (T.null ident)] ++
311+ let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
311312 [("mimetype", maintype),
312313 ("mime-subtype", subtype),
313314 ("xlink:href", src)] ++
@@ -434,7 +435,7 @@ inlineToJATS opts (Note contents) = do
434435 let notenum = case notes of
435436 (n, _):_ -> n + 1
436437 [] -> 1
437− thenote <- inTags True "fn" [("id","fn" <> tshow notenum)]
438+ thenote <- inTags True "fn" [("id", "fn" <> tshow notenum)]
438439 <$> wrappedBlocksToJATS (not . isPara) opts
439440 (walk demoteHeaderAndRefs contents)
440441 modify $ \st -> st{ jatsNotes = (notenum, thenote) : notes }
@@ -447,7 +448,7 @@ inlineToJATS opts (Cite _ lst) =
447448inlineToJATS opts (Span ("",_,[]) ils) = inlinesToJATS opts ils
448449inlineToJATS opts (Span (ident,_,kvs) ils) = do
449450 contents <- inlinesToJATS opts ils
450− let attr = [("id",ident) | not (T.null ident)] ++
451+ let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
451452 [("xml:lang",l) | ("lang",l) <- kvs] ++
452453 [(k,v) | (k,v) <- kvs
453454 , k `elem` ["content-type", "rationale",
@@ -488,9 +489,9 @@ inlineToJATS _ (Link _attr [Str t] (T.stripPrefix "mailto:" -> Just email, _))
488489 return $ inTagsSimple "email" $ literal (escapeStringForXML email)
489490inlineToJATS opts (Link (ident,_,kvs) txt (T.uncons -> Just ('#', src), _)) = do
490491 let attr = mconcat
491− [ [("id", ident) | not (T.null ident)]
492+ [ [("id", escapeNCName ident) | not (T.null ident)]
492493 , [("alt", stringify txt) | not (null txt)]
493− , [("rid", src)]
494+ , [("rid", escapeNCName src)]
494495 , [(k,v) | (k,v) <- kvs, k `elem` ["ref-type", "specific-use"]]
495496 , [("ref-type", "bibr") | "ref-" `T.isPrefixOf` src]
496497 ]
@@ -500,7 +501,7 @@ inlineToJATS opts (Link (ident,_,kvs) txt (T.uncons -> Just ('#', src), _)) = do
500501 contents <- inlinesToJATS opts txt
501502 return $ inTags False "xref" attr contents
502503inlineToJATS opts (Link (ident,_,kvs) txt (src, tit)) = do
503− let attr = [("id", ident) | not (T.null ident)] ++
504+ let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
504505 [("ext-link-type", "uri"),
505506 ("xlink:href", src)] ++
506507 [("xlink:title", tit) | not (T.null tit)] ++
@@ -518,7 +519,7 @@ inlineToJATS _ (Image (ident,_,kvs) _ (src, tit)) = do
518519 let subtype = fromMaybe "" $
519520 lookup "mime-subtype" kvs `mplus`
520521 (T.drop 1 . T.dropWhile (/='/') <$> mbMT)
521− let attr = [("id", ident) | not (T.null ident)] ++
522+ let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
522523 [("mimetype", maintype),
523524 ("mime-subtype", subtype),
524525 ("xlink:href", src)] ++