From 297345098db4b06bcb46cf39d2a74518eb24eb3a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 22 Dec 2015 13:28:11 -0800 Subject: ConTeXt writer: set default layout based on margin-left, etc. This sets up `\setuplayout` based on the variables `margin-left`, `margin-right`, `margin-bottom`, and `margin-top`, if no layout is given. --- src/Text/Pandoc/Writers/ConTeXt.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Text/Pandoc/Writers/ConTeXt.hs') diff --git a/src/Text/Pandoc/Writers/ConTeXt.hs b/src/Text/Pandoc/Writers/ConTeXt.hs index 446da142c..498e2d10f 100644 --- a/src/Text/Pandoc/Writers/ConTeXt.hs +++ b/src/Text/Pandoc/Writers/ConTeXt.hs @@ -37,6 +37,7 @@ import Text.Pandoc.Walk (query) import Text.Printf ( printf ) import Data.List ( intercalate, intersperse ) import Data.Char ( ord ) +import Data.Maybe ( catMaybes ) import Control.Monad.State import Text.Pandoc.Pretty import Text.Pandoc.ImageSize @@ -72,6 +73,14 @@ pandocToConTeXt options (Pandoc meta blocks) = do meta body <- mapM (elementToConTeXt options) $ hierarchicalize blocks let main = (render colwidth . vcat) body + let layoutFromMargins = intercalate [','] $ catMaybes $ + map (\(x,y) -> + ((x ++ "=") ++) <$> getField y metadata) + [("leftmargin","margin-left") + ,("rightmargin","margin-right") + ,("top","margin-top") + ,("bottom","margin-bottom") + ] let context = defField "toc" (writerTableOfContents options) $ defField "placelist" (intercalate ("," :: String) $ take (writerTOCDepth options + if writerChapters options @@ -80,6 +89,7 @@ pandocToConTeXt options (Pandoc meta blocks) = do ["chapter","section","subsection","subsubsection", "subsubsubsection","subsubsubsubsection"]) $ defField "body" main + $ defField "layout" layoutFromMargins $ defField "number-sections" (writerNumberSections options) $ metadata let context' = defField "context-lang" (maybe "" (fromBcp47 . splitBy (=='-')) $ -- cgit v1.2.3