git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: refactoring
commite26313dd62e1513a9bc2f75f2198a8dd8e9097ea authorAlexander Krotov <ilabdsf@gmail.com> dateFri 21 Sep 2018, 11:50 (8 years ago) parentb7b93d7
1 file changed+21−18
src/Text/Pandoc/Readers/Muse.hs+21−18
src/Text/Pandoc/Readers/Muse.hs+21−18
@@ -165,6 +165,9 @@ atStart p = do
165165 guard $ museLastStrPos st /= Just pos
166166 p
167167
168+firstColumn :: PandocMonad m => MuseParser m ()
169+firstColumn = getPosition >>= \pos -> guard (sourceColumn pos == 1)
170+
168171-- * Parsers
169172
170173-- | Parse end-of-line, which can be either a newline or end-of-file.
@@ -360,12 +363,11 @@ blockElements = do
360363
361364-- | Parse a line comment, starting with @;@ in the first column.
362365comment :: PandocMonad m => MuseParser m (F Blocks)
363−comment = try $ do
364− getPosition >>= \pos -> guard (sourceColumn pos == 1)
365− char ';'
366− optional (spaceChar *> many (noneOf "\n"))
367− eol
368− return mempty
366+comment = try $ mempty
367+ <$ firstColumn
368+ <* char ';'
369+ <* optional (spaceChar *> many (noneOf "\n"))
370+ <* eol
369371
370372-- | Parse a horizontal rule, consisting of 4 or more @\'-\'@ characters.
371373separator :: PandocMonad m => MuseParser m (F Blocks)
@@ -378,7 +380,7 @@ separator = try $ pure B.horizontalRule
378380headingStart :: PandocMonad m => MuseParser m (String, Int)
379381headingStart = try $ do
380382 anchorId <- option "" $ try (parseAnchor <* manyTill spaceChar eol)
381− getPosition >>= \pos -> guard (sourceColumn pos == 1)
383+ firstColumn
382384 level <- fmap length $ many1 $ char '*'
383385 guard $ level <= 5
384386 spaceChar
@@ -801,10 +803,11 @@ endline :: PandocMonad m => MuseParser m (F Inlines)
801803endline = try $ pure B.softbreak <$ newline <* notFollowedBy blankline
802804
803805parseAnchor :: PandocMonad m => MuseParser m String
804−parseAnchor = try $ do
805− getPosition >>= \pos -> guard (sourceColumn pos == 1)
806− char '#'
807− (:) <$> letter <*> many (letter <|> digit <|> char '-')
806+parseAnchor = try $ (:)
807+ <$ firstColumn
808+ <* char '#'
809+ <*> letter
810+ <*> many (letter <|> digit <|> char '-')
808811
809812anchor :: PandocMonad m => MuseParser m (F Inlines)
810813anchor = try $ do
@@ -849,8 +852,9 @@ enclosedInlines :: (PandocMonad m, Show a, Show b)
849852 => MuseParser m a
850853 -> MuseParser m b
851854 -> MuseParser m (F Inlines)
852−enclosedInlines start end = try $
853− trimInlinesF . mconcat <$> (enclosed (atStart start) end inline <* notFollowedBy (satisfy ((||) <$> isLetter <*> isDigit)))
855+enclosedInlines start end = try $ trimInlinesF . mconcat
856+ <$> enclosed (atStart start) end inline
857+ <* notFollowedBy (satisfy ((||) <$> isLetter <*> isDigit))
854858
855859-- | Parse an inline tag, such as @\<em>@ and @\<strong>@.
856860inlineTag :: PandocMonad m
@@ -871,9 +875,9 @@ emph = fmap B.emph <$> emphasisBetween (char '*')
871875-- | Parse underline inline markup, indicated by @_@.
872876-- Supported only in Emacs Muse mode, not Text::Amuse.
873877underlined :: PandocMonad m => MuseParser m (F Inlines)
874−underlined = do
875− guardDisabled Ext_amuse -- Supported only by Emacs Muse
876− fmap underlineSpan <$> emphasisBetween (char '_')
878+underlined = fmap underlineSpan
879+ <$ guardDisabled Ext_amuse -- Supported only by Emacs Muse
880+ <*> emphasisBetween (char '_')
877881
878882-- | Parse @\<strong>@ tag.
879883strongTag :: PandocMonad m => MuseParser m (F Inlines)
@@ -902,9 +906,8 @@ verbatimTag = return . B.text . snd <$> htmlElement "verbatim"
902906-- | Parse @\<class>@ tag.
903907classTag :: PandocMonad m => MuseParser m (F Inlines)
904908classTag = do
905− attrs <- openTag "class"
909+ classes <- maybe [] words . lookup "name" <$> openTag "class"
906910 res <- manyTill inline $ closeTag "class"
907− let classes = maybe [] words $ lookup "name" attrs
908911 return $ B.spanWith ("", classes, []) <$> mconcat res
909912
910913-- | Parse "~~" as nonbreaking space.