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 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'app') 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 -- cgit v1.2.3