X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=Rakka%2FWiki%2FEngine.hs;h=02e987cd20f7ed92c6eb7521f3cd2d2e877c6f3f;hb=42f51754dea02201aececaacbf194d714cd58aaf;hp=2b751d4a47db96bc49bc23e0ef02f0d54e2d2427;hpb=8f77b5949ccd5f2272a02c852d51bfa2ecfa84c8;p=Rakka.git
diff --git a/Rakka/Wiki/Engine.hs b/Rakka/Wiki/Engine.hs
index 2b751d4..02e987c 100644
--- a/Rakka/Wiki/Engine.hs
+++ b/Rakka/Wiki/Engine.hs
@@ -1,134 +1,444 @@
+{-# LANGUAGE
+ Arrows
+ , OverloadedStrings
+ , ScopedTypeVariables
+ , TypeOperators
+ , UnicodeSyntax
+ #-}
module Rakka.Wiki.Engine
- ( formatPage
- , formatSubPage
+ ( InterpTable
+ , makeMainXHTML
+ , makeSubXHTML
+ , makePreviewXHTML
+ , makePageLinkList
+ , makeDraft
)
where
-
-import Control.Arrow
-import Control.Arrow.ArrowIO
-import Data.Encoding
-import Data.Encoding.UTF8
-import Data.Generics
+import Control.Applicative
+import Control.Arrow
+import Control.Arrow.ArrowIO
+import Control.Arrow.ArrowList
+import Control.Arrow.Unicode
+import Control.Monad.Unicode
+import qualified Codec.Binary.UTF8.String as UTF8
+import qualified Data.ByteString.Lazy as Lazy
+import qualified Data.ByteString.Lazy.Char8 as L8 hiding (ByteString)
+import Data.Map (Map)
import qualified Data.Map as M
+import Data.Maybe
+import Data.Monoid.Unicode
+import Data.Text (Text)
+import qualified Data.Text as T
import Network.HTTP.Lucu
-import Rakka.Environment
+import Network.URI
+import OpenSSL.EVP.Base64
+import Prelude.Unicode
import Rakka.Page
+import Rakka.Storage
import Rakka.SystemConfig
+import Rakka.Utils
import Rakka.Wiki
import Rakka.Wiki.Parser
import Rakka.Wiki.Formatter
import Rakka.Wiki.Interpreter
+import Text.HyperEstraier hiding (getText)
import Text.ParserCombinators.Parsec
-import Text.XML.HXT.Arrow.XmlArrow
-import Text.XML.HXT.DOM.TypeDefs
-
-
-formatPage :: (ArrowXml a, ArrowChoice a, ArrowIO a) =>
- Environment
- -> a Page XmlTree
-formatPage env
- = proc page
- -> do BaseURI baseURI <- getSysConfA (envSysConf env) (BaseURI undefined) -< ()
- wiki <- wikifyPage env -< page
- xs <- interpretCommandsA env -< (pageName page, (Just wiki, wiki))
- formatWikiBlocks -< (baseURI, xs)
-
-
-formatSubPage :: (ArrowXml a, ArrowChoice a, ArrowIO a) =>
- Environment
- -> a (PageName, (Maybe Page, Page)) XmlTree
-formatSubPage env
- = proc (mainPageName, (mainPage, subPage))
- -> do BaseURI baseURI <- getSysConfA (envSysConf env) (BaseURI undefined) -< ()
+import Text.XML.HXT.Arrow.XmlArrow hiding (err)
+import Text.XML.HXT.DOM.TypeDefs
+import Text.XML.HXT.XPath
+
+type InterpTable = Map Text Interpreter
+
+wikifyPage â· (ArrowXml (â), ArrowChoice (â)) â InterpTable â XmlTree â WikiPage
+wikifyPage interpTable
+ = proc tree
+ â do pType â getXPathTreesInDoc "/page/@type/text()" â getText â arr read ⤠tree
+ textData â maybeA (getXPathTreesInDoc "/page/textData/text()" â getText) ⤠tree
+ base64Data â maybeA (getXPathTreesInDoc "/page/binaryData/text()" â getText) ⤠tree
+
+ let dataURI = binToURI pType <$> base64Data
+
+ case pType of
+ MIMEType "text" "x-rakka" _
+ â case parse (wikiPage $ cmdTypeOf interpTable) "" (fromJust textData) of
+ Left err â wikifyParseError ⤠err
+ Right xs â returnA ⤠xs
+
+ MIMEType "image" _ _
+ --
+ â returnA ⤠[ Paragraph [Image (Left $ fromJust dataURI) Nothing] ]
+
+ _ â if isJust dataURI then
+ --
+ -- application/zip
+ --
+ returnA ⤠[ Paragraph [ Anchor
+ [("href", T.pack $ show dataURI)]
+ [Text (T.pack $ show pType)]
+ ]
+ ]
+ else
+ -- pre
+ returnA ⤠[ Preformatted [Text â T.pack $ fromJust textData] ]
+ where
+ binToURI :: MIMEType -> String -> URI
+ binToURI pType base64Data
+ = nullURI {
+ uriScheme = "data:"
+ , uriPath = show pType ++ ";base64," ++ (stripWhiteSpace base64Data)
+ }
+
+ stripWhiteSpace :: String -> String
+ stripWhiteSpace [] = []
+ stripWhiteSpace (x:xs)
+ | x `elem` " \t\n" = stripWhiteSpace xs
+ | otherwise = x : stripWhiteSpace xs
+
+
+wikifyBin :: (ArrowXml (â), ArrowChoice (â)) â InterpTable â (MIMEType, Lazy.ByteString) â WikiPage
+wikifyBin interpTable
+ = proc (pType, pBin)
+ â do let text = UTF8.decode $ Lazy.unpack pBin
+ dataURI = binToURI pType pBin
+
+ case pType of
+ MIMEType "text" "x-rakka" _
+ -> case parse (wikiPage $ cmdTypeOf interpTable) "" text of
+ Left err -> wikifyParseError -< err
+ Right xs -> returnA -< xs
+
+ MIMEType "image" _ _
+ --
+ -> returnA -< [ Paragraph [Image (Left dataURI) Nothing] ]
+
+ _ --
+ -- application/zip (19372 bytes)
+ --
+ -> returnA -< [ Paragraph [ Anchor
+ [("href", T.pack $ show dataURI)]
+ [Text (T.concat [ T.pack $ show pType
+ , "("
+ , T.pack â show $ Lazy.length pBin
+ , " bytes)"
+ ])]
+ ]
+ ]
+ where
+ binToURI :: MIMEType -> Lazy.ByteString -> URI
+ binToURI m b
+ = nullURI {
+ uriScheme = "data:"
+ , uriPath = show m ++ ";base64," ++ (L8.unpack $ encodeBase64LBS b)
+ }
+
+cmdTypeOf â· Alternative f â InterpTable â Text â f CommandType
+cmdTypeOf interpTable name
+ = case M.lookup name interpTable of
+ Just t â pure $ commandType t
+ Nothing â empty
+
+makeMainXHTML â· (ArrowXml (â), ArrowChoice (â), ArrowIO (â))
+ â Storage
+ â SystemConfig
+ â InterpTable
+ â XmlTree â XmlTree
+makeMainXHTML sto sysConf interpTable
+ = proc tree
+ â do BaseURI baseURI â getSysConfA sysConf ⤠()
+ wiki â wikifyPage interpTable ⤠tree
+ pName â getXPathTreesInDoc "/page/@name/text()" â getText ⤠tree
+ interpreted â interpretCommands sto sysConf interpTable
+ ⤠(Just (T.pack pName), Just tree, Just wiki, wiki)
+ formatWikiBlocks ⤠(baseURI, interpreted)
+
+
+makeSubXHTML :: (ArrowXml a, ArrowChoice a, ArrowIO a) =>
+ Storage
+ -> SystemConfig
+ -> InterpTable
+ -> a (Maybe PageName, Maybe XmlTree, XmlTree) XmlTree
+makeSubXHTML sto sysConf interpTable
+ = proc (mainPageName, mainPage, subPage)
+ -> do BaseURI baseURI <- getSysConfA sysConf -< ()
mainWiki <- case mainPage of
Just page
- -> do wiki <- wikifyPage env -< page
- returnA -< Just wiki
+ -> do wiki <- wikifyPage interpTable -< page
+ returnA -< Just (page, wiki)
Nothing
-> returnA -< Nothing
- subWiki <- wikifyPage env -< subPage
- xs <- interpretCommandsA env -< (mainPageName, (mainWiki, subWiki))
- formatWikiBlocks -< (baseURI, xs)
-
-
-wikifyPage :: (ArrowXml a, ArrowChoice a, ArrowIO a) =>
- Environment
- -> a Page WikiPage
-wikifyPage env
- = proc page
- -> case pageType page of
- MIMEType "text" "x-rakka" _
- -> do let source = decodeLazy UTF8 (pageContent page)
- parser = wikiPage tableToFunc
-
- case parse parser "" source of
- Left err
- -> wikifyParseError -< err
-
- Right xs
- -> returnA -< xs
- where
- tableToFunc :: String -> Maybe CommandType
- tableToFunc name
- = fmap commandType (M.lookup name (envInterpTable env))
+ subWiki <- wikifyPage interpTable -< subPage
+ interpreted <- interpretCommands sto sysConf interpTable
+ -< (mainPageName, fmap fst mainWiki, fmap snd mainWiki, subWiki)
+ formatWikiBlocks -< (baseURI, interpreted)
-interpretCommandsA :: ArrowIO a =>
- Environment
- -> a (PageName, (Maybe WikiPage, WikiPage)) WikiPage
-interpretCommandsA = arrIO3 . interpretCommands
+makePreviewXHTML :: (ArrowXml a, ArrowChoice a, ArrowIO a) =>
+ Storage
+ -> SystemConfig
+ -> InterpTable
+ -> a (PageName, MIMEType, Lazy.ByteString) XmlTree
+makePreviewXHTML sto sysConf interpTable
+ = proc (name, pageType, pageBin)
+ -> do BaseURI baseURI <- getSysConfA sysConf -< ()
+ wiki <- wikifyBin interpTable -< (pageType, pageBin)
+ interpreted <- interpretCommands sto sysConf interpTable
+ -< (Just name, Nothing, Just wiki, wiki)
+ formatWikiBlocks -< (baseURI, interpreted)
-interpretCommands :: Environment -> PageName -> Maybe WikiPage -> WikiPage -> IO WikiPage
-interpretCommands _ _ _ [] = return []
-interpretCommands env name mainTree targetTree
- = everywhereM' (mkM interpBlockCmd) targetTree
- >>=
- everywhereM' (mkM interpInlineCmd)
+interpretCommands :: (ArrowXml a, ArrowChoice a, ArrowIO a) =>
+ Storage
+ -> SystemConfig
+ -> InterpTable
+ -> a (Maybe PageName, Maybe XmlTree, Maybe WikiPage, WikiPage) WikiPage
+interpretCommands sto sysConf interpTable
+ = proc (name, mainPage, mainWiki, targetWiki)
+ -> let ctx = InterpreterContext {
+ ctxPageName = name
+ , ctxMainPage = mainPage
+ , ctxMainWiki = mainWiki
+ , ctxTargetWiki = targetWiki
+ , ctxStorage = sto
+ , ctxSysConf = sysConf
+ }
+ in
+ arrIO2 (mapM . interpBlock) -< (ctx, targetWiki)
where
- ctx :: InterpreterContext
- ctx = InterpreterContext {
- ctxPageName = name
- , ctxMainTree = mainTree
- , ctxTargetTree = targetTree
- , ctxStorage = envStorage env
- , ctxSysConf = envSysConf env
- }
+ interpElem :: InterpreterContext -> Element -> IO Element
+ interpElem ctx (Block b) = interpBlock ctx b >>= return . Block
+ interpElem ctx (Inline i) = interpInline ctx i >>= return . Inline
- interpBlockCmd :: BlockElement -> IO BlockElement
- interpBlockCmd (BlockCmd cmd) = interpBlockCmd' cmd
- interpBlockCmd others = return others
+ interpBlock :: InterpreterContext -> BlockElement -> IO BlockElement
+ interpBlock ctx (List lType lItems) = mapM (interpListItem ctx) lItems >>= return . List lType
+ interpBlock ctx (DefinitionList defs) = mapM (interpDefinition ctx) defs >>= return . DefinitionList
+ interpBlock ctx (Preformatted inlines) = mapM (interpInline ctx) inlines >>= return . Preformatted
+ interpBlock ctx (Paragraph inlines) = mapM (interpInline ctx) inlines >>= return . Paragraph
+ interpBlock ctx (Div attrs elems) = mapM (interpElem ctx) elems >>= return . Div attrs
+ interpBlock ctx (BlockCmd bcmd) = interpBlockCommand ctx bcmd
+ interpBlock _ x = return x
- interpBlockCmd' :: BlockCommand -> IO BlockElement
- interpBlockCmd' cmd
- = case M.lookup (bCmdName cmd) (envInterpTable env) of
- Nothing
- -> fail ("no such interpreter: " ++ bCmdName cmd)
+ interpInline :: InterpreterContext -> InlineElement -> IO InlineElement
+ interpInline ctx (Italic inlines) = mapM (interpInline ctx) inlines >>= return . Italic
+ interpInline ctx (Bold inlines) = mapM (interpInline ctx) inlines >>= return . Bold
+ interpInline ctx (Span attrs inlines) = mapM (interpInline ctx) inlines >>= return . Span attrs
+ interpInline ctx (Anchor attrs inlines) = mapM (interpInline ctx) inlines >>= return . Anchor attrs
+ interpInline ctx (InlineCmd icmd) = interpInlineCommand ctx icmd
+ interpInline _ x = return x
- Just interp
- -> bciInterpret interp ctx cmd
+ interpListItem :: InterpreterContext -> ListItem -> IO ListItem
+ interpListItem = mapM . interpElem
+ interpDefinition :: InterpreterContext -> Definition -> IO Definition
+ interpDefinition ctx (Definition term desc)
+ = do term' <- mapM (interpInline ctx) term
+ desc' <- mapM (interpInline ctx) desc
+ return (Definition term' desc')
- interpInlineCmd :: InlineElement -> IO InlineElement
- interpInlineCmd (InlineCmd cmd) = interpInlineCmd' cmd
- interpInlineCmd others = return others
+ interpBlockCommand â· InterpreterContext â BlockCommand â IO BlockElement
+ interpBlockCommand ctx cmd
+ = case M.lookup (bCmdName cmd) interpTable of
+ Nothing
+ â fail ("no such interpreter: " â T.unpack (bCmdName cmd))
- interpInlineCmd' :: InlineCommand -> IO InlineElement
- interpInlineCmd' cmd
- = case M.lookup (iCmdName cmd) (envInterpTable env) of
+ Just interp
+ â bciInterpret interp ctx cmd
+ â«=
+ interpBlock ctx
+
+ interpInlineCommand â· InterpreterContext â InlineCommand â IO InlineElement
+ interpInlineCommand ctx cmd
+ = case M.lookup (iCmdName cmd) interpTable of
Nothing
- -> fail ("no such interpreter: " ++ iCmdName cmd)
+ â fail ("no such interpreter: " â T.unpack (iCmdName cmd))
Just interp
- -> iciInterpret interp ctx cmd
+ â iciInterpret interp ctx cmd â«= interpInline ctx
+
+makeDraft â· â(â). (ArrowXml (â), ArrowChoice (â), ArrowIO (â)) â InterpTable â XmlTree â Document
+makeDraft interpTable
+ = proc tree â
+ do redir â maybeA (getXPathTreesInDoc "/page/@redirect") ⤠tree
+ case redir of
+ Nothing â makeEntityDraft ⤠tree
+ Just _ â makeRedirectDraft ⤠tree
+ where
+ makeEntityDraft â· XmlTree â Document
+ makeEntityDraft
+ = proc tree â
+ do doc â arrIO0 newDocument ⤠()
+
+ pName â getXPathTreesInDoc "/page/@name/text()" â getText ⤠tree
+ pType â getXPathTreesInDoc "/page/@type/text()" â getText ⤠tree
+ pLastMod â getXPathTreesInDoc "/page/@lastModified/text()" â getText ⤠tree
+ pIsLocked â getXPathTreesInDoc "/page/@isLocked/text()" â getText ⤠tree
+ pIsBinary â getXPathTreesInDoc "/page/@isBinary/text()" â getText ⤠tree
+ pRevision â getXPathTreesInDoc "/page/@revision/text()" â getText ⤠tree
+ pLang â maybeA (getXPathTreesInDoc "/page/@lang/text()" â getText) ⤠tree
+ pIsTheme â maybeA (getXPathTreesInDoc "/page/@isTheme/text()" â getText) ⤠tree
+ pIsFeed â maybeA (getXPathTreesInDoc "/page/@isFeed/text()" â getText) ⤠tree
+ pSummary â maybeA (getXPathTreesInDoc "/page/summary/text()" â getText) ⤠tree
+
+ arrIO2 setURI ⤠(doc, Just â mkRakkaURI $ T.pack pName )
+ arrIO2 (flip setAttribute "@title" ) ⤠(doc, Just $ T.pack pName )
+ arrIO2 (flip setAttribute "@type" ) ⤠(doc, Just $ T.pack pType )
+ arrIO2 (flip setAttribute "@mdate" ) ⤠(doc, Just $ T.pack pLastMod )
+ arrIO2 (flip setAttribute "@lang" ) ⤠(doc, T.pack <$> pLang)
+ arrIO2 (flip setAttribute "rakka:isLocked") ⤠(doc, Just $ T.pack pIsLocked)
+ arrIO2 (flip setAttribute "rakka:isBinary") ⤠(doc, Just $ T.pack pIsBinary)
+ arrIO2 (flip setAttribute "rakka:revision") ⤠(doc, Just $ T.pack pRevision)
+ arrIO2 (flip setAttribute "rakka:summary" ) ⤠(doc, T.pack <$> pSummary)
+
+ arrIO2 addHiddenText ⤠(doc, T.pack pName)
+
+ case pSummary of
+ Just s â arrIO2 addHiddenText ⤠(doc, T.pack s)
+ Nothing â returnA ⤠()
+
+ -- otherLang ã¯ãªã³ã¯å
ãã¼ã¸åã hidden text ã§å
¥ããã
+ otherLangs â listA (getXPathTreesInDoc "/page/otherLang/link/@page/text()" â getText) ⤠tree
+ listA ( (arr fst &&& arrL snd)
+ â
+ arrIO2 addHiddenText
+ â
+ none
+ ) ⤠(doc, T.pack <$> otherLangs)
+
+ case read pType of
+ MIMEType "text" "css" _
+ â arrIO2 (flip setAttribute "rakka:isTheme") ⤠(doc, T.pack <$> pIsTheme)
+
+ MIMEType "text" "x-rakka" _
+ -- wikify ãã¦èå³ã®ããé¨åã addText ããã
+ â do arrIO2 (flip setAttribute "rakka:isFeed") ⤠(doc, T.pack <$> pIsFeed)
+ wiki â wikifyPage interpTable ⤠tree
+ arrIO2 (mapM_ â addBlockText) ⤠(doc, wiki)
+
+ MIMEType _ _ _
+ â returnA ⤠()
+
+ returnA ⤠doc
+
+ makeRedirectDraft â· XmlTree â Document
+ makeRedirectDraft
+ = proc tree â
+ do doc â arrIO0 newDocument ⤠()
+
+ pName â getXPathTreesInDoc "/page/@name/text()" â getText ⤠tree
+ pRedir â getXPathTreesInDoc "/page/@redirect/text()" â getText ⤠tree
+ pIsLocked â getXPathTreesInDoc "/page/@isLocked/text()" â getText ⤠tree
+ pRevision â getXPathTreesInDoc "/page/@revision/text()" â getText ⤠tree
+ pLastMod â getXPathTreesInDoc "/page/@lastModified/text()" â getText ⤠tree
+
+ arrIO2 setURI -< (doc, Just â mkRakkaURI $ T.pack pName )
+ arrIO2 (flip setAttribute "@title" ) -< (doc, Just $ T.pack pName )
+ arrIO2 (flip setAttribute "@type" ) -< (doc, Just "application/x-rakka-redirection")
+ arrIO2 (flip setAttribute "@mdate" ) -< (doc, Just $ T.pack pLastMod )
+ arrIO2 (flip setAttribute "rakka:isLocked") -< (doc, Just $ T.pack pIsLocked )
+ arrIO2 (flip setAttribute "rakka:revision") -< (doc, Just $ T.pack pRevision )
+
+ -- ãªãã¤ã¬ã¯ãå
ãã¼ã¸åã¯ããã¹ãã¨ãã¦å
¥ãã
+ arrIO2 addText ⤠(doc, T.pack pRedir)
+
+ returnA ⤠doc
+
+ addElemText :: Document -> Element -> IO ()
+ addElemText doc (Block b) = addBlockText doc b
+ addElemText doc (Inline i) = addInlineText doc i
+
+ addBlockText :: Document -> BlockElement -> IO ()
+ addBlockText doc (Heading _ text) = addText doc text
+ addBlockText _ HorizontalLine = return ()
+ addBlockText doc (List _ items) = mapM_ (addListItemText doc) items
+ addBlockText doc (DefinitionList defs) = mapM_ (addDefinitionText doc) defs
+ addBlockText doc (Preformatted inlines) = mapM_ (addInlineText doc) inlines
+ addBlockText doc (Paragraph inlines) = mapM_ (addInlineText doc) inlines
+ addBlockText doc (Div _ elems) = mapM_ (addElemText doc) elems
+ addBlockText _ EmptyBlock = return ()
+ addBlockText doc (BlockCmd bcmd) = addBlockCmdText doc bcmd
+
+ addInlineText â· Document â InlineElement â IO ()
+ addInlineText doc (Text text) = addText doc text
+ addInlineText doc (Italic inlines) = mapM_ (addInlineText doc) inlines
+ addInlineText doc (Bold inlines) = mapM_ (addInlineText doc) inlines
+ addInlineText doc (ObjectLink page Nothing) = addText doc page
+ addInlineText doc (ObjectLink page (Just text)) = addHiddenText doc page
+ *> addText doc text
+ addInlineText doc (PageLink page fragm Nothing) = addText doc (fromMaybe (â
) page â maybe (â
) (T.cons '#') fragm)
+ addInlineText doc (PageLink page fragm (Just text)) = addHiddenText doc (fromMaybe (â
) page â maybe (â
) (T.cons '#') fragm)
+ *> addText doc text
+ addInlineText doc (ExternalLink uri Nothing) = addText doc (T.pack $ uriToString id uri "")
+ addInlineText doc (ExternalLink uri (Just text)) = addHiddenText doc (T.pack $ uriToString id uri "")
+ *> addText doc text
+ addInlineText _ (LineBreak _) = return ()
+ addInlineText doc (Span _ inlines) = mapM_ (addInlineText doc) inlines
+ addInlineText doc (Image src alt) = do case src of
+ Left uri -> addHiddenText doc (T.pack $ uriToString id uri "")
+ Right page -> addHiddenText doc page
+ case alt of
+ Just text -> addHiddenText doc text
+ Nothing -> return ()
+ addInlineText doc (Anchor _ inlines) = mapM_ (addInlineText doc) inlines
+ addInlineText _ (Input _) = return ()
+ addInlineText _ EmptyInline = return ()
+ addInlineText doc (InlineCmd icmd) = addInlineCmdText doc icmd
+
+ addListItemText :: Document -> ListItem -> IO ()
+ addListItemText = mapM_ . addElemText
+
+ addDefinitionText :: Document -> Definition -> IO ()
+ addDefinitionText doc (Definition term desc)
+ = do mapM_ (addInlineText doc) term
+ mapM_ (addInlineText doc) desc
+
+ addBlockCmdText :: Document -> BlockCommand -> IO ()
+ addBlockCmdText doc (BlockCommand _ _ blocks) = mapM_ (addBlockText doc) blocks
+
+ addInlineCmdText :: Document -> InlineCommand -> IO ()
+ addInlineCmdText doc (InlineCommand _ _ inlines) = mapM_ (addInlineText doc) inlines
+
+
+makePageLinkList â· (ArrowXml (â), ArrowChoice (â), ArrowIO (â))
+ â Storage
+ â SystemConfig
+ â InterpTable
+ â XmlTree â [PageName]
+makePageLinkList sto sysConf interpTable
+ = proc tree
+ â do wiki â wikifyPage interpTable ⤠tree
+ pName â getXPathTreesInDoc "/page/@name/text()" â getText ⤠tree
+ interpreted â interpretCommands sto sysConf interpTable
+ ⤠(Just (T.pack pName), Just tree, Just wiki, wiki)
+ returnA ⤠concatMap extractFromBlock interpreted
+ where
+ extractFromElem :: Element -> [PageName]
+ extractFromElem (Block b) = extractFromBlock b
+ extractFromElem (Inline i) = extractFromInline i
+
+ extractFromBlock :: BlockElement -> [PageName]
+ extractFromBlock (List _ items) = concatMap extractFromListItem items
+ extractFromBlock (DefinitionList defs) = concatMap extractFromDefinition defs
+ extractFromBlock (Preformatted inlines) = concatMap extractFromInline inlines
+ extractFromBlock (Paragraph inlines) = concatMap extractFromInline inlines
+ extractFromBlock (Div _ elems) = concatMap extractFromElem elems
+ extractFromBlock _ = []
+ extractFromInline :: InlineElement -> [PageName]
+ extractFromInline (Italic inlines) = concatMap extractFromInline inlines
+ extractFromInline (Bold inlines) = concatMap extractFromInline inlines
+ extractFromInline (Span _ inlines) = concatMap extractFromInline inlines
+ extractFromInline (PageLink (Just name) _ _) = [name]
+ extractFromInline _ = []
--- Perform monadic transformation in top-down order.
-everywhereM' :: Monad m => GenericM m -> GenericM m
-everywhereM' f x = f x >>= gmapM (everywhereM' f)
+ extractFromListItem :: ListItem -> [PageName]
+ extractFromListItem = concatMap extractFromElem
+ extractFromDefinition :: Definition -> [PageName]
+ extractFromDefinition (Definition term desc)
+ = concatMap extractFromInline term
+ ++
+ concatMap extractFromInline desc
-wikifyParseError :: ArrowXml a => a ParseError WikiPage
-wikifyParseError
- = proc err -> returnA -< [Div [("class", "error")]
- [ Preformatted [Text (show err)] ]]
+wikifyParseError â· Arrow (â) â ParseError â WikiPage
+wikifyParseError = proc err
+ â returnA -< [Div [("class", "error")]
+ [ Block (Preformatted [Text (T.pack $ show err)]) ]]