Skip to content

Instantly share code, notes, and snippets.

@balachia
Created September 16, 2014 03:16
Show Gist options
  • Save balachia/d836f8829aec61cb4b54 to your computer and use it in GitHub Desktop.
Save balachia/d836f8829aec61cb4b54 to your computer and use it in GitHub Desktop.
Pandoc filter that cleans up internal references to figures and tables.
{-
Pandoc filter that cleans up internal references to figures and tables.
It's an attempt to deal with: https://github.com/jgm/pandoc/issues/813
Compile with:
ghc --make pandoc-internalref.hs
and use in pandoc with
--filter [PATH]/pandoc-internalref
-}
module Main where
import Text.Pandoc.JSON
import Data.List
main = toJSONFilter makeref
makeref :: Inline -> [Inline]
makeref (Link txt ('#':ident, x))
| Just subident <- stripPrefix "fig:" ident = reflink
| Just subident <- stripPrefix "tab:" ident = reflink
where reflink = [Link [RawInline (Format "latex") ("\\ref*{" ++ ident ++ "}")] ("#" ++ ident, x)]
makeref x = [x]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment