summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2023-02-09 07:21:40 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2023-02-09 08:15:13 +0100
commit9eee4a2582822f01cdc46d9576dd9ed17b135e2c (patch)
tree4d39c676acf827e663434cf712c7c81d6e6bdc78
parent4edc02d3b5b4a297bf0cd9ac2b16bb85c2b15d00 (diff)
Lua: add field `chunk_template` to WriterOptions objects [API change]
The PathTemplate type exported from Text.Pandoc.Chunks is now an instance of the ToJSON and FromJSON classes. Closes: #8607
-rw-r--r--doc/lua-filters.md3
-rw-r--r--pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/WriterOptions.hs7
-rw-r--r--pandoc-lua-engine/test/lua/module/globals.lua3
-rw-r--r--src/Text/Pandoc/Chunks.hs5
4 files changed, 15 insertions, 3 deletions
diff --git a/doc/lua-filters.md b/doc/lua-filters.md
index cf0a5ef25..ccd327b95 100644
--- a/doc/lua-filters.md
+++ b/doc/lua-filters.md
@@ -2115,6 +2115,9 @@ Pandoc writer options
Fields:
+`chunk_template`
+: Template used to generate chunked HTML filenames (string)
+
`cite_method`
: How to print cites -- one of 'citeproc', 'natbib', or
'biblatex' (string)
diff --git a/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/WriterOptions.hs b/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/WriterOptions.hs
index 960972bed..4ef5ae14d 100644
--- a/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/WriterOptions.hs
+++ b/pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/WriterOptions.hs
@@ -55,7 +55,12 @@ typeWriterOptions = deftype "WriterOptions"
<#> udparam typeWriterOptions "opts" "options to print in native format"
=#> functionResult pushString "string" "Haskell representation"
]
- [ property "cite_method"
+ [ property "chunk_template"
+ "Templates used to generate chunked HTML filenames (string)"
+ (pushViaJSON, writerChunkTemplate)
+ (peekViaJSON, \opts x -> opts{ writerChunkTemplate = x })
+
+ , property "cite_method"
"How to print cites"
(pushViaJSON, writerCiteMethod)
(peekViaJSON, \opts x -> opts{ writerCiteMethod = x })
diff --git a/pandoc-lua-engine/test/lua/module/globals.lua b/pandoc-lua-engine/test/lua/module/globals.lua
index 72edef036..19fee3e92 100644
--- a/pandoc-lua-engine/test/lua/module/globals.lua
+++ b/pandoc-lua-engine/test/lua/module/globals.lua
@@ -8,6 +8,9 @@ local assert = tasty.assert
-- WriterOptions and its components. UPDATE THE DOCS if anything changes.
return {
group 'PANDOC_WRITER_OPTIONS' {
+ test('chunk_template', function ()
+ assert.are_equal(type(PANDOC_WRITER_OPTIONS.chunk_template), 'string')
+ end),
test('cite_method', function ()
assert.are_equal(type(PANDOC_WRITER_OPTIONS.cite_method), 'string')
end),
diff --git a/src/Text/Pandoc/Chunks.hs b/src/Text/Pandoc/Chunks.hs
index 2447deb72..bd34cc6d5 100644
--- a/src/Text/Pandoc/Chunks.hs
+++ b/src/Text/Pandoc/Chunks.hs
@@ -1,5 +1,4 @@
{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
@@ -27,9 +26,11 @@ module Text.Pandoc.Chunks
, tocToList
, SecInfo(..)
) where
+
import Text.Pandoc.Definition
import Text.Pandoc.Shared (makeSections, stringify, inlineListToIdentifier)
import Text.Pandoc.Walk (Walkable(..))
+import Data.Aeson (FromJSON, ToJSON)
import Data.Text (Text)
import Text.Printf (printf)
import Data.Maybe (fromMaybe, isNothing)
@@ -257,7 +258,7 @@ resolvePathTemplate (PathTemplate templ) chunknum headingText ident secnum =
-- @"section-1.2-introduction.html"@.
newtype PathTemplate =
PathTemplate { unPathTemplate :: Text }
- deriving (Show, IsString, Data, Typeable, Generic)
+ deriving (Show, IsString, Data, Typeable, Generic, ToJSON, FromJSON)
-- | A part of a document (typically a chapter or section, or
-- the part of a section before its subsections).