aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2023-01-25 09:51:59 -0800
committerJohn MacFarlane <[email protected]>2023-01-25 09:51:59 -0800
commit131f546282953a549eeddc688f16748a51063bff (patch)
treed4790c5e6f3b1213a008d28fb3dc151f334e3f4e
parent5d25e56eeca86a87a1592e22bbabec566863b486 (diff)
Ensure that automatically set variables ...
`pandoc-version`, `outputfile`, `title-prefix`, `epub-cover-image`, `curdir`, `dzslides-core` can be overridden by `--variable` on the command line. Previously they would create lists in the template Context, which is not desirable.
-rw-r--r--src/Text/Pandoc/App/CommandLineOptions.hs3
-rw-r--r--src/Text/Pandoc/App/OutputSettings.hs11
-rw-r--r--test/writer.man2
-rw-r--r--test/writer.ms2
4 files changed, 10 insertions, 8 deletions
diff --git a/src/Text/Pandoc/App/CommandLineOptions.hs b/src/Text/Pandoc/App/CommandLineOptions.hs
index fc636e438..b54279e02 100644
--- a/src/Text/Pandoc/App/CommandLineOptions.hs
+++ b/src/Text/Pandoc/App/CommandLineOptions.hs
@@ -1062,7 +1062,8 @@ deprecatedOption o msg = do
Right () -> return ()
Left e -> optError e
--- | Set text value in text context.
+-- | Set text value in text context. Create list if it has a value already,
+-- or add to a list value.
setVariable :: Text -> Text -> Context Text -> Context Text
setVariable key val (Context ctx) = Context $ M.alter go key ctx
where go Nothing = Just $ toVal val
diff --git a/src/Text/Pandoc/App/OutputSettings.hs b/src/Text/Pandoc/App/OutputSettings.hs
index 4fd30ff66..17df09e9d 100644
--- a/src/Text/Pandoc/App/OutputSettings.hs
+++ b/src/Text/Pandoc/App/OutputSettings.hs
@@ -38,7 +38,7 @@ import System.IO (stdout)
import Text.Pandoc
import Text.Pandoc.App.FormatHeuristics (formatFromFilePaths)
import Text.Pandoc.App.Opt (Opt (..))
-import Text.Pandoc.App.CommandLineOptions (engines, setVariable)
+import Text.Pandoc.App.CommandLineOptions (engines)
import qualified Text.Pandoc.Format as Format
import Text.Pandoc.Highlighting (lookupHighlightingStyle)
import Text.Pandoc.Scripting (ScriptingEngine (engineLoadCustom),
@@ -163,8 +163,6 @@ optToOutputSettings scriptingEngine opts = do
hlStyle <- traverse (lookupHighlightingStyle . T.unpack) $
optHighlightStyle opts
- let setVariableM k v = return . setVariable k v
-
let setListVariableM _ [] ctx = return ctx
setListVariableM k vs ctx = do
let ctxMap = unContext ctx
@@ -263,6 +261,13 @@ optToOutputSettings scriptingEngine opts = do
, outputPdfProgram = maybePdfProg
}
+-- | Set text value in text context unless it is already set.
+setVariableM :: Monad m
+ => T.Text -> T.Text -> Context T.Text -> m (Context T.Text)
+setVariableM key val (Context ctx) = return $ Context $ M.alter go key ctx
+ where go Nothing = Just $ toVal val
+ go (Just x) = Just x
+
baseWriterName :: T.Text -> T.Text
baseWriterName = T.takeWhile (\c -> c /= '+' && c /= '-')
diff --git a/test/writer.man b/test/writer.man
index fb21c9f60..bee7f7178 100644
--- a/test/writer.man
+++ b/test/writer.man
@@ -1,5 +1,3 @@
-.\" Automatically generated by Pandoc 3.0
-.\"
.\" Define V font for inline verbatim, using C font in formats
.\" that render this, and otherwise B font.
.ie "\f[CB]x\f[]"x" \{\
diff --git a/test/writer.ms b/test/writer.ms
index ec7d5d6b1..32d7c1670 100644
--- a/test/writer.ms
+++ b/test/writer.ms
@@ -1,5 +1,3 @@
-.\" Automatically generated by Pandoc 3.0
-.\"
.\" **** Custom macro definitions *********************************
.\" * Super/subscript
.\" (https://lists.gnu.org/archive/html/groff/2012-07/msg00046.html)