@@ -239,7 +239,7 @@ languageFor classes =
239codeAttr :: Attr -> (Text, [(Text, Text)])
239codeAttr :: Attr -> (Text, [(Text, Text)])
240codeAttr (ident,classes,kvs) = (lang, attr)
240codeAttr (ident,classes,kvs) = (lang, attr)
242− attr = [("id",ident) | not (T.null ident)] ++
242+ attr = [("id", escapeNCName ident) | not (T.null ident)] ++
243 [("language",lang) | not (T.null lang)] ++
243 [("language",lang) | not (T.null lang)] ++
244 [(k,v) | (k,v) <- kvs, k `elem` ["code-type",
244 [(k,v) | (k,v) <- kvs, k `elem` ["code-type",
245 "code-version", "executable",
245 "code-version", "executable",
@@ -251,7 +251,8 @@ codeAttr (ident,classes,kvs) = (lang, attr)
251blockToJATS :: PandocMonad m => WriterOptions -> Block -> JATS m (Doc Text)
251blockToJATS :: PandocMonad m => WriterOptions -> Block -> JATS m (Doc Text)
252blockToJATS _ Null = return empty
252blockToJATS _ Null = return empty
253blockToJATS opts (Div (id',"section":_,kvs) (Header _lvl _ ils : xs)) = do
253blockToJATS 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 let otherAttrs = ["sec-type", "specific-use"]
256 let otherAttrs = ["sec-type", "specific-use"]
256 let attribs = idAttr ++ [(k,v) | (k,v) <- kvs, k `elem` otherAttrs]
257 let attribs = idAttr ++ [(k,v) | (k,v) <- kvs, k `elem` otherAttrs]
257 title' <- inlinesToJATS opts ils
258 title' <- inlinesToJATS opts ils
@@ -260,7 +261,7 @@ blockToJATS opts (Div (id',"section":_,kvs) (Header _lvl _ ils : xs)) = do
260 inTagsSimple "title" title' $$ contents
261 inTagsSimple "title" title' $$ contents
261-- Bibliography reference:
262-- Bibliography reference:
262blockToJATS opts (Div (ident,_,_) [Para lst]) | "ref-" `T.isPrefixOf` ident =
263blockToJATS opts (Div (ident,_,_) [Para lst]) | "ref-" `T.isPrefixOf` ident =
263− inTags True "ref" [("id", ident)] .
264+ inTags True "ref" [("id", escapeNCName ident)] .
264 inTagsSimple "mixed-citation" <$>
265 inTagsSimple "mixed-citation" <$>
265 inlinesToJATS opts lst
266 inlinesToJATS opts lst
266blockToJATS opts (Div ("refs",_,_) xs) = do
267blockToJATS opts (Div ("refs",_,_) xs) = do
@@ -271,14 +272,14 @@ blockToJATS opts (Div ("refs",_,_) xs) = do
271 return $ inTagsIndented "ref-list" contents
272 return $ inTagsIndented "ref-list" contents
272blockToJATS opts (Div (ident,[cls],kvs) bs) | cls `elem` ["fig", "caption", "table-wrap"] = do
273blockToJATS opts (Div (ident,[cls],kvs) bs) | cls `elem` ["fig", "caption", "table-wrap"] = do
273 contents <- blocksToJATS opts bs
274 contents <- blocksToJATS opts bs
274− let attr = [("id", ident) | not (T.null ident)] ++
275+ let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
275 [("xml:lang",l) | ("lang",l) <- kvs] ++
276 [("xml:lang",l) | ("lang",l) <- kvs] ++
276 [(k,v) | (k,v) <- kvs, k `elem` ["specific-use",
277 [(k,v) | (k,v) <- kvs, k `elem` ["specific-use",
277 "content-type", "orientation", "position"]]
278 "content-type", "orientation", "position"]]
278 return $ inTags True cls attr contents
279 return $ inTags True cls attr contents
279blockToJATS opts (Div (ident,_,kvs) bs) = do
280blockToJATS opts (Div (ident,_,kvs) bs) = do
280 contents <- blocksToJATS opts bs
281 contents <- blocksToJATS opts bs
281− let attr = [("id", ident) | not (T.null ident)] ++
282+ let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
282 [("xml:lang",l) | ("lang",l) <- kvs] ++
283 [("xml:lang",l) | ("lang",l) <- kvs] ++
283 [(k,v) | (k,v) <- kvs, k `elem` ["specific-use",
284 [(k,v) | (k,v) <- kvs, k `elem` ["specific-use",
284 "content-type", "orientation", "position"]]
285 "content-type", "orientation", "position"]]
@@ -296,7 +297,7 @@ blockToJATS opts (Para [Image (ident,_,kvs) txt
296 let capt = if null txt
297 let capt = if null txt
297 then empty
298 then empty
298 else inTagsSimple "caption" $ inTagsSimple "p" alt
299 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)] ++
300 [(k,v) | (k,v) <- kvs, k `elem` ["fig-type", "orientation",
301 [(k,v) | (k,v) <- kvs, k `elem` ["fig-type", "orientation",
301 "position", "specific-use"]]
302 "position", "specific-use"]]
302 let graphicattr = [("mimetype",maintype),
303 let graphicattr = [("mimetype",maintype),
@@ -307,7 +308,7 @@ blockToJATS opts (Para [Image (ident,_,kvs) txt
307 capt $$ selfClosingTag "graphic" graphicattr
308 capt $$ selfClosingTag "graphic" graphicattr
308blockToJATS _ (Para [Image (ident,_,kvs) _ (src, tit)]) = do
309blockToJATS _ (Para [Image (ident,_,kvs) _ (src, tit)]) = do
309 let (maintype, subtype) = imageMimeType src kvs
310 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)] ++
311 [("mimetype", maintype),
312 [("mimetype", maintype),
312 ("mime-subtype", subtype),
313 ("mime-subtype", subtype),
313 ("xlink:href", src)] ++
314 ("xlink:href", src)] ++
@@ -434,7 +435,7 @@ inlineToJATS opts (Note contents) = do
434 let notenum = case notes of
435 let notenum = case notes of
435 (n, _):_ -> n + 1
436 (n, _):_ -> n + 1
437− thenote <- inTags True "fn" [("id","fn" <> tshow notenum)]
438+ thenote <- inTags True "fn" [("id", "fn" <> tshow notenum)]
438 <$> wrappedBlocksToJATS (not . isPara) opts
439 <$> wrappedBlocksToJATS (not . isPara) opts
439 (walk demoteHeaderAndRefs contents)
440 (walk demoteHeaderAndRefs contents)
440 modify $ \st -> st{ jatsNotes = (notenum, thenote) : notes }
441 modify $ \st -> st{ jatsNotes = (notenum, thenote) : notes }
@@ -447,7 +448,7 @@ inlineToJATS opts (Cite _ lst) =
447inlineToJATS opts (Span ("",_,[]) ils) = inlinesToJATS opts ils
448inlineToJATS opts (Span ("",_,[]) ils) = inlinesToJATS opts ils
448inlineToJATS opts (Span (ident,_,kvs) ils) = do
449inlineToJATS opts (Span (ident,_,kvs) ils) = do
449 contents <- inlinesToJATS opts ils
450 contents <- inlinesToJATS opts ils
450− let attr = [("id",ident) | not (T.null ident)] ++
451+ let attr = [("id", escapeNCName ident) | not (T.null ident)] ++
451 [("xml:lang",l) | ("lang",l) <- kvs] ++
452 [("xml:lang",l) | ("lang",l) <- kvs] ++
452 [(k,v) | (k,v) <- kvs
453 [(k,v) | (k,v) <- kvs
453 , k `elem` ["content-type", "rationale",
454 , k `elem` ["content-type", "rationale",
@@ -488,9 +489,9 @@ inlineToJATS _ (Link _attr [Str t] (T.stripPrefix "mailto:" -> Just email, _))
488 return $ inTagsSimple "email" $ literal (escapeStringForXML email)
489 return $ inTagsSimple "email" $ literal (escapeStringForXML email)
489inlineToJATS opts (Link (ident,_,kvs) txt (T.uncons -> Just ('#', src), _)) = do
490inlineToJATS opts (Link (ident,_,kvs) txt (T.uncons -> Just ('#', src), _)) = do
490 let attr = mconcat
491 let attr = mconcat
491− [ [("id", ident) | not (T.null ident)]
492+ [ [("id", escapeNCName ident) | not (T.null ident)]
492 , [("alt", stringify txt) | not (null txt)]
493 , [("alt", stringify txt) | not (null txt)]
493− , [("rid", src)]
494+ , [("rid", escapeNCName src)]
494 , [(k,v) | (k,v) <- kvs, k `elem` ["ref-type", "specific-use"]]
495 , [(k,v) | (k,v) <- kvs, k `elem` ["ref-type", "specific-use"]]
495 , [("ref-type", "bibr") | "ref-" `T.isPrefixOf` src]
496 , [("ref-type", "bibr") | "ref-" `T.isPrefixOf` src]
@@ -500,7 +501,7 @@ inlineToJATS opts (Link (ident,_,kvs) txt (T.uncons -> Just ('#', src), _)) = do
500 contents <- inlinesToJATS opts txt
501 contents <- inlinesToJATS opts txt
501 return $ inTags False "xref" attr contents
502 return $ inTags False "xref" attr contents
502inlineToJATS opts (Link (ident,_,kvs) txt (src, tit)) = do
503inlineToJATS 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)] ++
504 [("ext-link-type", "uri"),
505 [("ext-link-type", "uri"),
505 ("xlink:href", src)] ++
506 ("xlink:href", src)] ++
506 [("xlink:title", tit) | not (T.null tit)] ++
507 [("xlink:title", tit) | not (T.null tit)] ++
@@ -518,7 +519,7 @@ inlineToJATS _ (Image (ident,_,kvs) _ (src, tit)) = do
518 let subtype = fromMaybe "" $
519 let subtype = fromMaybe "" $
519 lookup "mime-subtype" kvs `mplus`
520 lookup "mime-subtype" kvs `mplus`
520 (T.drop 1 . T.dropWhile (/='/') <$> mbMT)
521 (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)] ++
522 [("mimetype", maintype),
523 [("mimetype", maintype),
523 ("mime-subtype", subtype),
524 ("mime-subtype", subtype),
524 ("xlink:href", src)] ++
525 ("xlink:href", src)] ++