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

This commit is contained in:
Tissevert 2019-02-16 09:08:58 +01:00
parent 6c3f31ea6c
commit 76607879df
1 changed files with 4 additions and 5 deletions

View File

@ -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)