Skip to content

Commit

Permalink
XWiki writer: use template if it is specified.
Browse files Browse the repository at this point in the history
Previously templates were ignored completely.

Closes #8296.
  • Loading branch information
jgm committed Sep 13, 2022
1 parent 369058d commit eb03cad
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Text/Pandoc/Writers/XWiki.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ import Text.Pandoc.Options
import Text.Pandoc.Shared
import Text.Pandoc.Writers.MediaWiki (highlightingLangs)
import Text.Pandoc.Writers.Shared (toLegacyTable)
import Text.Pandoc.Templates (renderTemplate)
import Text.Pandoc.Writers.Shared (defField, metaToContext)
import Text.DocLayout (render, literal)

newtype WriterState = WriterState {
listLevel :: Text -- String at the beginning of items
Expand All @@ -53,9 +56,19 @@ type XWikiReader m = ReaderT WriterState m

-- | Convert Pandoc to XWiki.
writeXWiki :: PandocMonad m => WriterOptions -> Pandoc -> m Text
writeXWiki _ (Pandoc _ blocks) =
writeXWiki opts (Pandoc meta blocks) = do
let env = WriterState { listLevel = "" }
in runReaderT (blockListToXWiki blocks) env
metadata <- metaToContext opts
(fmap (literal . trimr) . (\bs -> runReaderT (blockListToXWiki bs) env))
(fmap (literal . trimr) . (\is -> runReaderT (inlineListToXWiki is) env))
meta
body <- runReaderT (blockListToXWiki blocks) env
let context = defField "body" body
$ defField "toc" (writerTableOfContents opts) metadata
return $
case writerTemplate opts of
Just tpl -> render Nothing $ renderTemplate tpl context
Nothing -> body

-- | Concatenates strings with line breaks between them.
vcat :: [Text] -> Text
Expand Down

0 comments on commit eb03cad

Please sign in to comment.