git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: paragraph indentation does not indicate nested quote

Muse allows indentation to indicate quotation or alignment, but only on the top level, not within a <quote> or list. This patch also simplifies the code by removing museInQuote and museInList fields from the state structure. Headers and indented paragraphs are attempted to be parsed only at the topmost level, instead of aborting parsing with guards.

commit3480a8acc24c650bc208b2e6cc8f1d5ac2e04aa5 authorAlexander Krotov <ilabdsf@gmail.com> dateMon 12 Feb 2018, 04:25 (9 years ago) parent30cd636
2 files changed+16−35
src/Text/Pandoc/Readers/Muse.hs+10−35 test/Tests/Readers/Muse.hs+6
src/Text/Pandoc/Readers/Muse.hs+10−35
@@ -81,8 +81,6 @@ data MuseState = MuseState { museMeta :: F Meta -- ^ Document metadata
8181 , museLastStrPos :: Maybe SourcePos -- ^ Position after last str parsed
8282 , museLogMessages :: [LogMessage]
8383 , museNotes :: M.Map String (SourcePos, F Blocks)
84− , museInQuote :: Bool
85− , museInList :: Bool
8684 , museInLink :: Bool
8785 }
8886
@@ -97,8 +95,6 @@ defaultMuseState = MuseState { museMeta = return nullMeta
9795 , museLastStrPos = Nothing
9896 , museLogMessages = []
9997 , museNotes = M.empty
100− , museInQuote = False
101− , museInList = False
10298 , museInLink = False
10399 }
104100
@@ -256,11 +252,14 @@ parseBlocks =
256252 try blockStart <|>
257253 try paraStart
258254 where
259− blockStart = do first <- blockElements
255+ blockStart = do first <- header <|> blockElements <|> amuseNoteBlock <|> emacsNoteBlock
260256 rest <- parseBlocks
261257 return $ first B.<> rest
262− paraStart = do (first, rest) <- paraUntil ((mempty <$ eof) <|> blockStart)
263− return $ first B.<> rest
258+ paraStart = do
259+ indent <- length <$> many spaceChar
260+ (first, rest) <- paraUntil ((mempty <$ eof) <|> blockStart)
261+ let first' = if indent >= 2 && indent < 6 then B.blockQuote <$> first else first
262+ return $ first' B.<> rest
264263
265264parseBlock :: PandocMonad m => MuseParser m (F Blocks)
266265parseBlock = do
@@ -273,7 +272,6 @@ blockElements :: PandocMonad m => MuseParser m (F Blocks)
273272blockElements = choice [ mempty <$ blankline
274273 , comment
275274 , separator
276− , header
277275 , example
278276 , exampleTag
279277 , literalTag
@@ -288,8 +286,6 @@ blockElements = choice [ mempty <$ blankline
288286 , definitionList
289287 , table
290288 , commentTag
291− , amuseNoteBlock
292− , emacsNoteBlock
293289 ]
294290
295291comment :: PandocMonad m => MuseParser m (F Blocks)
@@ -309,9 +305,7 @@ separator = try $ do
309305
310306header :: PandocMonad m => MuseParser m (F Blocks)
311307header = try $ do
312− st <- museInList <$> getState
313− q <- museInQuote <$> getState
314− getPosition >>= \pos -> guard (not st && not q && sourceColumn pos == 1)
308+ getPosition >>= \pos -> guard (sourceColumn pos == 1)
315309 level <- fmap length $ many1 $ char '*'
316310 guard $ level <= 5
317311 spaceChar
@@ -370,13 +364,7 @@ rightTag :: PandocMonad m => MuseParser m (F Blocks)
370364rightTag = snd <$> parseHtmlContent "right"
371365
372366quoteTag :: PandocMonad m => MuseParser m (F Blocks)
373−quoteTag = do
374− st <- getState
375− let oldInQuote = museInQuote st
376− setState $ st{ museInQuote = True }
377− res <- snd <$> parseHtmlContent "quote"
378− setState $ st{ museInQuote = oldInQuote }
379− return $ B.blockQuote <$> res
367+quoteTag = (fmap B.blockQuote) <$> snd <$> parseHtmlContent "quote"
380368
381369-- <div> tag is supported by Emacs Muse, but not Amusewiki 2.025
382370divTag :: PandocMonad m => MuseParser m (F Blocks)
@@ -408,12 +396,8 @@ paraUntil :: PandocMonad m
408396 => MuseParser m a
409397 -> MuseParser m (F Blocks, a)
410398paraUntil end = do
411− indent <- length <$> many spaceChar
412− st <- museInList <$> getState
413− let f = if not st && indent >= 2 && indent < 6 then B.blockQuote else id
414399 (l, e) <- someUntil inline $ try (manyTill spaceChar eol >> end)
415− let p = fmap (f . B.para) $ trimInlinesF $ mconcat l
416− return (p, e)
400+ return (fmap (B.para) $ trimInlinesF $ mconcat l, e)
417401
418402noteMarker :: PandocMonad m => MuseParser m String
419403noteMarker = try $ do
@@ -481,18 +465,9 @@ lineBlock = try $ do
481465-- lists
482466--
483467
484−withListContext :: PandocMonad m => MuseParser m a -> MuseParser m a
485−withListContext p = do
486− state <- getState
487− let oldInList = museInList state
488− setState $ state { museInList = True }
489− parsed <- p
490− updateState (\st -> st { museInList = oldInList })
491− return parsed
492−
493468listItemContents' :: PandocMonad m => Int -> MuseParser m (F Blocks)
494469listItemContents' col =
495− mconcat <$> withListContext (parseBlock `sepBy1` try (skipMany blankline >> indentWith col))
470+ mconcat <$> parseBlock `sepBy1` try (skipMany blankline >> indentWith col)
496471
497472listItemContents :: PandocMonad m => MuseParser m (F Blocks)
498473listItemContents = do
test/Tests/Readers/Muse.hs+6
@@ -252,6 +252,12 @@ tests =
252252 , "Quote" =:
253253 " This is a quotation\n" =?>
254254 blockQuote (para "This is a quotation")
255+ , "Indentation does not indicate quote inside quote tag" =:
256+ T.unlines [ "<quote>"
257+ , " Not a nested quote"
258+ , "</quote>"
259+ ] =?>
260+ blockQuote (para "Not a nested quote")
255261 , "Multiline quote" =:
256262 T.unlines [ " This is a quotation"
257263 , " with a continuation"