git.iko.soy/typeable/pandoc
on master help sign in
Made Citation information available in lua custom writer.
commit2a881541a04d3aef04dbfb313afbcce576780ee3 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 16 Jul 2014, 09:32 (12 years ago) parent1bff443
2 files changed+24−4
data/sample.lua+7−2 src/Text/Pandoc/Writers/Custom.hs+17−2
data/sample.lua+7−2
@@ -181,8 +181,13 @@ function Span(s, attr)
181181 return "<span" .. attributes(attr) .. ">" .. s .. "</span>"
182182end
183183
184−function Cite(s)
185− return "<span class=\"cite\">" .. s .. "</span>"
184+function Cite(s, cs)
185+ local ids = {}
186+ for _,cit in ipairs(cs) do
187+ table.insert(ids, cit.citationId)
188+ end
189+ return "<span class=\"cite\" data-citation-ids=\"" .. table.concat(ids, ",") ..
190+ "\">" .. s .. "</span>"
186191end
187192
188193function Plain(s)
src/Text/Pandoc/Writers/Custom.hs+17−2
@@ -1,4 +1,5 @@
1−{-# LANGUAGE OverlappingInstances, FlexibleInstances, OverloadedStrings #-}
1+{-# LANGUAGE OverlappingInstances, FlexibleInstances, OverloadedStrings,
2+ ScopedTypeVariables #-}
23{-# OPTIONS_GHC -fno-warn-orphans #-}
34{- Copyright (C) 2012-2014 John MacFarlane <jgm@berkeley.edu>
45
@@ -128,6 +129,20 @@ instance StackValue MetaValue where
128129 valuetype (MetaInlines _) = Lua.TSTRING
129130 valuetype (MetaBlocks _) = Lua.TSTRING
130131
132+instance StackValue Citation where
133+ push lua cit = do
134+ Lua.createtable lua 6 0
135+ let addValue ((k :: String), v) = Lua.push lua k >> Lua.push lua v >>
136+ Lua.rawset lua (-3)
137+ addValue ("citationId", citationId cit)
138+ addValue ("citationPrefix", citationPrefix cit)
139+ addValue ("citationSuffix", citationSuffix cit)
140+ addValue ("citationMode", show (citationMode cit))
141+ addValue ("citationNoteNum", citationNoteNum cit)
142+ addValue ("citationHash", citationHash cit)
143+ peek = undefined
144+ valuetype _ = Lua.TTABLE
145+
131146-- | Convert Pandoc to custom markup.
132147writeCustom :: FilePath -> WriterOptions -> Pandoc -> IO String
133148writeCustom luaFile opts doc = do
@@ -225,7 +240,7 @@ inlineToCustom lua (Quoted SingleQuote lst) = callfunc lua "SingleQuoted" lst
225240
226241inlineToCustom lua (Quoted DoubleQuote lst) = callfunc lua "DoubleQuoted" lst
227242
228−inlineToCustom lua (Cite _ lst) = callfunc lua "Cite" lst
243+inlineToCustom lua (Cite cs lst) = callfunc lua "Cite" lst cs
229244
230245inlineToCustom lua (Code attr str) =
231246 callfunc lua "Code" (fromString str) (attrToMap attr)