From 7b28a1cdf2c0b5f431377f218720698e8dfdbb47 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 14 Sep 2022 10:40:41 +1000 Subject: Prepending level 1 heading --- src/Servall/Types.hs | 21 +++++++++++++++++---- src/Servall/WikiParser.hs | 13 +++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Servall/Types.hs b/src/Servall/Types.hs index 69c2045..794482c 100644 --- a/src/Servall/Types.hs +++ b/src/Servall/Types.hs @@ -1,8 +1,6 @@ +{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-} -module Servall.Types - ( WikiTemplate(..) - , Video(..) - ) where +module Servall.Types where import Data.Aeson ( (.:) , (.=) @@ -13,6 +11,7 @@ import Data.Aeson ( (.:) ) import qualified Data.HashMap.Lazy as HM import Data.Text ( Text ) +import GHC.Generics ( Generic ) data WikiTemplate = WikiTemplate { wtName :: Text @@ -48,3 +47,17 @@ instance ToJSON Video where , "description" .= desc , "duration" .= duration ] + + +data WikiSummary = WikiSummary + { wsTitle :: Text + , wsWikbase :: Text + , wsPageId :: Int + } + deriving (Show, Eq, Generic) + +instance FromJSON WikiSummary where + parseJSON (Object o) = + WikiSummary <$> o .: "title" <*> o .: "wikibase_item" <*> o .: "pageid" + +instance ToJSON WikiSummary diff --git a/src/Servall/WikiParser.hs b/src/Servall/WikiParser.hs index 2680fad..e284a3b 100644 --- a/src/Servall/WikiParser.hs +++ b/src/Servall/WikiParser.hs @@ -32,8 +32,9 @@ import qualified Data.Text as T import Data.Text ( Text ) import GHC.Generics ( Generic ) import Servall.Types -import Text.Pandoc.Definition ( Inline(..) - , Pandoc +import Text.Pandoc.Definition ( Block(..) + , Inline(..) + , Pandoc(..) ) import Text.Pandoc.Generic ( topDown ) @@ -109,8 +110,12 @@ wikilinkP = do content <- T.pack <$> manyTill anyChar (string "]]") return $ beg <> content <> "]]" -wikiFilter :: Pandoc -> Pandoc -wikiFilter = topDown fixUrl +wikiFilter :: Text -> Pandoc -> Pandoc +wikiFilter title = insertHeader title . topDown fixUrl + +insertHeader :: Text -> Pandoc -> Pandoc +insertHeader title (Pandoc m bs) = + Pandoc m (Header 1 ("", [], []) [Str title] : bs) fixUrl :: Inline -> Inline fixUrl (Link attr label (url, "wikilink")) = -- cgit v1.2.3