git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: reduce duplication by introducing `getIndent`
commit7cfce586f6ef6e97934c48f8871741aa0e8379dc authorAlexander Krotov <ilabdsf@gmail.com> dateFri 5 Oct 2018, 18:27 (8 years ago) parentabd770c
1 file changed+7−9
src/Text/Pandoc/Readers/Muse.hs+7−9
src/Text/Pandoc/Readers/Muse.hs+7−9
@@ -548,6 +548,10 @@ lineBlock = try $ do
548548
549549-- *** List parsers
550550
551+getIndent :: PandocMonad m
552+ => MuseParser m Int
553+getIndent = subtract 1 . sourceColumn <$ many spaceChar <*> getPosition
554+
551555bulletListItemsUntil :: PandocMonad m
552556 => Int -- ^ Indentation
553557 -> MuseParser m a -- ^ Terminator parser
@@ -564,9 +568,7 @@ bulletListUntil :: PandocMonad m
564568 => MuseParser m a
565569 -> MuseParser m (F Blocks, a)
566570bulletListUntil end = try $ do
567− many spaceChar
568− pos <- getPosition
569− let indent = sourceColumn pos - 1
571+ indent <- getIndent
570572 guard $ indent /= 0
571573 (items, e) <- bulletListItemsUntil indent end
572574 return (B.bulletList <$> sequence items, e)
@@ -604,9 +606,7 @@ orderedListUntil :: PandocMonad m
604606 => MuseParser m a
605607 -> MuseParser m (F Blocks, a)
606608orderedListUntil end = try $ do
607− many spaceChar
608− pos <- getPosition
609− let indent = sourceColumn pos - 1
609+ indent <- getIndent
610610 guard $ indent /= 0
611611 (style, start) <- decimal <|> lowerRoman <|> upperRoman <|> lowerAlpha <|> upperAlpha
612612 char '.'
@@ -642,9 +642,7 @@ definitionListUntil :: PandocMonad m
642642 => MuseParser m a -- ^ Terminator parser
643643 -> MuseParser m (F Blocks, a)
644644definitionListUntil end = try $ do
645− many spaceChar
646− pos <- getPosition
647− let indent = sourceColumn pos - 1
645+ indent <- getIndent
648646 guardDisabled Ext_amuse <|> guard (indent /= 0) -- Initial space is required by Amusewiki, but not Emacs Muse
649647 first (fmap B.definitionList . sequence) <$> definitionListItemsUntil indent end
650648