diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2021-01-01 10:50:58 +0100 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2021-01-01 11:18:36 +0100 |
commit | 17e3efc785fa8b0680ec6d4ebaac1ea6bdb57e1a (patch) | |
tree | 0f0fb6f2b55a7d0cb237804452ee3f14999a72c2 /src/Text/Pandoc/Readers | |
parent | 23f964b9076f9795b00e740d20feebeb1d6d91db (diff) | |
download | pandoc-17e3efc785fa8b0680ec6d4ebaac1ea6bdb57e1a.tar.gz |
Org reader: restructure output of captioned code blocks
The Div wrapper of code blocks with captions now has the class
"captioned-content". The caption itself is added as a Plain block
inside a Div of class "caption". This makes it easier to write filters
which match on captioned code blocks. Existing filters will need to be
updated.
Closes: #6977
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/Org/Blocks.hs | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs index f2e8b1ab6..17e3ff986 100644 --- a/src/Text/Pandoc/Readers/Org/Blocks.hs +++ b/src/Text/Pandoc/Readers/Org/Blocks.hs @@ -294,24 +294,22 @@ verseBlock blockType = try $ do codeBlock :: PandocMonad m => BlockAttributes -> Text -> OrgParser m (F Blocks) codeBlock blockAttrs blockType = do skipSpaces - (classes, kv) <- codeHeaderArgs <|> (mempty <$ ignHeaders) - content <- rawBlockContent blockType - resultsContent <- option mempty babelResultsBlock - let id' = fromMaybe mempty $ blockAttrName blockAttrs - let codeBlck = B.codeBlockWith ( id', classes, kv ) content - let labelledBlck = maybe (pure codeBlck) - (labelDiv codeBlck) - (blockAttrCaption blockAttrs) + (classes, kv) <- codeHeaderArgs <|> (mempty <$ ignHeaders) + content <- rawBlockContent blockType + resultsContent <- option mempty babelResultsBlock + let identifier = fromMaybe mempty $ blockAttrName blockAttrs + let codeBlk = B.codeBlockWith (identifier, classes, kv) content + let wrap = maybe pure addCaption (blockAttrCaption blockAttrs) return $ - (if exportsCode kv then labelledBlck else mempty) <> + (if exportsCode kv then wrap codeBlk else mempty) <> (if exportsResults kv then resultsContent else mempty) where - labelDiv :: Blocks -> F Inlines -> F Blocks - labelDiv blk value = - B.divWith nullAttr <$> (mappend <$> labelledBlock value <*> pure blk) + addCaption :: F Inlines -> Blocks -> F Blocks + addCaption caption blk = B.divWith ("", ["captioned-content"], []) + <$> (mkCaptionBlock caption <> pure blk) - labelledBlock :: F Inlines -> F Blocks - labelledBlock = fmap (B.plain . B.spanWith ("", ["label"], [])) + mkCaptionBlock :: F Inlines -> F Blocks + mkCaptionBlock = fmap (B.divWith ("", ["caption"], []) . B.plain) exportsResults :: [(Text, Text)] -> Bool exportsResults = maybe False (`elem` ["results", "both"]) . lookup "exports" |