diff options
author | Alexander Krotov <ilabdsf@gmail.com> | 2017-12-05 12:59:28 +0300 |
---|---|---|
committer | Alexander Krotov <ilabdsf@gmail.com> | 2017-12-05 12:59:28 +0300 |
commit | 12789fd42a15126751018f7a392d08a05c68c210 (patch) | |
tree | 814d217d0fcd2ec41d494ad615f0e5f3ead61a29 /src/Text | |
parent | 00f634ba805bd767d0f66c7413b17efa0077e5fd (diff) | |
download | pandoc-12789fd42a15126751018f7a392d08a05c68c210.tar.gz |
Muse reader: support multiline directives in Amusewiki mode
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Readers/Muse.hs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index 0688b479c..39aa67f82 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -140,19 +140,39 @@ commonPrefix (x:xs) (y:ys) -- directive parsers -- -parseDirective :: PandocMonad m => MuseParser m (String, F Inlines) -parseDirective = do +-- While not documented, Emacs Muse allows "-" in directive name +parseDirectiveKey :: PandocMonad m => MuseParser m (String) +parseDirectiveKey = do char '#' - key <- many letter + many (letter <|> char '-') + +parseEmacsDirective :: PandocMonad m => MuseParser m (String, F Inlines) +parseEmacsDirective = do + key <- parseDirectiveKey space spaces raw <- manyTill anyChar eol value <- parseFromString (trimInlinesF . mconcat <$> many inline) raw return (key, value) +parseAmuseDirective :: PandocMonad m => MuseParser m (String, F Inlines) +parseAmuseDirective = do + key <- parseDirectiveKey + space + spaces + first <- manyTill anyChar eol + rest <- manyTill anyLine endOfDirective + many blankline + value <- parseFromString (trimInlinesF . mconcat <$> many inline) $ unlines (first : rest) + return (key, value) + where + endOfDirective = lookAhead $ endOfInput <|> (try $ void blankline) <|> (try $ void parseDirectiveKey) + endOfInput = try $ skipMany blankline >> skipSpaces >> eof + directive :: PandocMonad m => MuseParser m () directive = do - (key, value) <- parseDirective + ext <- getOption readerExtensions + (key, value) <- if extensionEnabled Ext_amuse ext then parseAmuseDirective else parseEmacsDirective updateState $ \st -> st { stateMeta' = B.setMeta key <$> value <*> stateMeta' st } -- |