git.iko.soy/typeable/pandoc
on master help sign in
Implemented templates for context writer.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@1701 788f1e2b-df1e-0410-8736-df70ead52e1b

commitb7750b705a57720681a3308f2c887ec86f82bf85 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 31 Dec 2009, 01:13 (17 years ago) parent1f580fb
2 files changed+43−76
src/Text/Pandoc/Writers/ConTeXt.hs+28−47 templates/context.template+15−29
src/Text/Pandoc/Writers/ConTeXt.hs+28−47
@@ -35,6 +35,7 @@ import Data.List ( isSuffixOf, intercalate, intersperse )
3535import Control.Monad.State
3636import Control.Monad (liftM)
3737import Text.PrettyPrint.HughesPJ hiding ( Str )
38+import Text.Pandoc.Templates ( renderTemplate )
3839
3940data WriterState =
4041 WriterState { stNextRef :: Int -- number of next URL reference
@@ -52,54 +53,34 @@ writeConTeXt options document =
5253 , stOrderedListLevel = 0
5354 , stOptions = options
5455 }
55− in render $
56− evalState (pandocToConTeXt options document) defaultWriterState
56+ in evalState (pandocToConTeXt options document) defaultWriterState
5757
58−pandocToConTeXt :: WriterOptions -> Pandoc -> State WriterState Doc
59−pandocToConTeXt options (Pandoc meta blocks) = do
60− return empty -- TODO
61−-- main <- blockListToConTeXt blocks
62−-- let before = if null (writerIncludeBefore options)
63−-- then empty
64−-- else text $ writerIncludeBefore options
65−-- let after = if null (writerIncludeAfter options)
66−-- then empty
67−-- else text $ writerIncludeAfter options
68−-- let body = before $$ main $$ after
69−-- head' <- if writerStandalone options
70−-- then contextHeader options meta
71−-- else return empty
72−-- let toc = if writerTableOfContents options
73−-- then text "\\placecontent\n"
74−-- else empty
75−-- let foot = if writerStandalone options
76−-- then text "\\stoptext\n"
77−-- else empty
78−-- return $ head' $$ toc $$ body $$ foot
79−
80−-- | Insert bibliographic information into ConTeXt header.
81−contextHeader :: WriterOptions -- ^ Options, including ConTeXt header
82− -> Meta -- ^ Meta with bibliographic information
83− -> State WriterState Doc
84−contextHeader options (Meta title authors date) = do
85− return empty -- TODO
86−-- titletext <- if null title
87−-- then return empty
88−-- else inlineListToConTeXt title
89−-- let authorstext = if null authors
90−-- then ""
91−-- else if length authors == 1
92−-- then stringToConTeXt $ head authors
93−-- else stringToConTeXt $ (intercalate ", " $
94−-- init authors) ++ " & " ++ last authors
95−-- let datetext = if date == ""
96−-- then ""
97−-- else stringToConTeXt date
98−-- let titleblock = text "\\doctitle{" <> titletext <> char '}' $$
99−-- text ("\\author{" ++ authorstext ++ "}") $$
100−-- text ("\\date{" ++ datetext ++ "}")
101−-- let header = text $ writerHeader options
102−-- return $ header $$ titleblock $$ text "\\starttext\n\\maketitle\n"
58+pandocToConTeXt :: WriterOptions -> Pandoc -> State WriterState String
59+pandocToConTeXt options (Pandoc (Meta title authors date) blocks) = do
60+ body <- blockListToConTeXt blocks
61+ let before = if null (writerIncludeBefore options)
62+ then empty
63+ else text $ writerIncludeBefore options
64+ let after = if null (writerIncludeAfter options)
65+ then empty
66+ else text $ writerIncludeAfter options
67+ let main = render $ before $$ body $$ after
68+ titletext <- if null title
69+ then return ""
70+ else liftM render $ inlineListToConTeXt title
71+ authorstext <- mapM (liftM render . inlineListToConTeXt) authors
72+ datetext <- if null date
73+ then return ""
74+ else liftM render $ inlineListToConTeXt date
75+ let context = writerVariables options ++
76+ [ ("toc", if writerTableOfContents options then "yes" else "")
77+ , ("body", main)
78+ , ("title", titletext)
79+ , ("authors", intercalate "\\\\" authorstext)
80+ , ("date", datetext) ]
81+ return $ if writerStandalone options
82+ then renderTemplate context $ writerTemplate options
83+ else main
10384
10485-- escape things as needed for ConTeXt
10586
templates/context.template+15−29
@@ -1,3 +1,6 @@
1+$if(legacy-header)$
2+$legacy-header$
3+$else$
14\enableregime[utf] % use UTF-8
25
36\setupcolors[state=start]
@@ -67,43 +70,26 @@ after={\blank[medium]},
6770]
6871
6972\protect
70−
73+$endif$
7174$header-includes$
7275
76+$if(title)$
7377\doctitle{$title$}
74−\author{\$authors\$}
75−\date{\$date\$}
78+$endif$
79+$if(authors)$
80+\author{$authors$}
81+$endif$
82+$if(date)$
83+\date{$date$}
84+$endif$
7685\starttext
7786\maketitle
7887
88+$if(toc)$
7989\placecontent
90+$endif$
8091
81−\subject{section oen}
82−
83−\startitemize[n][stopper=.]
84−\item
85− one
86− \startitemize[a][stopper=.]
87− \item
88− two
89− \startitemize[r][start=3,stopper=.,width=2.5em]
90− \item
91− three
92− \stopitemize
93− \stopitemize
94−\stopitemize
95−
96−\starttyping
97−hi
98−\stoptyping
99−
100−footnote
101−\footnote{with code
102−
103−\starttyping
104−code
105−\stoptyping
106−}
92+$body$
10793
10894\stoptext
10995