git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: simplify <literal> tag parsers
f57a8aaAlexander Krotov
src/Text/Pandoc/Readers/Muse.hs+9−17
@@ -422,17 +422,12 @@ exampleTag = try $ do
422-- | Parse a @\<literal>@ tag as a raw block.
422-- | Parse a @\<literal>@ tag as a raw block.
423-- For 'RawInline' @\<literal>@ parser, see 'inlineLiteralTag'.
423-- For 'RawInline' @\<literal>@ parser, see 'inlineLiteralTag'.
424literalTag :: PandocMonad m => MuseParser m (F Blocks)
424literalTag :: PandocMonad m => MuseParser m (F Blocks)
425−literalTag = try $ do
425+literalTag = try $ fmap pure $ B.rawBlock
426− many spaceChar
426+ <$ many spaceChar
427− attr <- htmlAttrToPandoc <$> openTag "literal"
428− manyTill spaceChar eol
429− content <- manyTill anyChar $ closeTag "literal"
430− manyTill spaceChar eol
431− return $ return $ rawBlock (attr, content)
432− where
433− -- FIXME: Emacs Muse inserts <literal> without style into all output formats, but we assume HTML
427+ <*> (fromMaybe "html" . lookup "style" <$> openTag "literal") -- FIXME: Emacs Muse inserts <literal> without style into all output formats, but we assume HTML
434− format (_, _, kvs) = fromMaybe "html" $ lookup "style" kvs
428+ <* manyTill spaceChar eol
435− rawBlock (attrs, content) = B.rawBlock (format attrs) $ rchop $ intercalate "\n" $ dropSpacePrefix $ splitOn "\n" $ lchop content
429+ <*> (rchop . intercalate "\n" . dropSpacePrefix . splitOn "\n" . lchop <$> manyTill anyChar (closeTag "literal"))
430+ <* manyTill spaceChar eol
436
431
437-- | Parse @\<center>@ tag.
432-- | Parse @\<center>@ tag.
438-- Currently it is ignored as Pandoc cannot represent centered blocks.
433-- Currently it is ignored as Pandoc cannot represent centered blocks.
@@ -938,12 +933,9 @@ mathTag = return . B.math . snd <$> htmlElement "math"
938
933
939-- | Parse inline @\<literal>@ tag as a raw inline.
934-- | Parse inline @\<literal>@ tag as a raw inline.
940inlineLiteralTag :: PandocMonad m => MuseParser m (F Inlines)
935inlineLiteralTag :: PandocMonad m => MuseParser m (F Inlines)
941−inlineLiteralTag =
936+inlineLiteralTag = try $ fmap pure $ B.rawInline
942− (return . rawInline) <$> htmlElement "literal"
943− where
944− -- FIXME: Emacs Muse inserts <literal> without style into all output formats, but we assume HTML
937+ <$> (fromMaybe "html" . lookup "style" <$> openTag "literal") -- FIXME: Emacs Muse inserts <literal> without style into all output formats, but we assume HTML
945− format (_, _, kvs) = fromMaybe "html" $ lookup "style" kvs
938+ <*> manyTill anyChar (closeTag "literal")
946− rawInline (attrs, content) = B.rawInline (format attrs) content
947
939
948str :: PandocMonad m => MuseParser m (F Inlines)
940str :: PandocMonad m => MuseParser m (F Inlines)
949str = return . B.str <$> many1 alphaNum <* updateLastStrPos
941str = return . B.str <$> many1 alphaNum <* updateLastStrPos