Muse reader: debug indented paragraph support (#3839)

Take only first line indentation into account
and do not start new paragraph on indentation change.
This commit is contained in:
Alexander 2017-08-07 07:43:59 +03:00 committed by John MacFarlane
parent a67a96b932
commit 1b5bfced55
2 changed files with 34 additions and 27 deletions

View file

@ -186,7 +186,6 @@ blockElements = choice [ comment
, orderedList
, table
, commentTag
, indentedBlock
, noteBlock
]
@ -249,27 +248,12 @@ quoteTag = withQuoteContext InDoubleQuote $ blockTag B.blockQuote "quote"
commentTag :: PandocMonad m => MuseParser m (F Blocks)
commentTag = parseHtmlContent "comment" anyChar >> return mempty
-- Indented block is either center, right or quote
indentedLine :: PandocMonad m => MuseParser m (Int, String)
indentedLine = try $ do
indent <- length <$> many1 spaceChar
line <- anyLine
return (indent, line)
rawIndentedBlock :: PandocMonad m => MuseParser m (Int, String)
rawIndentedBlock = try $ do
lns <- many1 indentedLine
let indent = minimum $ map fst lns
return (indent, unlines $ map snd lns)
indentedBlock :: PandocMonad m => MuseParser m (F Blocks)
indentedBlock = try $ do
(indent, raw) <- rawIndentedBlock
contents <- withQuoteContext InDoubleQuote $ parseFromString parseBlocks raw
return $ (if indent >= 2 && indent < 6 then B.blockQuote else id) <$> contents
-- Indented paragraph is either center, right or quote
para :: PandocMonad m => MuseParser m (F Blocks)
para = liftM B.para . trimInlinesF . mconcat <$> many1Till inline endOfParaElement
para = do
indent <- length <$> many spaceChar
let f = if indent >= 2 && indent < 6 then B.blockQuote else id
liftM (f . B.para) . trimInlinesF . mconcat <$> many1Till inline endOfParaElement
where
endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
endOfInput = try $ skipMany blankline >> skipSpaces >> eof

View file

@ -32,7 +32,7 @@ tests =
[ testGroup "Inlines"
[ "Plain String" =:
"Hello, World" =?>
para (spcSep [ "Hello,", "World" ])
para "Hello, World"
, "Emphasis" =: "*Foo bar*" =?> para (emph . spcSep $ ["Foo", "bar"])
@ -102,12 +102,35 @@ tests =
, "5 dashes is a horizontal rule" =: "-----" =?> horizontalRule
, "4 dashes with spaces is a horizontal rule" =: "---- " =?> horizontalRule
]
, testGroup "Paragraphs"
[ "Simple paragraph" =:
T.unlines [ "First line"
, "second line."
] =?>
para "First line second line."
, "Indented paragraph" =:
T.unlines [ " First line"
, "second line."
] =?>
para "First line second line."
-- Emacs Muse starts a blockquote on the second line.
-- We copy Amusewiki behavior and require a blank line to start a blockquote.
, "Indentation in the middle of paragraph" =:
T.unlines [ "First line"
, " second line"
, "third line"
] =?>
para "First line second line third line"
, "Quote" =:
" This is a quotation\n" =?>
blockQuote (para "This is a quotation")
, "Multiline quote" =:
T.unlines [ " This is a quotation"
, " with a continuation"
] =?>
blockQuote (para "This is a quotation with a continuation")
]
, "Quote tag" =: "<quote>Hello, world</quote>" =?> blockQuote (para $ text "Hello, world")
, "Quote" =: " This is a quotation\n" =?> blockQuote (para $ text "This is a quotation")
, "Multiline quote" =: T.unlines [ " This is a quotation"
, " with a continuation"
]
=?> blockQuote (para $ text "This is a quotation with a continuation")
, "Center" =: "<center>Hello, world</center>" =?> para (text "Hello, world")
, "Right" =: "<right>Hello, world</right>" =?> para (text "Hello, world")
, testGroup "Comments"