commit 37523bca4990f5c692bd0862ab752e7507f366ae
parent acf6e9be5b4d4e330d11fe501173a450dc317a1b
Author: krasjet
Date: 2020-03-21 17:52Z

number sections

Diffstat:
Msrc/Karasu/Pandoc/Options.hs | 11+++++++----
Msrc/Karasu/Pandoc/Renderer.hs | 14+++++++++++---
2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/Karasu/Pandoc/Options.hs b/src/Karasu/Pandoc/Options.hs @@ -8,8 +8,11 @@ defKarasuReaderOptions :: ReaderOptions defKarasuReaderOptions= def { readerExtensions = enableExtension Ext_smart pandocExtensions } - -- | Default writer options for Karasu -defKarasuWriterOptions :: WriterOptions -defKarasuWriterOptions = def - { writerExtensions = enableExtension Ext_smart pandocExtensions } +defKarasuWriterOptions + :: Bool -- ^ number sections + -> WriterOptions +defKarasuWriterOptions numSec = def + { writerExtensions = enableExtension Ext_smart pandocExtensions + , writerNumberSections = numSec + } diff --git a/src/Karasu/Pandoc/Renderer.hs b/src/Karasu/Pandoc/Renderer.hs @@ -3,9 +3,9 @@ -- | The renderer for markdown -> html conversion module Karasu.Pandoc.Renderer (renderPreview, renderDisplay) where -import Karasu.Pandoc.Options import Karasu.Models import Karasu.Pandoc.Filters +import Karasu.Pandoc.Options import qualified Data.Text as T @@ -37,14 +37,22 @@ renderWith -> Text -- ^ content of the markdown -> IO (Either PandocError a) -- ^ error or the final HTML renderWith writer fs md = runIO $ do - pandoc' <- readMarkdown defKarasuReaderOptions md + pandoc'@(Pandoc meta _) <- readMarkdown defKarasuReaderOptions md + + -- denote if we should enable number sections + let numSec = case lookupMeta "number-sections" meta of + Just (MetaBool b) -> b + Just _ -> False + Nothing -> False + -- apply filters pandoc <- applyPandocFiltersIO fs pandoc' + -- load preview templates -- TODO cache to memory instead res <- liftIO $ compileTemplateFile $ "templates" </> "preview" <.> "html" case res of Left e -> throwError $ PandocTemplateError (T.pack e) Right template -> do - let wOpts = defKarasuWriterOptions { writerTemplate = Just template } + let wOpts = (defKarasuWriterOptions numSec) { writerTemplate = Just template } writer wOpts pandoc