From fd3809c33f663627f43168d347c7f2690a74b56f Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 6 Oct 2020 22:28:22 -0700 Subject: [PATCH] Unescape entities in writing CSL JSON. The renderCslJson function escapes `<`, `>`, and `&` as entities. This is appropriate when generating HTML, but in CSL JSON these are supposed to appear unescaped. Closes jgm/citeproc#17. --- src/Text/Pandoc/Writers/CslJson.hs | 7 +++++-- test/command/citeproc-17.md | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/command/citeproc-17.md diff --git a/src/Text/Pandoc/Writers/CslJson.hs b/src/Text/Pandoc/Writers/CslJson.hs index 3a8f6f5b1..95ffb34a7 100644 --- a/src/Text/Pandoc/Writers/CslJson.hs +++ b/src/Text/Pandoc/Writers/CslJson.hs @@ -23,6 +23,7 @@ import qualified Data.Text as T import qualified Text.Pandoc.UTF8 as UTF8 import Text.Pandoc.Error import Text.Pandoc.Class +import Text.Pandoc.XML (fromEntities) import Control.Monad.Except (throwError) import Data.ByteString.Lazy (toStrict) import Data.ByteString (ByteString) @@ -84,5 +85,7 @@ toCslJson locale = toStrict . encodePretty' defConfig{ confIndent = Spaces 2 , confCompare = compare , confNumFormat = Generic } - . map (runIdentity . traverse (return . renderCslJson locale . foldMap fromInline)) - + . map (runIdentity . traverse (return . + fromEntities . + renderCslJson locale . + foldMap fromInline)) diff --git a/test/command/citeproc-17.md b/test/command/citeproc-17.md new file mode 100644 index 000000000..d80550f81 --- /dev/null +++ b/test/command/citeproc-17.md @@ -0,0 +1,17 @@ +``` +% pandoc -t csljson +--- +references: +- id: foo + type: book + title: "Hi & Low" +... +^D +[ + { + "id": "foo", + "title": "Hi & Low", + "type": "book" + } +] +```