summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gnoutcheff <gnoutchd@softwarefreedom.org>2021-09-20 13:28:01 -0400
committerDaniel Gnoutcheff <gnoutchd@softwarefreedom.org>2021-09-21 19:33:22 -0400
commit07284b39f90bd85d19d12e0880c1e2f215d1eb0c (patch)
treef65a44c978a55eabe8d08596677506fc608ee3d7
parent229141a7001de5ca110b79e0f2bc161ab14bfced (diff)
Accomodate IkiWiki's inline plugin
-rw-r--r--app/Main.hs19
-rw-r--r--fast-pandoc.cabal1
-rw-r--r--package.yaml1
3 files changed, 19 insertions, 2 deletions
diff --git a/app/Main.hs b/app/Main.hs
index cb924e5..ae8bece 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -1,4 +1,5 @@
{-# OPTIONS_GHC -fno-full-laziness #-}
+{-# LANGUAGE OverloadedStrings #-}
-- Pandoc Markdown rendering for IkiWiki, implemented as a "external" (XML-RPC)
-- plugin.
@@ -26,6 +27,8 @@ import Text.XML.HaXml.Escape (xmlUnEscape, stdXmlEscaper)
import qualified Text.Pandoc as P
import qualified Network.XmlRpc.Internals as XRI
import qualified Text.Pandoc.Shared as PS
+import qualified Text.Pandoc.Definition as PD
+import qualified Text.Pandoc.Walk as PW
-- Modified version of XMLParse.document that doesn't wait for anything after
-- the top-level element
@@ -100,6 +103,18 @@ rpcHtmlize args = XRI.renderResponse . XRI.Return . XRI.ValueString .
-- leaks memory like crazy.
htmlize :: String -> String
htmlize mdwn = either (error . show) T.unpack . P.runPure .
- (P.writeHtml5String P.def =<<) . P.readMarkdown readOpts . PS.tabFilter 4 .
- T.pack . filter (\c -> c `elem` "\t\n\r" || (c>=' ' && c/='\x7f')) $ mdwn
+ (P.writeHtml5String P.def . PW.walk preserveIkiInline =<<) .
+ P.readMarkdown readOpts . PS.tabFilter 4 . T.pack .
+ filter (\c -> c `elem` ("\t\n\r" :: String) || (c>=' ' && c/='\x7f')) $ mdwn
where readOpts = P.def {P.readerExtensions = P.pandocExtensions}
+
+-- Lines of the form
+-- <div class="inline" id="some_string"></div>
+-- are placeholders inserted and expanded by IkiWiki's `inline` plugin. They
+-- must be preserved exactly, character-for-character, or else IkiWiki's regex
+-- won't match. Pandoc normally parses these as Div blocks, which won't do.
+preserveIkiInline :: PD.Block -> PD.Block
+preserveIkiInline (PD.Div (inlineId, ["inline"], []) []) =
+ PD.RawBlock (PD.Format "html") $
+ T.concat ["<div class=\"inline\" id=\"", inlineId, "\"></div>"]
+preserveIkiInline b = b
diff --git a/fast-pandoc.cabal b/fast-pandoc.cabal
index 44959f9..a0fb105 100644
--- a/fast-pandoc.cabal
+++ b/fast-pandoc.cabal
@@ -33,6 +33,7 @@ executable fast-pandoc
, haxr
, mtl
, pandoc
+ , pandoc-types
, polyparse
, split
, text
diff --git a/package.yaml b/package.yaml
index 64e09d2..9c94637 100644
--- a/package.yaml
+++ b/package.yaml
@@ -25,6 +25,7 @@ dependencies:
- bytestring
- text
- pandoc
+- pandoc-types
- haxr
- HaXml
- polyparse