summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Filter
diff options
context:
space:
mode:
authorLaurentRDC <>2018-10-14 15:41:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2018-10-14 15:41:00 (GMT)
commite93f276493d200a4e1cc102504eb7e42e5ca2f42 (patch)
tree5e4063efd5db44620605e8db3cc709d4f2fb8871 /src/Text/Pandoc/Filter
parent5b5d90b1b074de620d776d5bcb58348b1af297cd (diff)
version 1.0.2.01.0.2.0
Diffstat (limited to 'src/Text/Pandoc/Filter')
-rw-r--r--src/Text/Pandoc/Filter/Pyplot.hs23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Filter/Pyplot.hs b/src/Text/Pandoc/Filter/Pyplot.hs
index dc2667f..1aa5c31 100644
--- a/src/Text/Pandoc/Filter/Pyplot.hs
+++ b/src/Text/Pandoc/Filter/Pyplot.hs
@@ -42,7 +42,6 @@ data PandocPyplotError = ScriptError Int -- ^ Running Python scri
data FigureSpec = FigureSpec
{ target :: FilePath -- ^ filepath where generated figure will be saved
, alt :: String -- ^ Alternate text for the figure (optional)
- , caption :: String -- ^ Figure caption (optional)
, script :: PythonScript -- ^ Source code for the figure
, blockAttrs :: Attr -- ^ Attributes not related to @pandoc-pyplot@ will be propagated
}
@@ -61,10 +60,9 @@ presentableScript :: FigureSpec -> PythonScript
presentableScript spec = mconcat [ "# Source code for ", target spec, "\n", script spec ]
-- Keys that pandoc-pyplot will look for in code blocks
-targetKey, altTextKey, captionKey :: String
+targetKey, altTextKey :: String
targetKey = "plot_target"
altTextKey = "plot_alt"
-captionKey = "plot_caption"
-- | Determine inclusion specifications from Block attributes.
-- Note that the target key is required, but all other parameters are optional
@@ -73,12 +71,11 @@ parseFigureSpec (CodeBlock (id', cls, attrs) content) =
createInclusion <$> M.lookup targetKey attrs'
where
attrs' = M.fromList attrs
- inclusionKeys = [ targetKey, altTextKey, captionKey ]
+ inclusionKeys = [ targetKey, altTextKey ]
filteredAttrs = filter (\(k,_) -> k `notElem` inclusionKeys) attrs
createInclusion fname = FigureSpec
{ target = fname
, alt = M.findWithDefault "Figure generated by pandoc-pyplot" altTextKey attrs'
- , caption = M.findWithDefault mempty captionKey attrs'
, script = content
-- Propagate attributes that are not related to pandoc-pyplot
, blockAttrs = (id', cls, filteredAttrs)
@@ -125,14 +122,14 @@ makePlot' block =
-- Propagate attributes that are not related to pandoc-pyplot
let relevantAttrs = blockAttrs spec
- image = Image relevantAttrs [Str $ alt spec] (figurePath, "")
- srcTarget = (sourcePath, "Click on this figure to see the source code")
-
- -- TODO: use FigureSpec caption
- -- We make the figure be a link to the source code
- return $ Right $ Para [
- Link nullAttr [image] srcTarget
- ]
+ srcTarget = Link nullAttr [Str "Source code"] (sourcePath, "")
+ caption' = [Str $ alt spec, Space, Str "(", srcTarget, Str ")"]
+ -- To render images as figures with captions, the target title
+ -- must be "fig:"
+ -- Janky? yes
+ image = Image relevantAttrs caption' (figurePath, "fig:")
+
+ return $ Right $ Para $ [image]
-- | Translate filter error to an error message
showError :: PandocPyplotError -> String