aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2021-01-29 09:37:45 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2021-01-29 09:51:20 +0100
commit300b9b0ea365187240115afbfed0df7fa438a7b3 (patch)
tree5aaf9f53616f9b41a866dd11ef3f120763f97f9a
parent2ca61a5350003a0327eb9a031c84ae4a2a05807b (diff)
downloadpandoc-300b9b0ea365187240115afbfed0df7fa438a7b3.tar.gz
JATS writer: escape special chars in reference elements.
Prevents the generation of invalid markup if a citation element contains an ampersand or another character with a special meaning in XML.
-rw-r--r--src/Text/Pandoc/Writers/JATS/References.hs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Writers/JATS/References.hs b/src/Text/Pandoc/Writers/JATS/References.hs
index 4ee7eb9dd..903144128 100644
--- a/src/Text/Pandoc/Writers/JATS/References.hs
+++ b/src/Text/Pandoc/Writers/JATS/References.hs
@@ -29,7 +29,7 @@ import Text.Pandoc.Builder (Inlines)
import Text.Pandoc.Options (WriterOptions)
import Text.Pandoc.Shared (tshow)
import Text.Pandoc.Writers.JATS.Types
-import Text.Pandoc.XML (inTags)
+import Text.Pandoc.XML (escapeStringForXML, inTags)
import qualified Data.Text as T
referencesToJATS :: PandocMonad m
@@ -78,7 +78,8 @@ referenceToJATS _opts ref = do
varInTagWith var tagName tagAttribs =
case lookupVariable var ref >>= valToText of
Nothing -> mempty
- Just val -> inTags' tagName tagAttribs $ literal val
+ Just val -> inTags' tagName tagAttribs . literal $
+ escapeStringForXML val
authors = case lookupVariable "author" ref of
Just (NamesVal names) ->
@@ -143,7 +144,9 @@ toNameElements name =
then inTags' "name" [] nameTags
else nameLiteral name `inNameTag` "string-name"
where
- inNameTag val tag = maybe empty (inTags' tag [] . literal) val
+ inNameTag mVal tag = case mVal of
+ Nothing -> empty
+ Just val -> inTags' tag [] . literal $ escapeStringForXML val
surnamePrefix = maybe mempty (`T.snoc` ' ') $
nameNonDroppingParticle name
givenSuffix = maybe mempty (T.cons ' ') $