From d4f3629e4eb1a5a8d0dbb82ed4e8087faf6f2a58 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 15 Sep 2022 18:21:04 +1000 Subject: [server] reuse infobox function and separate out main --- src/Servall/WikiParser.hs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Servall/WikiParser.hs b/src/Servall/WikiParser.hs index b5188a4..7053197 100644 --- a/src/Servall/WikiParser.hs +++ b/src/Servall/WikiParser.hs @@ -206,21 +206,27 @@ fixHeaderTemplates (Pandoc m blocks) = Pandoc m (go [] blocks) where go acc (Header level (x, y, attr) content : bs) = let (raws, rest) = span isTemplateBlock bs in go - (acc ++ [Header level (x, y, attr ++ concatMap infobox' raws) content] + ( acc + ++ [ Header + level + ( x + , y + , attr ++ infobox (T.concat (map templateFromRawBlock raws)) + ) + content + ] ) rest go acc (b : bs) = go (acc ++ [b]) bs - infobox' :: Block -> [(Text, Text)] - infobox' (RawBlock (Format "mediawiki") temp) = - fromRight [] - $ (\wt -> if isInfobox wt then filterNameValues (wtArgs wt) else []) - <$> parseOnly templateP temp - infobox' _ = [] isTemplateBlock :: Block -> Bool isTemplateBlock (RawBlock (Format "mediawiki") temp) = True isTemplateBlock _ = False +templateFromRawBlock :: Block -> Text +templateFromRawBlock (RawBlock (Format "mediawiki") temp) = temp +templateFromRawBlock _ = "" + fixInline :: Inline -> Inline fixInline (Link attr label (url, "wikilink")) = Link attr label ("wiki:" <> url, "") -- cgit v1.2.3