packages feed

expand-0.0.1: src/Preprocessors.hs

module Preprocessors (preprocessHtml) where

import Data.Char

-- | Inserts "<plain>" and "</plain>" to escape plain text
preprocessHtml :: String -> String
preprocessHtml ""                 = ""
preprocessHtml ('>':xs) 
             | plainPrefix xs = let (text, xs') = getPlain xs
                                in  "><plain>" ++ text ++ "</plain>" ++ preprocessHtml xs'
preprocessHtml (x  :xs) = x:(preprocessHtml xs) 


plainPrefix :: String -> Bool
plainPrefix xs = case dropWhile isSpace xs of
                     (x:_) -> x /= '<'
                     _     -> False

getPlain :: String -> (String, String)
getPlain xs = (takeWhile (/= '<') xs, dropWhile (/= '<') xs)