diff --git a/src/Blog/Wording.hs b/src/Blog/Wording.hs index 3925d29..9d3023e 100644 --- a/src/Blog/Wording.hs +++ b/src/Blog/Wording.hs @@ -19,7 +19,7 @@ import Paths_hablo (getDataFileName) import Text.ParserCombinators.Parsec ( Parser , (<|>) - , char, choice, endBy, many, many1, noneOf, parse, string, try + , char, choice, endBy, eof, many, many1, noneOf, optional, parse, string, try ) import System.Exit (die) @@ -61,11 +61,14 @@ addWording currentWording wordingFile = do Right newWording -> return $ Map.union currentWording newWording wordingP :: Parser (Map String Text) -wordingP = Map.map Text.pack . Map.fromList <$> (many eol *> line `endBy` (many1 eol)) +wordingP = Map.map Text.pack . Map.fromList <$> + (many skip *> line `endBy` (many1 skip) <* eof) where - line = (,) <$> (choice (try . string <$> keys) <* equal) <*> many (noneOf "\r\n") - equal = many (char ' ') *> char '=' *> many (char ' ') + restOfLine = many $ noneOf "\r\n" eol = try (string "\r\n") <|> string "\r" <|> string "\n" + skip = optional (char '#' *> restOfLine) *> eol + line = (,) <$> (choice (try . string <$> keys) <* equal) <*> restOfLine + equal = many (char ' ') *> char '=' *> many (char ' ') checkTemplateWith :: [Text] -> String -> Map String Text -> IO Template checkTemplateWith variables key wording =