Forked from mpickering/gist:f1718fcdc4c56273ed52
Last active
August 29, 2015 14:13
-
-
Save ranjitjhala/171aa922204aa84c7b3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ViewPatterns #-} | |
module InTex where | |
import Text.Pandoc.JSON | |
import Text.Pandoc | |
import Data.List | |
main :: IO () | |
main = toJSONFilter readFootnotes | |
readFootnotes :: Inline -> Inline | |
readFootnotes (footnoteText -> Just args) = RawInline (Format "tex") res | |
where | |
parsed = writeLaTeX def . readMarkdown def | |
res = fnString ++ parsed args ++ "}" | |
readFootnotes (Span (_,["footnotetext"],_) is) = RawInline (Format "tex") tex | |
where | |
tex = fnString ++ writeLaTeX def para ++ "}" | |
para = Pandoc mempty [Para is] | |
readFootnotes i = i | |
fnString = "\\footnotetext{" | |
footnoteText :: Inline -> Maybe String | |
footnoteText (RawInline (Format "tex") s) = | |
if fnString `isPrefixOf` s | |
then Just . init . drop (length fnString) $ s -- Remove closing brace | |
else Nothing | |
footnoteText x = Nothing | |
------ | |
{- Now: | |
<span class="footnotetext">arbitrary-pandoc-markdown</span> | |
will get transformed nicely to: | |
\footnotetext{arbitrary-pandoc-markdown-transformed-to-latex} | |
-} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment