module Haskell (doHaskell) where import Regex (mkRegex,matchRegex,Sub,mkSub,doSub) import Split (Split(..)) import Filter (Filt,DocSubs,filterLine,docSubs,process) notSymbol :: String notSymbol = "[^-!#$%&*+./<=>?@\\^|~]" isolated :: String -> String isolated s = "(^|" ++ notSymbol ++ ")" ++ s ++ "($|" ++ notSymbol ++ ")" codeSubs :: [Sub] codeSubs = map mkSub [ (isolated "=>", "\\1⇒\\2") , (isolated "<=", "\\1⇐\\2") , (isolated "->", "\\1→\\2") , (isolated "<-", "\\1←\\2") ] libraries :: String libraries = "http://www.haskell.org/ghc/docs/latest/html/libraries/" haskellDocSubs :: DocSubs haskellDocSubs = [ ("lib", "([^` \t]+)[ \t]+`([^` \t]+)`", "[`\\3`](" ++ libraries ++ "\\2/\\3.html \"\\3\")") ] undotURL :: String -> String undotURL line = let regex = mkRegex $ "(^.*" ++ libraries ++ ")(.*)(.html .*$)" sub = mkSub ("\\.", "-") in case matchRegex regex line of Just [x,y,z] -> x ++ (doSub y sub) ++ z _ -> line codeFilter, docFilter :: Filt codeFilter = filterLine codeSubs docFilter = undotURL . (filterLine $ docSubs haskellDocSubs) doHaskell :: [Split] -> [Split] doHaskell = process codeFilter docFilter