From 07284b39f90bd85d19d12e0880c1e2f215d1eb0c Mon Sep 17 00:00:00 2001 From: Daniel Gnoutcheff Date: Mon, 20 Sep 2021 13:28:01 -0400 Subject: Accomodate IkiWiki's inline plugin --- app/Main.hs | 19 +++++++++++++++++-- fast-pandoc.cabal | 1 + package.yaml | 1 + 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 +--
+-- 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 ["
"] +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 -- cgit v1.2.3