From 12789fd42a15126751018f7a392d08a05c68c210 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Tue, 5 Dec 2017 12:59:28 +0300 Subject: Muse reader: support multiline directives in Amusewiki mode --- src/Text/Pandoc/Readers/Muse.hs | 28 ++++++++++++++++++++++++---- 1 file 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 } -- -- cgit v1.2.3