@@ -170,10 +170,10 @@ pushBlock :: LuaState -> Block -> IO ()
170pushBlock lua = \case
170pushBlock lua = \case
171 BlockQuote blcks -> pushViaConstructor lua "BlockQuote" blcks
171 BlockQuote blcks -> pushViaConstructor lua "BlockQuote" blcks
172 BulletList items -> pushViaConstructor lua "BulletList" items
172 BulletList items -> pushViaConstructor lua "BulletList" items
173− CodeBlock attr code -> pushViaConstructor lua "CodeBlock" code attr
173+ CodeBlock attr code -> pushViaConstructor lua "CodeBlock" code (LuaAttr attr)
174 DefinitionList items -> pushViaConstructor lua "DefinitionList" items
174 DefinitionList items -> pushViaConstructor lua "DefinitionList" items
175− Div attr blcks -> pushViaConstructor lua "Div" blcks attr
175+ Div attr blcks -> pushViaConstructor lua "Div" blcks (LuaAttr attr)
176− Header lvl attr inlns -> pushViaConstructor lua "Header" lvl attr inlns
176+ Header lvl attr inlns -> pushViaConstructor lua "Header" lvl (LuaAttr attr) inlns
177 HorizontalRule -> pushViaConstructor lua "HorizontalRule"
177 HorizontalRule -> pushViaConstructor lua "HorizontalRule"
178 LineBlock blcks -> pushViaConstructor lua "LineBlock" blcks
178 LineBlock blcks -> pushViaConstructor lua "LineBlock" blcks
179 OrderedList lstAttr list -> pushViaConstructor lua "OrderedList" list lstAttr
179 OrderedList lstAttr list -> pushViaConstructor lua "OrderedList" list lstAttr
@@ -193,10 +193,10 @@ peekBlock lua idx = do
193 Just t -> case t of
193 Just t -> case t of
194 "BlockQuote" -> fmap BlockQuote <$> elementContent
194 "BlockQuote" -> fmap BlockQuote <$> elementContent
195 "BulletList" -> fmap BulletList <$> elementContent
195 "BulletList" -> fmap BulletList <$> elementContent
196− "CodeBlock" -> fmap (uncurry CodeBlock) <$> elementContent
196+ "CodeBlock" -> fmap (withAttr CodeBlock) <$> elementContent
197 "DefinitionList" -> fmap DefinitionList <$> elementContent
197 "DefinitionList" -> fmap DefinitionList <$> elementContent
198− "Div" -> fmap (uncurry Div) <$> elementContent
198+ "Div" -> fmap (withAttr Div) <$> elementContent
199− "Header" -> fmap (\(lvl, attr, lst) -> Header lvl attr lst)
199+ "Header" -> fmap (\(lvl, LuaAttr attr, lst) -> Header lvl attr lst)
200 <$> elementContent
200 <$> elementContent
201 "HorizontalRule" -> return (Just HorizontalRule)
201 "HorizontalRule" -> return (Just HorizontalRule)
202 "LineBlock" -> fmap LineBlock <$> elementContent
202 "LineBlock" -> fmap LineBlock <$> elementContent
@@ -218,11 +218,11 @@ peekBlock lua idx = do
218pushInline :: LuaState -> Inline -> IO ()
218pushInline :: LuaState -> Inline -> IO ()
219pushInline lua = \case
219pushInline lua = \case
220 Cite citations lst -> pushViaConstructor lua "Cite" lst citations
220 Cite citations lst -> pushViaConstructor lua "Cite" lst citations
221− Code attr lst -> pushViaConstructor lua "Code" lst attr
221+ Code attr lst -> pushViaConstructor lua "Code" lst (LuaAttr attr)
222 Emph inlns -> pushViaConstructor lua "Emph" inlns
222 Emph inlns -> pushViaConstructor lua "Emph" inlns
223− Image attr alt (src,tit) -> pushViaConstructor lua "Image" alt src tit attr
223+ Image attr alt (src,tit) -> pushViaConstructor lua "Image" alt src tit (LuaAttr attr)
224 LineBreak -> pushViaConstructor lua "LineBreak"
224 LineBreak -> pushViaConstructor lua "LineBreak"
225− Link attr lst (src,tit) -> pushViaConstructor lua "Link" lst src tit attr
225+ Link attr lst (src,tit) -> pushViaConstructor lua "Link" lst src tit (LuaAttr attr)
226 Note blcks -> pushViaConstructor lua "Note" blcks
226 Note blcks -> pushViaConstructor lua "Note" blcks
227 Math mty str -> pushViaConstructor lua "Math" mty str
227 Math mty str -> pushViaConstructor lua "Math" mty str
228 Quoted qt inlns -> pushViaConstructor lua "Quoted" qt inlns
228 Quoted qt inlns -> pushViaConstructor lua "Quoted" qt inlns
@@ -230,7 +230,7 @@ pushInline lua = \case
230 SmallCaps inlns -> pushViaConstructor lua "SmallCaps" inlns
230 SmallCaps inlns -> pushViaConstructor lua "SmallCaps" inlns
231 SoftBreak -> pushViaConstructor lua "SoftBreak"
231 SoftBreak -> pushViaConstructor lua "SoftBreak"
232 Space -> pushViaConstructor lua "Space"
232 Space -> pushViaConstructor lua "Space"
233− Span attr inlns -> pushViaConstructor lua "Span" inlns attr
233+ Span attr inlns -> pushViaConstructor lua "Span" inlns (LuaAttr attr)
234 Str str -> pushViaConstructor lua "Str" str
234 Str str -> pushViaConstructor lua "Str" str
235 Strikeout inlns -> pushViaConstructor lua "Strikeout" inlns
235 Strikeout inlns -> pushViaConstructor lua "Strikeout" inlns
236 Strong inlns -> pushViaConstructor lua "Strong" inlns
236 Strong inlns -> pushViaConstructor lua "Strong" inlns
@@ -245,11 +245,11 @@ peekInline lua idx = do
245 Nothing -> return Nothing
245 Nothing -> return Nothing
246 Just t -> case t of
246 Just t -> case t of
247 "Cite" -> fmap (uncurry Cite) <$> elementContent
247 "Cite" -> fmap (uncurry Cite) <$> elementContent
248− "Code" -> fmap (uncurry Code) <$> elementContent
248+ "Code" -> fmap (withAttr Code) <$> elementContent
249 "Emph" -> fmap Emph <$> elementContent
249 "Emph" -> fmap Emph <$> elementContent
250− "Image" -> fmap (\(attr, lst, tgt) -> Image attr lst tgt)
250+ "Image" -> fmap (\(LuaAttr attr, lst, tgt) -> Image attr lst tgt)
251 <$> elementContent
251 <$> elementContent
252− "Link" -> fmap (\(attr, lst, tgt) -> Link attr lst tgt)
252+ "Link" -> fmap (\(LuaAttr attr, lst, tgt) -> Link attr lst tgt)
253 <$> elementContent
253 <$> elementContent
254 "LineBreak" -> return (Just LineBreak)
254 "LineBreak" -> return (Just LineBreak)
255 "Note" -> fmap Note <$> elementContent
255 "Note" -> fmap Note <$> elementContent
@@ -259,7 +259,7 @@ peekInline lua idx = do
259 "SmallCaps" -> fmap SmallCaps <$> elementContent
259 "SmallCaps" -> fmap SmallCaps <$> elementContent
260 "SoftBreak" -> return (Just SoftBreak)
260 "SoftBreak" -> return (Just SoftBreak)
261 "Space" -> return (Just Space)
261 "Space" -> return (Just Space)
262− "Span" -> fmap (uncurry Span) <$> elementContent
262+ "Span" -> fmap (withAttr Span) <$> elementContent
263 "Str" -> fmap Str <$> elementContent
263 "Str" -> fmap Str <$> elementContent
264 "Strikeout" -> fmap Strikeout <$> elementContent
264 "Strikeout" -> fmap Strikeout <$> elementContent
265 "Strong" -> fmap Strong <$> elementContent
265 "Strong" -> fmap Strong <$> elementContent
@@ -270,3 +270,15 @@ peekInline lua idx = do
270 -- Get the contents of an AST element.
270 -- Get the contents of an AST element.
271 elementContent :: StackValue a => IO (Maybe a)
271 elementContent :: StackValue a => IO (Maybe a)
272 elementContent = getTable lua idx "c"
272 elementContent = getTable lua idx "c"
274+withAttr :: (Attr -> a -> b) -> (LuaAttr, a) -> b
275+withAttr f (attributes, x) = f (fromLuaAttr attributes) x
277+-- | Wrapper for Attr
278+newtype LuaAttr = LuaAttr { fromLuaAttr :: Attr }
280+instance StackValue LuaAttr where
281+ push lua (LuaAttr (id', classes, kv)) =
282+ pushViaConstructor lua "Attributes" kv id' classes
283+ peek lua idx = fmap LuaAttr <$> peek lua idx
284+ valuetype _ = TTABLE