-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathArchWiki.hs
30 lines (23 loc) · 889 Bytes
/
ArchWiki.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module ArchWiki where
import Text.Pandoc
import Text.Pandoc.Walk
import Text.HTML.TagSoup
cleanAttr :: Block -> Block
cleanAttr (Header 3 _ xs) = Header 3 nullAttr ([Str "> "] ++ xs)
cleanAttr (Header n _ xs) = Header n nullAttr xs
cleanAttr (CodeBlock _ xs) = CodeBlock nullAttr xs
cleanAttr (Para [Strong [Str cat]]) = Header 3 nullAttr [Str ("> " ++ cat)]
cleanAttr x = x
filterWiki html = renderTags $ (take 4 skip) ++ cont
where tags = parseTags html
skip = dropWhile (~/= "<h1 id=firstHeading>") tags
cont = takeWhile (~/= "<div id=p-cactions>") $
dropWhile (~/= "<div id=mw-content-text>") skip
readDoc :: String -> Pandoc
readDoc = readHtml def
writeDoc :: Pandoc -> String
writeDoc = writePlain def
cleanDoc :: String -> String
cleanDoc = writeDoc . walk cleanAttr . readDoc . filterWiki
main :: IO ()
main = interact cleanDoc