git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: Allow finishing header with EOF (#3897)
commit743413a5b506351499fa2fb66d4184d74e125c54 authorAlexander <ilabdsf@gmail.com> dateWed 6 Sep 2017, 18:48 (9 years ago) parent0b05222
2 files changed+15−11
src/Text/Pandoc/Readers/Muse.hs+9−5 test/Tests/Readers/Muse.hs+6−6
src/Text/Pandoc/Readers/Muse.hs+9−5
@@ -1,3 +1,4 @@
1+{-# LANGUAGE FlexibleContexts #-}
12{-
23 Copyright (C) 2017 Alexander Krotov <ilabdsf@gmail.com>
34
@@ -100,6 +101,9 @@ parseBlocks = do
100101-- utility functions
101102--
102103
104+eol :: Stream s m Char => ParserT s st m ()
105+eol = void newline <|> eof
106+
103107nested :: PandocMonad m => MuseParser m a -> MuseParser m a
104108nested p = do
105109 nestlevel <- stateMaxNestingLevel <$> getState
@@ -195,7 +199,7 @@ comment = try $ do
195199 char ';'
196200 space
197201 many $ noneOf "\n"
198− void newline <|> eof
202+ eol
199203 return mempty
200204
201205separator :: PandocMonad m => MuseParser m (F Blocks)
@@ -203,7 +207,7 @@ separator = try $ do
203207 string "----"
204208 many $ char '-'
205209 many spaceChar
206− void newline <|> eof
210+ eol
207211 return $ return B.horizontalRule
208212
209213header :: PandocMonad m => MuseParser m (F Blocks)
@@ -214,7 +218,7 @@ header = try $ do
214218 level <- liftM length $ many1 $ char '*'
215219 guard $ level <= 5
216220 spaceChar
217− content <- trimInlinesF . mconcat <$> manyTill inline newline
221+ content <- trimInlinesF . mconcat <$> manyTill inline eol
218222 attr <- registerHeader ("", [], []) (runF content defaultParserState)
219223 return $ B.headerWith attr level <$> content
220224
@@ -464,10 +468,10 @@ museAppendElement tbl element =
464468
465469tableCell :: PandocMonad m => MuseParser m (F Blocks)
466470tableCell = 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
468472
469473tableElements :: PandocMonad m => MuseParser m [MuseTableElement]
470−tableElements = tableParseElement `sepEndBy1` (void newline <|> eof)
474+tableElements = tableParseElement `sepEndBy1` eol
471475
472476elementsToTable :: [MuseTableElement] -> F MuseTable
473477elementsToTable = foldM museAppendElement emptyTable
test/Tests/Readers/Muse.hs+6−6
@@ -210,21 +210,21 @@ tests =
210210 ]
211211 , testGroup "Headers"
212212 [ "Part" =:
213− "* First level\n" =?>
213+ "* First level" =?>
214214 header 1 "First level"
215215 , "Chapter" =:
216− "** Second level\n" =?>
216+ "** Second level" =?>
217217 header 2 "Second level"
218218 , "Section" =:
219− "*** Third level\n" =?>
219+ "*** Third level" =?>
220220 header 3 "Third level"
221221 , "Subsection" =:
222− "**** Fourth level\n" =?>
222+ "**** Fourth level" =?>
223223 header 4 "Fourth level"
224224 , "Subsubsection" =:
225− "***** Fifth level\n" =?>
225+ "***** Fifth level" =?>
226226 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"
228228 , "No headers in footnotes" =:
229229 T.unlines [ "Foo[1]"
230230 , "[1] * Bar"