module LatexConverter.Util (
  createTag
, beginTag
, endTag
, sectionTag
, subsectionTag
, itemTag
, documentEndTag
, documentBeginTag
, accfuntion
, convertList)
where
import TextData.Data
import TextData.Keywords


createTag :: String -> String -> String -> String
createTag t o o2 =  "\\" ++ t ++ "{" ++ o ++ "}" ++ (h o2) ++ "\n"
      where h "" = ""
            h s  = "[" ++ s ++ "]"

beginTag :: String -> String
beginTag s = createTag begin_tag s empty

endTag :: String -> String
endTag s = createTag end_tag s empty

sectionTag :: String -> String
sectionTag s = createTag section__tag s empty

subsectionTag :: String -> String
subsectionTag s = createTag subsection__tag s empty

itemTag :: String
itemTag = createTag item_tag empty empty

{-specific tags-}

documentBeginTag :: String
documentBeginTag = beginTag document_tag

documentEndTag :: String
documentEndTag = endTag document_tag

convertList :: (Monad m, Foldable t)
      => (m [Char] -> a -> m [Char]) -> t a -> m [Char]
convertList c = foldl c (return "")

accfuntion :: Monad m => (t -> m [a]) -> m [a] -> t -> m [a]
accfuntion st s t = s >>= \x -> st t >>= \y -> return $ x ++ y
