git.iko.soy/typeable/pandoc
on master help sign in
Org reader: restructure output of captioned code blocks
17e3efcAlbert Krewinkel
src/Text/Pandoc/Readers/Org/Blocks.hs+12−14
@@ -294,24 +294,22 @@ verseBlock blockType = try $ do
294codeBlock :: PandocMonad m => BlockAttributes -> Text -> OrgParser m (F Blocks)
294codeBlock :: PandocMonad m => BlockAttributes -> Text -> OrgParser m (F Blocks)
295codeBlock blockAttrs blockType = do
295codeBlock blockAttrs blockType = do
296 skipSpaces
296 skipSpaces
297− (classes, kv) <- codeHeaderArgs <|> (mempty <$ ignHeaders)
297+ (classes, kv) <- codeHeaderArgs <|> (mempty <$ ignHeaders)
298− content <- rawBlockContent blockType
298+ content <- rawBlockContent blockType
299− resultsContent <- option mempty babelResultsBlock
299+ resultsContent <- option mempty babelResultsBlock
300− let id' = fromMaybe mempty $ blockAttrName blockAttrs
300+ let identifier = fromMaybe mempty $ blockAttrName blockAttrs
301− let codeBlck = B.codeBlockWith ( id', classes, kv ) content
301+ let codeBlk = B.codeBlockWith (identifier, classes, kv) content
302− let labelledBlck = maybe (pure codeBlck)
303− (labelDiv codeBlck)
304− (blockAttrCaption blockAttrs)
302+ let wrap = maybe pure addCaption (blockAttrCaption blockAttrs)
305 return $
303 return $
306− (if exportsCode kv then labelledBlck else mempty) <>
304+ (if exportsCode kv then wrap codeBlk else mempty) <>
307 (if exportsResults kv then resultsContent else mempty)
305 (if exportsResults kv then resultsContent else mempty)
308 where
306 where
309− labelDiv :: Blocks -> F Inlines -> F Blocks
307+ addCaption :: F Inlines -> Blocks -> F Blocks
310− labelDiv blk value =
308+ addCaption caption blk = B.divWith ("", ["captioned-content"], [])
311− B.divWith nullAttr <$> (mappend <$> labelledBlock value <*> pure blk)
309+ <$> (mkCaptionBlock caption <> pure blk)
312
310
313− labelledBlock :: F Inlines -> F Blocks
311+ mkCaptionBlock :: F Inlines -> F Blocks
314− labelledBlock = fmap (B.plain . B.spanWith ("", ["label"], []))
312+ mkCaptionBlock = fmap (B.divWith ("", ["caption"], []) . B.plain)
315
313
316 exportsResults :: [(Text, Text)] -> Bool
314 exportsResults :: [(Text, Text)] -> Bool
317 exportsResults = maybe False (`elem` ["results", "both"]) . lookup "exports"
315 exportsResults = maybe False (`elem` ["results", "both"]) . lookup "exports"
test/Tests/Readers/Org/Block/CodeBlock.hs+3−3
@@ -185,10 +185,10 @@ tests =
185 , "#+end_src"
185 , "#+end_src"
186 ] =?>
186 ] =?>
187 divWith
187 divWith
188− nullAttr
188+ ("", ["captioned-content"], [] )
189 (mappend
189 (mappend
190− (plain $ spanWith ("", ["label"], [])
190+ (divWith ("", ["caption"], []) $
191− (spcSep [ "Functor", "laws", "in", "Haskell" ]))
191+ plain (spcSep [ "Functor", "laws", "in", "Haskell" ]))
192 (codeBlockWith ("functor-laws", ["haskell"], [])
192 (codeBlockWith ("functor-laws", ["haskell"], [])
193 (T.unlines [ "fmap id = id"
193 (T.unlines [ "fmap id = id"
194 , "fmap (p . q) = (fmap p) . (fmap q)"
194 , "fmap (p . q) = (fmap p) . (fmap q)"