aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-01-13 11:14:50 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-01-13 11:15:31 -0800
commit5c067bb457a96d8c7c35c9e1ca114169a02c1d2d (patch)
treef4ea9be0e6f1381b25787c7e92c75b9e92fb8242
parent5ecadd7bfac0fea7b4269822b82aacf63fb192be (diff)
downloadpandoc-5c067bb457a96d8c7c35c9e1ca114169a02c1d2d.tar.gz
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.
-rw-r--r--src/Text/Pandoc/Readers/RST.hs11
-rw-r--r--tests/Tests/Readers/RST.hs4
-rw-r--r--tests/rst-reader.native4
-rw-r--r--tests/rst-reader.rst2
4 files changed, 13 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index cc8293132..5f6850148 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -206,16 +206,21 @@ lineBlockLine = try $ do
char '|'
char ' ' <|> lookAhead (char '\n')
white <- many spaceChar
- line <- many $ (notFollowedBy newline >> inline) <|> (try $ endline >>~ char ' ')
+ line <- many1 $ (notFollowedBy newline >> inline) <|> (try $ endline >>~ char ' ')
optional endline
return $ if null white
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 = try $ do
lines' <- many1 lineBlockLine
- blanklines
+ skipMany1 $ blankline <|> try (char '|' >> blankline)
return $ B.para (mconcat $ intersperse B.linebreak lines')
--
diff --git a/tests/Tests/Readers/RST.hs b/tests/Tests/Readers/RST.hs
index fdce7c8f6..0ad21f224 100644
--- a/tests/Tests/Readers/RST.hs
+++ b/tests/Tests/Readers/RST.hs
@@ -18,8 +18,8 @@ infix 4 =:
tests :: [Test]
tests = [ "line block with blank line" =:
- "| a\n|\n| b" =?> para (str "a" <> linebreak <>
- linebreak <> str " " <> str "b")
+ "| a\n|\n| b" =?> para (str "a") <>
+ para (str "\160b")
, "field list" =:
[_LIT|
:Hostname: media08
diff --git a/tests/rst-reader.native b/tests/rst-reader.native
index e4419dd13..895d06d69 100644
--- a/tests/rst-reader.native
+++ b/tests/rst-reader.native
@@ -232,8 +232,8 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite",Str ":
,Para [Str "Another",Space,Str "paragraph"]
,Para [Str "A",Space,Str "third",Space,Str "paragraph"]
,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 "Continuation",Space,Str "line",LineBreak,Str " and",Space,Str "another"]
+,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 "\160\160and",Space,Str "another"]
,Header 1 ("",[],[]) [Str "Simple",Space,Str "Tables"]
,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0]
[[Plain [Str "col",Space,Str "1"]]
diff --git a/tests/rst-reader.rst b/tests/rst-reader.rst
index 14f57da18..970ab4d4a 100644
--- a/tests/rst-reader.rst
+++ b/tests/rst-reader.rst
@@ -454,7 +454,7 @@ Line blocks
| or not to be an entire bee,
| when half the bee is not a bee,
| due to some ancient injury?
-
+|
| Continuation
line
| and