aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorAlexander Krotov <ilabdsf@gmail.com>2018-09-02 14:38:04 +0300
committerAlexander Krotov <ilabdsf@gmail.com>2018-09-02 14:38:04 +0300
commit1630a731ec35d3e8538561b7824c135303fe4bdb (patch)
tree3442e135ff8b90f2f6b4d672a408477d97dfc518 /src/Text/Pandoc/Readers
parentafd3f21218cf4279cc718ff050b4ab9c747e72e1 (diff)
downloadpandoc-1630a731ec35d3e8538561b7824c135303fe4bdb.tar.gz
Muse reader: move duplicate code into "headingStart" function
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/Muse.hs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs
index 045feedb3..b251f2237 100644
--- a/src/Text/Pandoc/Readers/Muse.hs
+++ b/src/Text/Pandoc/Readers/Muse.hs
@@ -361,15 +361,20 @@ separator = try $ do
eol
return $ return B.horizontalRule
--- | Parse a single-line heading.
-emacsHeading :: PandocMonad m => MuseParser m (F Blocks)
-emacsHeading = try $ do
- guardDisabled Ext_amuse
+headingStart :: PandocMonad m => MuseParser m (String, Int)
+headingStart = do
anchorId <- option "" $ try (parseAnchor <* manyTill spaceChar eol)
getPosition >>= \pos -> guard (sourceColumn pos == 1)
level <- fmap length $ many1 $ char '*'
guard $ level <= 5
spaceChar
+ return (anchorId, level)
+
+-- | Parse a single-line heading.
+emacsHeading :: PandocMonad m => MuseParser m (F Blocks)
+emacsHeading = try $ do
+ guardDisabled Ext_amuse
+ (anchorId, level) <- headingStart
content <- trimInlinesF . mconcat <$> manyTill inline eol
attr <- registerHeader (anchorId, [], []) (runF content def)
return $ B.headerWith attr level <$> content
@@ -381,11 +386,7 @@ amuseHeadingUntil :: PandocMonad m
-> MuseParser m (F Blocks, a)
amuseHeadingUntil end = try $ do
guardEnabled Ext_amuse
- anchorId <- option "" $ try (parseAnchor <* manyTill spaceChar eol)
- getPosition >>= \pos -> guard (sourceColumn pos == 1)
- level <- fmap length $ many1 $ char '*'
- guard $ level <= 5
- spaceChar
+ (anchorId, level) <- headingStart
(content, e) <- paraContentsUntil end
attr <- registerHeader (anchorId, [], []) (runF content def)
return (B.headerWith attr level <$> content, e)