Skip to content

Commit

Permalink
Add ability to remove caption from PDF output
Browse files Browse the repository at this point in the history
See LaurentRDC#37.

For whatever reason, the change introduced in the PR related to the
issue above seems to not have an effect any more. Bring that change
back. Seems we might have problems with pandoc-crossref and other
filters because of which the change was dropped but right now this
is the only filter we care about.
  • Loading branch information
SanchayanMaity committed Aug 15, 2023
1 parent 825c633 commit 44f678d
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/Text/Pandoc/Filter/Plot/Embed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ import Text.HTML.TagSoup
import Text.Pandoc.Builder as Builder
( Inlines,
fromList,
figureWith,
imageWith,
plain,
para,
link,
str,
simpleCaption,
toList,
)
)
import Text.Pandoc.Class (runPure)
import Text.Pandoc.Definition (Attr, Block (..), Format, Pandoc (..))
import Text.Pandoc.Error (handleError)
Expand Down Expand Up @@ -81,10 +79,10 @@ figure ::
Inlines ->
PlotM Block
figure as fp caption' =
return . head . toList $
-- We want the attributes both on the Figure element and the contained Image element
-- so that pandoc-plot plays nice with pandoc-crossref and other filters
figureWith as (simpleCaption (plain caption')) $ plain $ imageWith mempty (pack fp) mempty caption'
return . head . toList . para $
imageWith as (pack fp) title caption'
where
title = if caption' /= mempty then "fig:" else mempty

-- TODO: also add the case where SVG plots can be
-- embedded in HTML output
Expand Down Expand Up @@ -173,7 +171,7 @@ extractPlot t =
let tags = canonicalizeTags $ parseTagsOptions parseOptionsFast t
extracted = headScripts tags <> [inside "body" tags]
-- In the past (e.g. commit 8417b011ccb20263427822c7447840ab4a30a41e), we used to
-- make all JS scripts 'deferred'. This turned out to be problematic for plotly
-- make all JS scripts 'deferred'. This turned out to be problematic for plotly
-- specifically (see issue #39). In the future, we may want to defer scripts for
-- certain toolkits, but that's a testing nightmare...
in mconcat $ renderTags <$> extracted
Expand All @@ -185,4 +183,4 @@ extractPlot t =
inside :: Text -> [Tag Text] -> [Tag Text]
inside t = init . tail . tgs
where
tgs = takeWhile (~/= TagClose t) . dropWhile (~/= TagOpen t [])
tgs = takeWhile (~/= TagClose t) . dropWhile (~/= TagOpen t [])

0 comments on commit 44f678d

Please sign in to comment.