diff options
author | Alexander Krotov <ilabdsf@gmail.com> | 2018-10-17 13:43:55 +0300 |
---|---|---|
committer | Alexander Krotov <ilabdsf@gmail.com> | 2018-10-17 13:57:05 +0300 |
commit | 1071732719fa015b1dcc994e1d80146f291d3e17 (patch) | |
tree | f8560bb287f340f67a4826749215667742fc6f0f /src/Text/Pandoc/Readers | |
parent | 63b3886bfe3c5b50d171355573ab59750e009d03 (diff) | |
download | pandoc-1071732719fa015b1dcc994e1d80146f291d3e17.tar.gz |
Muse reader: remove indentation from examples indicated by {{{ and }}}
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/Muse.hs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index 6acc88b3d..5d417e717 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -147,6 +147,9 @@ lchop s = s rchop :: String -> String rchop = reverse . lchop . reverse +unindent :: String -> String +unindent = rchop . intercalate "\n" . dropSpacePrefix . splitOn "\n" . lchop + dropSpacePrefix :: [String] -> [String] dropSpacePrefix lns = map (drop maxIndent) lns @@ -380,15 +383,15 @@ amuseHeadingUntil end = try $ do example :: PandocMonad m => MuseParser m (F Blocks) example = try $ pure . B.codeBlock <$ string "{{{" - <* optional blankline - <*> manyTill anyChar (try (optional blankline *> string "}}}")) + <* many spaceChar + <*> (unindent <$> manyTill anyChar (string "}}}")) -- | Parse an @\<example>@ tag. exampleTag :: PandocMonad m => MuseParser m (F Blocks) exampleTag = try $ fmap pure $ B.codeBlockWith <$ many spaceChar <*> (htmlAttrToPandoc <$> openTag "example") - <*> (rchop . intercalate "\n" . dropSpacePrefix . splitOn "\n" . lchop <$> manyTill anyChar (closeTag "example")) + <*> (unindent <$> manyTill anyChar (closeTag "example")) <* manyTill spaceChar eol -- | Parse a @\<literal>@ tag as a raw block. @@ -398,7 +401,7 @@ literalTag = try $ fmap pure $ B.rawBlock <$ many spaceChar <*> (fromMaybe "html" . lookup "style" <$> openTag "literal") -- FIXME: Emacs Muse inserts <literal> without style into all output formats, but we assume HTML <* manyTill spaceChar eol - <*> (rchop . intercalate "\n" . dropSpacePrefix . splitOn "\n" . lchop <$> manyTill anyChar (closeTag "literal")) + <*> (unindent <$> manyTill anyChar (closeTag "literal")) <* manyTill spaceChar eol -- | Parse @\<center>@ tag. |