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 Oct 3, 2024
1 parent 215dbaf commit b9b8c0b
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/Text/Pandoc/Filter/Plot/Embed.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import Text.HTML.TagSoup
)
import Text.Pandoc.Builder as Builder

Check warning on line 32 in src/Text/Pandoc/Filter/Plot/Embed.hs

View workflow job for this annotation

GitHub Actions / build-and-test (windows-latest, 9.8.2)

The import of ‘plain, simpleCaption’

Check warning on line 32 in src/Text/Pandoc/Filter/Plot/Embed.hs

View workflow job for this annotation

GitHub Actions / build-and-test (ubuntu-latest, 9.8.2)

The import of ‘plain, simpleCaption’

Check warning on line 32 in src/Text/Pandoc/Filter/Plot/Embed.hs

View workflow job for this annotation

GitHub Actions / build-and-test (macos-latest, 9.8.2)

The import of ‘plain, simpleCaption’
( Inlines,
figureWith,
fromList,
imageWith,
para,
link,
plain,
simpleCaption,
Expand Down Expand Up @@ -88,16 +88,10 @@ figure ::
Inlines ->
PlotM Block
figure as fp caption' =
return . head . toList $
if null caption'
-- If there is no caption, a LaTeX figure may look strange. See #37
then plain $ imageWith as (pack fp) mempty caption'
else
-- 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 as (pack fp) mempty caption'
return . head . toList . para $

Check warning on line 91 in src/Text/Pandoc/Filter/Plot/Embed.hs

View workflow job for this annotation

GitHub Actions / build-and-test (windows-latest, 9.8.2)

In the use of ‘head’

Check warning on line 91 in src/Text/Pandoc/Filter/Plot/Embed.hs

View workflow job for this annotation

GitHub Actions / build-and-test (ubuntu-latest, 9.8.2)

In the use of ‘head’

Check warning on line 91 in src/Text/Pandoc/Filter/Plot/Embed.hs

View workflow job for this annotation

GitHub Actions / build-and-test (macos-latest, 9.8.2)

In the use of ‘head’
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 @@ -188,11 +182,11 @@ extractPlot :: Text -> Text
extractPlot t =
let tags = canonicalizeTags $ parseTagsOptions parseOptionsFast t
extracted = headScripts tags <> [inside "body" tags]
in -- In the past (e.g. commit 8417b011ccb20263427822c7447840ab4a30a41e), we used to
-- In the past (e.g. commit 8417b011ccb20263427822c7447840ab4a30a41e), we used to
-- 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...
mconcat $ renderTags <$> extracted
in mconcat $ renderTags <$> extracted
where
headScripts = partitions (~== ("<script>" :: String)) . inside "head"

Expand Down

0 comments on commit b9b8c0b

Please sign in to comment.