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:
parent
6c3f31ea6c
commit
76607879df
1 changed files with 4 additions and 5 deletions
|
@ -5,7 +5,6 @@ module Article (
|
||||||
, at
|
, at
|
||||||
, getKey
|
, getKey
|
||||||
, preview
|
, preview
|
||||||
, titleP
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Applicative ((<|>))
|
import Control.Applicative ((<|>))
|
||||||
|
@ -19,9 +18,8 @@ import System.Posix.Files (getFileStatus, modificationTime)
|
||||||
import Text.ParserCombinators.Parsec (
|
import Text.ParserCombinators.Parsec (
|
||||||
ParseError
|
ParseError
|
||||||
, Parser
|
, Parser
|
||||||
-- , (<|>)
|
|
||||||
, anyChar, char, count, endBy, eof, getPosition, many, many1, noneOf
|
, 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
|
type Metadata = Map String String
|
||||||
|
@ -41,7 +39,7 @@ articleP =
|
||||||
headerP =
|
headerP =
|
||||||
try ((,,,) <$> titleP <* many eol <*> metadataP)
|
try ((,,,) <$> titleP <* many eol <*> metadataP)
|
||||||
<|> flip (,,,) <$> metadataP <* many eol<*> titleP
|
<|> flip (,,,) <$> metadataP <* many eol<*> titleP
|
||||||
lineOffset = sourceLine <$> getPosition
|
lineOffset = pred . sourceLine <$> getPosition
|
||||||
bodyP = lines <$> many anyChar <* eof
|
bodyP = lines <$> many anyChar <* eof
|
||||||
|
|
||||||
metadataP :: Parser Metadata
|
metadataP :: Parser Metadata
|
||||||
|
@ -52,7 +50,8 @@ metadataP = Map.fromList <$> option [] (
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
metaSectionSeparator = count 3 (oneOf "~-") *> eol
|
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 :: Parser String
|
||||||
titleP = try (singleLine <|> underlined)
|
titleP = try (singleLine <|> underlined)
|
||||||
|
|
Loading…
Reference in a new issue