RST reader: Line block improvements.

* Use nonbreaking spaces for initial indent (otherwise lost in HTML and
  LaTeX).
* Allow multiple paragraphs in a single line block.
This commit is contained in:
John MacFarlane 2013-01-13 11:14:50 -08:00
parent 5ecadd7bfa
commit 5c067bb457
4 changed files with 13 additions and 8 deletions

View file

@ -206,16 +206,21 @@ lineBlockLine = try $ do
char '|' char '|'
char ' ' <|> lookAhead (char '\n') char ' ' <|> lookAhead (char '\n')
white <- many spaceChar white <- many spaceChar
line <- many $ (notFollowedBy newline >> inline) <|> (try $ endline >>~ char ' ') line <- many1 $ (notFollowedBy newline >> inline) <|> (try $ endline >>~ char ' ')
optional endline optional endline
return $ if null white return $ if null white
then mconcat line then mconcat line
else B.str white <> mconcat line else B.str (spToNbsp white) <> mconcat line
spToNbsp :: String -> String
spToNbsp (' ':xs) = '\160' : spToNbsp xs
spToNbsp (x:xs) = x : spToNbsp xs
spToNbsp [] = ""
lineBlock :: RSTParser Blocks lineBlock :: RSTParser Blocks
lineBlock = try $ do lineBlock = try $ do
lines' <- many1 lineBlockLine lines' <- many1 lineBlockLine
blanklines skipMany1 $ blankline <|> try (char '|' >> blankline)
return $ B.para (mconcat $ intersperse B.linebreak lines') return $ B.para (mconcat $ intersperse B.linebreak lines')
-- --

View file

@ -18,8 +18,8 @@ infix 4 =:
tests :: [Test] tests :: [Test]
tests = [ "line block with blank line" =: tests = [ "line block with blank line" =:
"| a\n|\n| b" =?> para (str "a" <> linebreak <> "| a\n|\n| b" =?> para (str "a") <>
linebreak <> str " " <> str "b") para (str "\160b")
, "field list" =: , "field list" =:
[_LIT| [_LIT|
:Hostname: media08 :Hostname: media08

View file

@ -232,8 +232,8 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite",Str ":
,Para [Str "Another",Space,Str "paragraph"] ,Para [Str "Another",Space,Str "paragraph"]
,Para [Str "A",Space,Str "third",Space,Str "paragraph"] ,Para [Str "A",Space,Str "third",Space,Str "paragraph"]
,Header 1 ("",[],[]) [Str "Line",Space,Str "blocks"] ,Header 1 ("",[],[]) [Str "Line",Space,Str "blocks"]
,Para [Str "But",Space,Str "can",Space,Str "a",Space,Str "bee",Space,Str "be",Space,Str "said",Space,Str "to",Space,Str "be",LineBreak,Str " or",Space,Str "not",Space,Str "to",Space,Str "be",Space,Str "an",Space,Str "entire",Space,Str "bee,",LineBreak,Str " when",Space,Str "half",Space,Str "the",Space,Str "bee",Space,Str "is",Space,Str "not",Space,Str "a",Space,Str "bee,",LineBreak,Str " due",Space,Str "to",Space,Str "some",Space,Str "ancient",Space,Str "injury?"] ,Para [Str "But",Space,Str "can",Space,Str "a",Space,Str "bee",Space,Str "be",Space,Str "said",Space,Str "to",Space,Str "be",LineBreak,Str "\160\160\160\160or",Space,Str "not",Space,Str "to",Space,Str "be",Space,Str "an",Space,Str "entire",Space,Str "bee,",LineBreak,Str "\160\160\160\160\160\160\160\160when",Space,Str "half",Space,Str "the",Space,Str "bee",Space,Str "is",Space,Str "not",Space,Str "a",Space,Str "bee,",LineBreak,Str "\160\160\160\160\160\160\160\160\160\160\160\160due",Space,Str "to",Space,Str "some",Space,Str "ancient",Space,Str "injury?"]
,Para [Str "Continuation",Space,Str "line",LineBreak,Str " and",Space,Str "another"] ,Para [Str "Continuation",Space,Str "line",LineBreak,Str "\160\160and",Space,Str "another"]
,Header 1 ("",[],[]) [Str "Simple",Space,Str "Tables"] ,Header 1 ("",[],[]) [Str "Simple",Space,Str "Tables"]
,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0] ,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0]
[[Plain [Str "col",Space,Str "1"]] [[Plain [Str "col",Space,Str "1"]]

View file

@ -454,7 +454,7 @@ Line blocks
| or not to be an entire bee, | or not to be an entire bee,
| when half the bee is not a bee, | when half the bee is not a bee,
| due to some ancient injury? | due to some ancient injury?
|
| Continuation | Continuation
line line
| and | and