git.iko.soy/typeable/pandoc
on master help sign in
Writers: Use defField for defaults.

This way explicitly specified fields not overridden. Fixes a problem e.g. with specifying a documentclass via the command line using -V.

commit899a65b7d157193bdcb05bd4027a9e7a7fc3c9cc authorJohn MacFarlane <fiddlosopher@gmail.com> dateThu 27 Jun 2013, 22:42 (13 years ago) parent9ab60a4
15 files changed+83−83
src/Text/Pandoc/Writers/AsciiDoc.hs+3−3 src/Text/Pandoc/Writers/ConTeXt.hs+5−5 src/Text/Pandoc/Writers/Docbook.hs+2−2 src/Text/Pandoc/Writers/HTML.hs+14−14 src/Text/Pandoc/Writers/LaTeX.hs+25−25 src/Text/Pandoc/Writers/Man.hs+7−7 src/Text/Pandoc/Writers/Markdown.hs+3−3 src/Text/Pandoc/Writers/MediaWiki.hs+2−2 src/Text/Pandoc/Writers/OPML.hs+1−1 src/Text/Pandoc/Writers/OpenDocument.hs+3−3 src/Text/Pandoc/Writers/Org.hs+2−2 src/Text/Pandoc/Writers/RST.hs+6−6 src/Text/Pandoc/Writers/RTF.hs+3−3 src/Text/Pandoc/Writers/Texinfo.hs+6−6 src/Text/Pandoc/Writers/Textile.hs+1−1
src/Text/Pandoc/Writers/AsciiDoc.hs+3−3
@@ -84,10 +84,10 @@ pandocToAsciiDoc opts (Pandoc meta blocks) = do
8484 _ -> metadata
8585 body <- blockListToAsciiDoc opts blocks
8686 let main = render colwidth body
87− let context = setField "body" main
88− $ setField "toc"
87+ let context = defField "body" main
88+ $ defField "toc"
8989 (writerTableOfContents opts && writerStandalone opts)
90− $ setField "titleblock" titleblock
90+ $ defField "titleblock" titleblock
9191 $ foldl (\acc (x,y) -> setField x y acc)
9292 metadata' (writerVariables opts)
9393 if writerStandalone opts
src/Text/Pandoc/Writers/ConTeXt.hs+5−5
@@ -69,16 +69,16 @@ pandocToConTeXt options (Pandoc meta blocks) = do
6969 meta
7070 body <- mapM (elementToConTeXt options) $ hierarchicalize blocks
7171 let main = (render colwidth . vcat) body
72− let context = setField "toc" (writerTableOfContents options)
73− $ setField "placelist" (intercalate ("," :: String) $
72+ let context = defField "toc" (writerTableOfContents options)
73+ $ defField "placelist" (intercalate ("," :: String) $
7474 take (writerTOCDepth options + if writerChapters options
7575 then 0
7676 else 1)
7777 ["chapter","section","subsection","subsubsection",
7878 "subsubsubsection","subsubsubsubsection"])
79− $ setField "body" main
80− $ setField "number-sections" (writerNumberSections options)
81− $ setField "mainlang" (maybe ""
79+ $ defField "body" main
80+ $ defField "number-sections" (writerNumberSections options)
81+ $ defField "mainlang" (maybe ""
8282 (reverse . takeWhile (/=',') . reverse)
8383 (lookup "lang" $ writerVariables options))
8484 $ foldl (\acc (x,y) -> setField x y acc)
src/Text/Pandoc/Writers/Docbook.hs+2−2
@@ -87,8 +87,8 @@ writeDocbook opts (Pandoc meta blocks) =
8787 (Just . render colwidth . inlinesToDocbook opts)
8888 meta'
8989 main = render' $ vcat (map (elementToDocbook opts' startLvl) elements)
90− context = setField "body" main
91− $ setField "mathml" (case writerHTMLMathMethod opts of
90+ context = defField "body" main
91+ $ defField "mathml" (case writerHTMLMathMethod opts of
9292 MathML _ -> True
9393 _ -> False)
9494 $ foldl (\acc (x,y) -> setField x y acc)
src/Text/Pandoc/Writers/HTML.hs+14−14
@@ -156,25 +156,25 @@ pandocToHtml opts (Pandoc meta blocks) = do
156156 Nothing -> mempty
157157 else mempty
158158 let context = (if stHighlighting st
159− then setField "highlighting-css"
159+ then defField "highlighting-css"
160160 (styleToCss $ writerHighlightStyle opts)
161161 else id) $
162162 (if stMath st
163− then setField "math" (renderHtml math)
163+ then defField "math" (renderHtml math)
164164 else id) $
165− setField "quotes" (stQuotes st) $
166− maybe id (setField "toc" . renderHtml) toc $
167− setField "author-meta" authsMeta $
168− maybe id (setField "date-meta") (normalizeDate dateMeta) $
169− setField "pagetitle" (stringify $ docTitle meta) $
170− setField "idprefix" (writerIdentifierPrefix opts) $
165+ defField "quotes" (stQuotes st) $
166+ maybe id (defField "toc" . renderHtml) toc $
167+ defField "author-meta" authsMeta $
168+ maybe id (defField "date-meta") (normalizeDate dateMeta) $
169+ defField "pagetitle" (stringify $ docTitle meta) $
170+ defField "idprefix" (writerIdentifierPrefix opts) $
171171 -- these should maybe be set in pandoc.hs
172− setField "slidy-url"
172+ defField "slidy-url"
173173 ("http://www.w3.org/Talks/Tools/Slidy2" :: String) $
174− setField "slideous-url" ("slideous" :: String) $
175− setField "revealjs-url" ("reveal.js" :: String) $
176− setField "s5-url" ("s5/default" :: String) $
177− setField "html5" (writerHtml5 opts) $
174+ defField "slideous-url" ("slideous" :: String) $
175+ defField "revealjs-url" ("reveal.js" :: String) $
176+ defField "s5-url" ("s5/default" :: String) $
177+ defField "html5" (writerHtml5 opts) $
178178 foldl (\acc (x,y) -> setField x y acc)
179179 metadata (writerVariables opts)
180180 return (thebody, context)
@@ -185,7 +185,7 @@ inTemplate :: TemplateTarget a
185185 -> Html
186186 -> a
187187inTemplate opts context body = renderTemplate' (writerTemplate opts)
188− $ setField "body" (renderHtml body) context
188+ $ defField "body" (renderHtml body) context
189189
190190-- | Like Text.XHtml's identifier, but adds the writerIdentifierPrefix
191191prefixedId :: WriterOptions -> String -> Attribute
src/Text/Pandoc/Writers/LaTeX.hs+25−25
@@ -120,43 +120,43 @@ pandocToLaTeX options (Pandoc meta blocks) = do
120120 let main = render colwidth $ vsep body
121121 st <- get
122122 let biblioFiles = intercalate "," $ map dropExtension $ writerBiblioFiles options
123− let context = setField "toc" (writerTableOfContents options) $
124− setField "toc-depth" (show (writerTOCDepth options -
123+ let context = defField "toc" (writerTableOfContents options) $
124+ defField "toc-depth" (show (writerTOCDepth options -
125125 if writerChapters options
126126 then 1
127127 else 0)) $
128− setField "body" main $
129− setField "title-meta" (stringify $ docTitle meta) $
130− setField "author-meta" (intercalate "; " $ map stringify $ docAuthors meta) $
131− setField "documentclass" (if writerBeamer options
128+ defField "body" main $
129+ defField "title-meta" (stringify $ docTitle meta) $
130+ defField "author-meta" (intercalate "; " $ map stringify $ docAuthors meta) $
131+ defField "documentclass" (if writerBeamer options
132132 then ("beamer" :: String)
133133 else if writerChapters options
134134 then "book"
135135 else "article") $
136− setField "verbatim-in-note" (stVerbInNote st) $
137− setField "tables" (stTable st) $
138− setField "strikeout" (stStrikeout st) $
139− setField "url" (stUrl st) $
140− setField "numbersections" (writerNumberSections options) $
141− setField "lhs" (stLHS st) $
142− setField "graphics" (stGraphics st) $
143− setField "book-class" (stBook st) $
144− setField "euro" (stUsesEuro st) $
145− setField "listings" (writerListings options || stLHS st) $
146− setField "beamer" (writerBeamer options) $
147− setField "mainlang" (maybe "" (reverse . takeWhile (/=',') . reverse)
136+ defField "verbatim-in-note" (stVerbInNote st) $
137+ defField "tables" (stTable st) $
138+ defField "strikeout" (stStrikeout st) $
139+ defField "url" (stUrl st) $
140+ defField "numbersections" (writerNumberSections options) $
141+ defField "lhs" (stLHS st) $
142+ defField "graphics" (stGraphics st) $
143+ defField "book-class" (stBook st) $
144+ defField "euro" (stUsesEuro st) $
145+ defField "listings" (writerListings options || stLHS st) $
146+ defField "beamer" (writerBeamer options) $
147+ defField "mainlang" (maybe "" (reverse . takeWhile (/=',') . reverse)
148148 (lookup "lang" $ writerVariables options)) $
149149 (if stHighlighting st
150− then setField "highlighting-macros" (styleToLaTeX
150+ then defField "highlighting-macros" (styleToLaTeX
151151 $ writerHighlightStyle options )
152152 else id) $
153153 (case writerCiteMethod options of
154− Natbib -> setField "biblio-files" biblioFiles .
155− setField "biblio-title" biblioTitle .
156− setField "natbib" True
157− Biblatex -> setField "biblio-files" biblioFiles .
158− setField "biblio-title" biblioTitle .
159− setField "biblatex" True
154+ Natbib -> defField "biblio-files" biblioFiles .
155+ defField "biblio-title" biblioTitle .
156+ defField "natbib" True
157+ Biblatex -> defField "biblio-files" biblioFiles .
158+ defField "biblio-title" biblioTitle .
159+ defField "biblatex" True
160160 _ -> id) $
161161 foldl (\acc (x,y) -> setField x y acc)
162162 metadata (writerVariables options)
src/Text/Pandoc/Writers/Man.hs+7−7
@@ -62,15 +62,15 @@ pandocToMan opts (Pandoc meta blocks) = do
6262 case break (== ' ') title' of
6363 (cmdName, rest) -> case reverse cmdName of
6464 (')':d:'(':xs) | isDigit d ->
65− setField "title" (reverse xs) .
66− setField "section" [d] .
65+ defField "title" (reverse xs) .
66+ defField "section" [d] .
6767 case splitBy (=='|') rest of
6868 (ft:hds) ->
69− setField "footer" (trim ft) .
70− setField "header"
69+ defField "footer" (trim ft) .
70+ defField "header"
7171 (trim $ concat hds)
7272 [] -> id
73− _ -> setField "title" title'
73+ _ -> defField "title" title'
7474 metadata <- metaToJSON
7575 (fmap (render colwidth) . blockListToMan opts)
7676 (fmap (render colwidth) . inlineListToMan opts)
@@ -80,9 +80,9 @@ pandocToMan opts (Pandoc meta blocks) = do
8080 notes' <- notesToMan opts (reverse notes)
8181 let main = render' $ body $$ notes' $$ text ""
8282 hasTables <- liftM stHasTables get
83− let context = setField "body" main
83+ let context = defField "body" main
8484 $ setFieldsFromTitle
85− $ setField "has-tables" hasTables
85+ $ defField "has-tables" hasTables
8686 $ foldl (\acc (x,y) -> setField x y acc)
8787 metadata (writerVariables opts)
8888 if writerStandalone opts
src/Text/Pandoc/Writers/Markdown.hs+3−3
@@ -145,11 +145,11 @@ pandocToMarkdown opts (Pandoc meta blocks) = do
145145 let main = render' $ body <>
146146 (if isEmpty notes' then empty else blankline <> notes') <>
147147 (if isEmpty refs' then empty else blankline <> refs')
148− let context = setField "toc" (render' toc)
149− $ setField "body" main
148+ let context = defField "toc" (render' toc)
149+ $ defField "body" main
150150 $ (if not (null (docTitle meta) && null (docAuthors meta)
151151 && null (docDate meta))
152− then setField "titleblock" (render' titleblock)
152+ then defField "titleblock" (render' titleblock)
153153 else id)
154154 $ foldl (\acc (x,y) -> setField x y acc)
155155 metadata (writerVariables opts)
src/Text/Pandoc/Writers/MediaWiki.hs+2−2
@@ -64,8 +64,8 @@ pandocToMediaWiki opts (Pandoc meta blocks) = do
6464 then "\n<references />"
6565 else ""
6666 let main = body ++ notes
67− let context = setField "body" main
68− $ setField "toc" (writerTableOfContents opts)
67+ let context = defField "body" main
68+ $ defField "toc" (writerTableOfContents opts)
6969 $ foldl (\acc (x,y) -> setField x y acc)
7070 metadata (writerVariables opts)
7171 if writerStandalone opts
src/Text/Pandoc/Writers/OPML.hs+1−1
@@ -54,7 +54,7 @@ writeOPML opts (Pandoc meta blocks) =
5454 (\ils -> [Plain ils]))
5555 meta'
5656 main = render colwidth $ vcat (map (elementToOPML opts) elements)
57− context = setField "body" main
57+ context = defField "body" main
5858 $ foldl (\acc (x,y) -> setField x y acc)
5959 metadata (writerVariables opts)
6060 in if writerStandalone opts
src/Text/Pandoc/Writers/OpenDocument.hs+3−3
@@ -42,7 +42,7 @@ import Control.Arrow ( (***), (>>>) )
4242import Control.Monad.State hiding ( when )
4343import Data.Char (chr, isDigit)
4444import qualified Data.Map as Map
45−import Text.Pandoc.Shared (metaToJSON, setField)
45+import Text.Pandoc.Shared (metaToJSON, defField, setField)
4646
4747-- | Auxiliary function to convert Plain block to Para.
4848plainToPara :: Block -> Block
@@ -192,8 +192,8 @@ writeOpenDocument opts (Pandoc meta blocks) =
192192 listStyles = map listStyle (stListStyles s)
193193 automaticStyles = inTagsIndented "office:automatic-styles" $ vcat $
194194 reverse $ styles ++ listStyles
195− context = setField "body" body
196− $ setField "automatic-styles" (render' automaticStyles)
195+ context = defField "body" body
196+ $ defField "automatic-styles" (render' automaticStyles)
197197 $ foldl (\acc (x,y) -> setField x y acc)
198198 metadata (writerVariables opts)
199199 in if writerStandalone opts
src/Text/Pandoc/Writers/Org.hs+2−2
@@ -72,8 +72,8 @@ pandocToOrg (Pandoc meta blocks) = do
7272 -- note that the notes may contain refs, so we do them first
7373 hasMath <- liftM stHasMath get
7474 let main = render colwidth $ foldl ($+$) empty $ [body, notes]
75− let context = setField "body" main
76− $ setField "math" hasMath
75+ let context = defField "body" main
76+ $ defField "math" hasMath
7777 $ foldl (\acc (x,y) -> setField x y acc)
7878 metadata (writerVariables opts)
7979 if writerStandalone opts
src/Text/Pandoc/Writers/RST.hs+6−6
@@ -82,12 +82,12 @@ pandocToRST (Pandoc meta blocks) = do
8282 pics <- liftM (reverse . stImages) get >>= pictRefsToRST
8383 hasMath <- liftM stHasMath get
8484 let main = render colwidth $ foldl ($+$) empty $ [body, notes, refs, pics]
85− let context = setField "body" main
86− $ setField "toc" (writerTableOfContents opts)
87− $ setField "toc-depth" (writerTOCDepth opts)
88− $ setField "math" hasMath
89− $ setField "title" (render Nothing title :: String)
90− $ setField "math" hasMath
85+ let context = defField "body" main
86+ $ defField "toc" (writerTableOfContents opts)
87+ $ defField "toc-depth" (writerTOCDepth opts)
88+ $ defField "math" hasMath
89+ $ defField "title" (render Nothing title :: String)
90+ $ defField "math" hasMath
9191 $ foldl (\acc (x,y) -> setField x y acc)
9292 metadata (writerVariables opts)
9393 if writerStandalone opts
src/Text/Pandoc/Writers/RTF.hs+3−3
@@ -82,10 +82,10 @@ writeRTF options (Pandoc meta blocks) =
8282 body = concatMap (blockToRTF 0 AlignDefault) blocks
8383 isTOCHeader (Header lev _ _) = lev <= writerTOCDepth options
8484 isTOCHeader _ = False
85− context = setField "body" body
86− $ setField "spacer" spacer
85+ context = defField "body" body
86+ $ defField "spacer" spacer
8787 $ (if writerTableOfContents options
88− then setField "toc"
88+ then defField "toc"
8989 (tableOfContents $ filter isTOCHeader blocks)
9090 else id)
9191 $ foldl (\acc (x,y) -> setField x y acc)
src/Text/Pandoc/Writers/Texinfo.hs+6−6
@@ -80,12 +80,12 @@ pandocToTexinfo options (Pandoc meta blocks) = do
8080 main <- blockListToTexinfo blocks
8181 st <- get
8282 let body = render colwidth main
83− let context = setField "body" body
84− $ setField "toc" (writerTableOfContents options)
85− $ setField "titlepage" titlePage
86− $ setField "subscript" (stSubscript st)
87− $ setField "superscript" (stSuperscript st)
88− $ setField "strikeout" (stStrikeout st)
83+ let context = defField "body" body
84+ $ defField "toc" (writerTableOfContents options)
85+ $ defField "titlepage" titlePage
86+ $ defField "subscript" (stSubscript st)
87+ $ defField "superscript" (stSuperscript st)
88+ $ defField "strikeout" (stStrikeout st)
8989 $ foldl (\acc (x,y) -> setField x y acc)
9090 metadata (writerVariables options)
9191 if writerStandalone options
src/Text/Pandoc/Writers/Textile.hs+1−1
@@ -59,7 +59,7 @@ pandocToTextile opts (Pandoc meta blocks) = do
5959 body <- blockListToTextile opts blocks
6060 notes <- liftM (unlines . reverse . stNotes) get
6161 let main = body ++ if null notes then "" else ("\n\n" ++ notes)
62− let context = setField "body" main
62+ let context = defField "body" main
6363 $ foldl (\acc (x,y) -> setField x y acc)
6464 metadata (writerVariables opts)
6565 if writerStandalone opts