aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Krotov <ilabdsf@gmail.com>2018-09-19 13:22:25 +0300
committerAlexander Krotov <ilabdsf@gmail.com>2018-09-19 13:22:25 +0300
commit1feb62cb24a8fda5ce8ea823ec102abc0bd6e2ec (patch)
tree1fcbc75111e49cd843a3c3ff2952a3a73eac2b1f /src
parent6632f2f2cede4dca986bb9216a202bd172599806 (diff)
downloadpandoc-1feb62cb24a8fda5ce8ea823ec102abc0bd6e2ec.tar.gz
Muse reader: add openTag and closeTag functions
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Muse.hs37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs
index 0b5d3dc1f..ea45ea9fc 100644
--- a/src/Text/Pandoc/Readers/Muse.hs
+++ b/src/Text/Pandoc/Readers/Muse.hs
@@ -179,16 +179,22 @@ someUntil p end = first <$> ((:) <$> p) <*> manyUntil p end
-- ** HTML parsers
+openTag :: PandocMonad m => String -> MuseParser m Attr
+openTag tag = do
+ (TagOpen _ attr, _) <- htmlTag(~== TagOpen tag [])
+ return $ htmlAttrToPandoc attr
+
+closeTag :: PandocMonad m => String -> MuseParser m ()
+closeTag tag = void $ htmlTag (~== TagClose tag)
+
-- | Parse HTML tag, returning its attributes and literal contents.
htmlElement :: PandocMonad m
=> String -- ^ Tag name
-> MuseParser m (Attr, String)
htmlElement tag = try $ do
- (TagOpen _ attr, _) <- htmlTag (~== TagOpen tag [])
- content <- manyTill anyChar endtag
- return (htmlAttrToPandoc attr, content)
- where
- endtag = void $ htmlTag (~== TagClose tag)
+ attr <- openTag tag
+ content <- manyTill anyChar $ closeTag tag
+ return (attr, content)
htmlBlock :: PandocMonad m
=> String -- ^ Tag name
@@ -213,13 +219,11 @@ parseHtmlContent :: PandocMonad m
parseHtmlContent tag = try $ do
many spaceChar
pos <- getPosition
- (TagOpen _ attr, _) <- htmlTag (~== TagOpen tag [])
+ attr <- openTag tag
manyTill spaceChar eol
- content <- parseBlocksTill $ try $ count (sourceColumn pos - 1) spaceChar >> endtag
+ content <- parseBlocksTill $ try $ count (sourceColumn pos - 1) spaceChar >> closeTag tag
manyTill spaceChar eol -- closing tag must be followed by optional whitespace and newline
- return (htmlAttrToPandoc attr, content)
- where
- endtag = void $ htmlTag (~== TagClose tag)
+ return (attr, content)
-- ** Directive parsers
@@ -423,13 +427,12 @@ exampleTag = try $ do
literalTag :: PandocMonad m => MuseParser m (F Blocks)
literalTag = try $ do
many spaceChar
- (TagOpen _ attr, _) <- htmlTag (~== TagOpen "literal" [])
+ attr <- openTag "literal"
manyTill spaceChar eol
- content <- manyTill anyChar endtag
+ content <- manyTill anyChar $ closeTag "literal"
manyTill spaceChar eol
- return $ return $ rawBlock (htmlAttrToPandoc attr, content)
+ return $ return $ rawBlock (attr, content)
where
- endtag = void $ htmlTag (~== TagClose "literal")
-- FIXME: Emacs Muse inserts <literal> without style into all output formats, but we assume HTML
format (_, _, kvs) = fromMaybe "html" $ lookup "style" kvs
rawBlock (attrs, content) = B.rawBlock (format attrs) $ rchop $ intercalate "\n" $ dropSpacePrefix $ splitOn "\n" $ lchop content
@@ -480,14 +483,12 @@ verseTag :: PandocMonad m => MuseParser m (F Blocks)
verseTag = try $ do
many spaceChar
pos <- getPosition
- (TagOpen _ _, _) <- htmlTag (~== TagOpen "verse" [])
+ openTag "verse"
manyTill spaceChar eol
let indent = count (sourceColumn pos - 1) spaceChar
- content <- sequence <$> manyTill (indent >> verseLine) (try $ indent >> endtag)
+ content <- sequence <$> manyTill (indent >> verseLine) (try $ indent >> closeTag "verse")
manyTill spaceChar eol
return $ B.lineBlock <$> content
- where
- endtag = void $ htmlTag (~== TagClose "verse")
-- | Parse @\<comment>@ tag.
commentTag :: PandocMonad m => MuseParser m (F Blocks)