From 76607879df7d41d3f3b24901ca4d5755b94bada1 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Sat, 16 Feb 2019 09:08:58 +0100 Subject: [PATCH] Remove unused exports, commented-out operator, fix bug in metadata parser failing when followed by ':' and redefine the offset as the number of lines to skip not the line at which body starts --- src/Article.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Article.hs b/src/Article.hs index 0507102..bc3f066 100644 --- a/src/Article.hs +++ b/src/Article.hs @@ -5,7 +5,6 @@ module Article ( , at , getKey , preview - , titleP ) where import Control.Applicative ((<|>)) @@ -19,9 +18,8 @@ import System.Posix.Files (getFileStatus, modificationTime) import Text.ParserCombinators.Parsec ( ParseError , Parser --- , (<|>) , anyChar, char, count, endBy, eof, getPosition, many, many1, noneOf - , oneOf, option, parse, skipMany, sourceLine, spaces, string, try + , oneOf, option, parse, skipMany, sourceLine, string, try ) type Metadata = Map String String @@ -41,7 +39,7 @@ articleP = headerP = try ((,,,) <$> titleP <* many eol <*> metadataP) <|> flip (,,,) <$> metadataP <* many eol<*> titleP - lineOffset = sourceLine <$> getPosition + lineOffset = pred . sourceLine <$> getPosition bodyP = lines <$> many anyChar <* eof metadataP :: Parser Metadata @@ -52,7 +50,8 @@ metadataP = Map.fromList <$> option [] ( ) where metaSectionSeparator = count 3 (oneOf "~-") *> eol - keyVal = (,) <$> (no ": " <* spaces <* char ':' <* spaces) <*> no "\r\n" + spaces = skipMany $ char ' ' + keyVal = (,) <$> (no ": \r\n" <* spaces <* char ':' <* spaces) <*> no "\r\n" titleP :: Parser String titleP = try (singleLine <|> underlined)