+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)