git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: Allow finishing header with EOF (#3897)
743413aAlexander
src/Text/Pandoc/Readers/Muse.hs+9−5
@@ -1,3 +1,4 @@
1+{-# LANGUAGE FlexibleContexts #-}
1{-
2{-
2 Copyright (C) 2017 Alexander Krotov <ilabdsf@gmail.com>
3 Copyright (C) 2017 Alexander Krotov <ilabdsf@gmail.com>
3
4
@@ -100,6 +101,9 @@ parseBlocks = do
100-- utility functions
101-- utility functions
101--
102--
102
103
104+eol :: Stream s m Char => ParserT s st m ()
105+eol = void newline <|> eof
106+
103nested :: PandocMonad m => MuseParser m a -> MuseParser m a
107nested :: PandocMonad m => MuseParser m a -> MuseParser m a
104nested p = do
108nested p = do
105 nestlevel <- stateMaxNestingLevel <$> getState
109 nestlevel <- stateMaxNestingLevel <$> getState
@@ -195,7 +199,7 @@ comment = try $ do
195 char ';'
199 char ';'
196 space
200 space
197 many $ noneOf "\n"
201 many $ noneOf "\n"
198− void newline <|> eof
202+ eol
199 return mempty
203 return mempty
200
204
201separator :: PandocMonad m => MuseParser m (F Blocks)
205separator :: PandocMonad m => MuseParser m (F Blocks)
@@ -203,7 +207,7 @@ separator = try $ do
203 string "----"
207 string "----"
204 many $ char '-'
208 many $ char '-'
205 many spaceChar
209 many spaceChar
206− void newline <|> eof
210+ eol
207 return $ return B.horizontalRule
211 return $ return B.horizontalRule
208
212
209header :: PandocMonad m => MuseParser m (F Blocks)
213header :: PandocMonad m => MuseParser m (F Blocks)
@@ -214,7 +218,7 @@ header = try $ do
214 level <- liftM length $ many1 $ char '*'
218 level <- liftM length $ many1 $ char '*'
215 guard $ level <= 5
219 guard $ level <= 5
216 spaceChar
220 spaceChar
217− content <- trimInlinesF . mconcat <$> manyTill inline newline
221+ content <- trimInlinesF . mconcat <$> manyTill inline eol
218 attr <- registerHeader ("", [], []) (runF content defaultParserState)
222 attr <- registerHeader ("", [], []) (runF content defaultParserState)
219 return $ B.headerWith attr level <$> content
223 return $ B.headerWith attr level <$> content
220
224
@@ -464,10 +468,10 @@ museAppendElement tbl element =
464
468
465tableCell :: PandocMonad m => MuseParser m (F Blocks)
469tableCell :: PandocMonad m => MuseParser m (F Blocks)
466tableCell = try $ liftM B.plain . trimInlinesF . mconcat <$> manyTill inline (lookAhead cellEnd)
470tableCell = try $ liftM B.plain . trimInlinesF . mconcat <$> manyTill inline (lookAhead cellEnd)
467− where cellEnd = try $ void (many1 spaceChar >> char '|') <|> void newline <|> eof
471+ where cellEnd = try $ void (many1 spaceChar >> char '|') <|> eol
468
472
469tableElements :: PandocMonad m => MuseParser m [MuseTableElement]
473tableElements :: PandocMonad m => MuseParser m [MuseTableElement]
470−tableElements = tableParseElement `sepEndBy1` (void newline <|> eof)
474+tableElements = tableParseElement `sepEndBy1` eol
471
475
472elementsToTable :: [MuseTableElement] -> F MuseTable
476elementsToTable :: [MuseTableElement] -> F MuseTable
473elementsToTable = foldM museAppendElement emptyTable
477elementsToTable = foldM museAppendElement emptyTable
test/Tests/Readers/Muse.hs+6−6
@@ -210,21 +210,21 @@ tests =
210 ]
210 ]
211 , testGroup "Headers"
211 , testGroup "Headers"
212 [ "Part" =:
212 [ "Part" =:
213− "* First level\n" =?>
213+ "* First level" =?>
214 header 1 "First level"
214 header 1 "First level"
215 , "Chapter" =:
215 , "Chapter" =:
216− "** Second level\n" =?>
216+ "** Second level" =?>
217 header 2 "Second level"
217 header 2 "Second level"
218 , "Section" =:
218 , "Section" =:
219− "*** Third level\n" =?>
219+ "*** Third level" =?>
220 header 3 "Third level"
220 header 3 "Third level"
221 , "Subsection" =:
221 , "Subsection" =:
222− "**** Fourth level\n" =?>
222+ "**** Fourth level" =?>
223 header 4 "Fourth level"
223 header 4 "Fourth level"
224 , "Subsubsection" =:
224 , "Subsubsection" =:
225− "***** Fifth level\n" =?>
225+ "***** Fifth level" =?>
226 header 5 "Fifth level"
226 header 5 "Fifth level"
227− , "Whitespace is required after *" =: "**Not a header\n" =?> para "**Not a header"
227+ , "Whitespace is required after *" =: "**Not a header" =?> para "**Not a header"
228 , "No headers in footnotes" =:
228 , "No headers in footnotes" =:
229 T.unlines [ "Foo[1]"
229 T.unlines [ "Foo[1]"
230 , "[1] * Bar"
230 , "[1] * Bar"