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.
This commit is contained in:
John MacFarlane 2020-10-06 22:28:22 -07:00
parent eda5540719
commit fd3809c33f
2 changed files with 22 additions and 2 deletions

View file

@ -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))

View file

@ -0,0 +1,17 @@
```
% pandoc -t csljson
---
references:
- id: foo
type: book
title: "Hi & Low"
...
^D
[
{
"id": "foo",
"title": "Hi & Low",
"type": "book"
}
]
```