git.iko.soy/typeable/pandoc
on master help sign in
Custom writer: Pass full metadata, not just tit/auth/date.
commit644e3239a9d1fc92f7409db8612ced39e38fde2f authorJohn MacFarlane <fiddlosopher@gmail.com> dateThu 27 Jun 2013, 22:55 (13 years ago) parent899a65b
2 files changed+22−12
data/sample.lua+7−7 src/Text/Pandoc/Writers/Custom.hs+15−5
data/sample.lua+7−7
@@ -66,10 +66,10 @@ function Blocksep()
6666end
6767
6868-- This function is called once for the whole document. Parameters:
69−-- body, title, date are strings; authors is an array of strings;
70−-- variables is a table. One could use some kind of templating
69+-- body is a string, metadata is a table, variables is a table.
70+-- One could use some kind of templating
7171-- system here; this just gives you a simple standalone HTML file.
72−function Doc(body, title, authors, date, variables)
72+function Doc(body, metadata, variables)
7373 local buffer = {}
7474 local function add(s)
7575 table.insert(buffer, s)
@@ -77,17 +77,17 @@ function Doc(body, title, authors, date, variables)
7777 add('<!DOCTYPE html>')
7878 add('<html>')
7979 add('<head>')
80− add('<title>' .. title .. '</title>')
80+ add('<title>' .. metadata.title .. '</title>')
8181 add('</head>')
8282 add('<body>')
8383 if title ~= "" then
84− add('<h1 class="title">' .. title .. '</h1>')
84+ add('<h1 class="title">' .. metadata.title .. '</h1>')
8585 end
86− for _, author in pairs(authors) do
86+ for _, author in pairs(metadata.author) do
8787 add('<h2 class="author">' .. author .. '</h2>')
8888 end
8989 if date ~= "" then
90− add('<h3 class="date">' .. date .. '</h3>')
90+ add('<h3 class="date">' .. metadata.date .. '</h3>')
9191 end
9292 add(body)
9393 if #notes > 0 then
src/Text/Pandoc/Writers/Custom.hs+15−5
@@ -107,6 +107,19 @@ instance StackValue [Block] where
107107 peek _ _ = undefined
108108 valuetype _ = Lua.TSTRING
109109
110+instance StackValue MetaValue where
111+ push l (MetaMap m) = Lua.push l m
112+ push l (MetaList xs) = Lua.push l xs
113+ push l (MetaString s) = Lua.push l s
114+ push l (MetaInlines ils) = Lua.push l ils
115+ push l (MetaBlocks bs) = Lua.push l bs
116+ peek _ _ = undefined
117+ valuetype (MetaMap _) = Lua.TTABLE
118+ valuetype (MetaList _) = Lua.TTABLE
119+ valuetype (MetaString _) = Lua.TSTRING
120+ valuetype (MetaInlines _) = Lua.TSTRING
121+ valuetype (MetaBlocks _) = Lua.TSTRING
122+
110123-- | Convert Pandoc to custom markup.
111124writeCustom :: FilePath -> WriterOptions -> Pandoc -> IO String
112125writeCustom luaFile opts doc = do
@@ -121,12 +134,9 @@ writeCustom luaFile opts doc = do
121134 return $ toString rendered
122135
123136docToCustom :: LuaState -> WriterOptions -> Pandoc -> IO ByteString
124−docToCustom lua opts (Pandoc meta blocks) = do
125− title' <- inlineListToCustom lua $ docTitle meta
126− authors' <- mapM (inlineListToCustom lua) $ docAuthors meta
127− date' <- inlineListToCustom lua $ docDate meta
137+docToCustom lua opts (Pandoc (Meta metamap) blocks) = do
128138 body <- blockListToCustom lua blocks
129− callfunc lua "Doc" body title' authors' date' (writerVariables opts)
139+ callfunc lua "Doc" body metamap (writerVariables opts)
130140
131141-- | Convert Pandoc block element to Custom.
132142blockToCustom :: LuaState -- ^ Lua state