Muse reader: remove indentation from examples indicated by {{{ and }}}
This commit is contained in:
parent
63b3886bfe
commit
1071732719
2 changed files with 13 additions and 4 deletions
|
@ -147,6 +147,9 @@ lchop s = s
|
||||||
rchop :: String -> String
|
rchop :: String -> String
|
||||||
rchop = reverse . lchop . reverse
|
rchop = reverse . lchop . reverse
|
||||||
|
|
||||||
|
unindent :: String -> String
|
||||||
|
unindent = rchop . intercalate "\n" . dropSpacePrefix . splitOn "\n" . lchop
|
||||||
|
|
||||||
dropSpacePrefix :: [String] -> [String]
|
dropSpacePrefix :: [String] -> [String]
|
||||||
dropSpacePrefix lns =
|
dropSpacePrefix lns =
|
||||||
map (drop maxIndent) lns
|
map (drop maxIndent) lns
|
||||||
|
@ -380,15 +383,15 @@ amuseHeadingUntil end = try $ do
|
||||||
example :: PandocMonad m => MuseParser m (F Blocks)
|
example :: PandocMonad m => MuseParser m (F Blocks)
|
||||||
example = try $ pure . B.codeBlock
|
example = try $ pure . B.codeBlock
|
||||||
<$ string "{{{"
|
<$ string "{{{"
|
||||||
<* optional blankline
|
<* many spaceChar
|
||||||
<*> manyTill anyChar (try (optional blankline *> string "}}}"))
|
<*> (unindent <$> manyTill anyChar (string "}}}"))
|
||||||
|
|
||||||
-- | Parse an @\<example>@ tag.
|
-- | Parse an @\<example>@ tag.
|
||||||
exampleTag :: PandocMonad m => MuseParser m (F Blocks)
|
exampleTag :: PandocMonad m => MuseParser m (F Blocks)
|
||||||
exampleTag = try $ fmap pure $ B.codeBlockWith
|
exampleTag = try $ fmap pure $ B.codeBlockWith
|
||||||
<$ many spaceChar
|
<$ many spaceChar
|
||||||
<*> (htmlAttrToPandoc <$> openTag "example")
|
<*> (htmlAttrToPandoc <$> openTag "example")
|
||||||
<*> (rchop . intercalate "\n" . dropSpacePrefix . splitOn "\n" . lchop <$> manyTill anyChar (closeTag "example"))
|
<*> (unindent <$> manyTill anyChar (closeTag "example"))
|
||||||
<* manyTill spaceChar eol
|
<* manyTill spaceChar eol
|
||||||
|
|
||||||
-- | Parse a @\<literal>@ tag as a raw block.
|
-- | Parse a @\<literal>@ tag as a raw block.
|
||||||
|
@ -398,7 +401,7 @@ literalTag = try $ fmap pure $ B.rawBlock
|
||||||
<$ many spaceChar
|
<$ many spaceChar
|
||||||
<*> (fromMaybe "html" . lookup "style" <$> openTag "literal") -- FIXME: Emacs Muse inserts <literal> without style into all output formats, but we assume HTML
|
<*> (fromMaybe "html" . lookup "style" <$> openTag "literal") -- FIXME: Emacs Muse inserts <literal> without style into all output formats, but we assume HTML
|
||||||
<* manyTill spaceChar eol
|
<* manyTill spaceChar eol
|
||||||
<*> (rchop . intercalate "\n" . dropSpacePrefix . splitOn "\n" . lchop <$> manyTill anyChar (closeTag "literal"))
|
<*> (unindent <$> manyTill anyChar (closeTag "literal"))
|
||||||
<* manyTill spaceChar eol
|
<* manyTill spaceChar eol
|
||||||
|
|
||||||
-- | Parse @\<center>@ tag.
|
-- | Parse @\<center>@ tag.
|
||||||
|
|
|
@ -459,6 +459,12 @@ tests =
|
||||||
, "}}}"
|
, "}}}"
|
||||||
] =?>
|
] =?>
|
||||||
codeBlock "Example line\n"
|
codeBlock "Example line\n"
|
||||||
|
, "Indented braces" =:
|
||||||
|
T.unlines [ " - {{{"
|
||||||
|
, " Example line"
|
||||||
|
, " }}}"
|
||||||
|
] =?>
|
||||||
|
bulletList [ codeBlock "Example line" ]
|
||||||
-- Amusewiki requires braces to be on separate line,
|
-- Amusewiki requires braces to be on separate line,
|
||||||
-- this is an extension.
|
-- this is an extension.
|
||||||
, "One line" =:
|
, "One line" =:
|
||||||
|
|
Loading…
Reference in a new issue