Skip to content

Instantly share code, notes, and snippets.

@lierdakil
Created July 10, 2018 06:59
Show Gist options
  • Save lierdakil/c1bd46e057e886a6c39ef58d5b47e4e9 to your computer and use it in GitHub Desktop.
Save lierdakil/c1bd46e057e886a6c39ef58d5b47e4e9 to your computer and use it in GitHub Desktop.
Pandoc filter to replace internal links with page references
import Text.Pandoc.JSON
import Data.List
main :: IO ()
main = toJSONFilter myfilter
myfilter (Link _ text (url, _))
| '#':ref <- url
= Span nullAttr $
text <>
[ Space
, Str "(page"
, Space
, RawInline (Format "latex") ("\\pageref{" <> ref <> "}")
, Str ")"
]
myfilter x = x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment