From af7e78243682ec7c353dd202590c45c734f86ada Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 12 Dec 2015 09:31:51 -0800 Subject: [PATCH] Modified readers to emit SoftBreak when appropriate. --- src/Text/Pandoc/Readers/CommonMark.hs | 2 +- src/Text/Pandoc/Readers/HTML.hs | 5 ++++- src/Text/Pandoc/Readers/LaTeX.hs | 12 +++++++++--- src/Text/Pandoc/Readers/MediaWiki.hs | 3 ++- src/Text/Pandoc/Readers/Org.hs | 2 +- src/Text/Pandoc/Readers/RST.hs | 2 +- src/Text/Pandoc/Readers/Txt2Tags.hs | 2 +- stack.yaml | 2 +- tests/testsuite.native | 2 +- tests/writer.docbook | 2 +- tests/writer.dokuwiki | 2 +- tests/writer.html | 2 +- tests/writer.mediawiki | 2 +- tests/writer.textile | 2 +- 14 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/Text/Pandoc/Readers/CommonMark.hs b/src/Text/Pandoc/Readers/CommonMark.hs index 7f752c446..71c7d05b2 100644 --- a/src/Text/Pandoc/Readers/CommonMark.hs +++ b/src/Text/Pandoc/Readers/CommonMark.hs @@ -103,7 +103,7 @@ addInline (Node _ (TEXT t) _) = (map toinl clumps ++) toinl (' ':_) = Space toinl xs = Str xs addInline (Node _ LINEBREAK _) = (LineBreak :) -addInline (Node _ SOFTBREAK _) = (Space :) +addInline (Node _ SOFTBREAK _) = (SoftBreak :) addInline (Node _ (INLINE_HTML t) _) = (RawInline (Format "html") (unpack t) :) addInline (Node _ (CODE t) _) = diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index 85e9a0743..a34e2fb5c 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -799,7 +799,10 @@ pBad = do return $ B.str [c'] pSpace :: InlinesParser Inlines -pSpace = many1 (satisfy isSpace) >> return B.space +pSpace = many1 (satisfy isSpace) >>= \xs -> + if '\n' `elem` xs + then return B.softbreak + else return B.space -- -- Constants diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 6500cb29f..5a4612862 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -100,8 +100,13 @@ dimenarg = try $ do return $ ch ++ num ++ dim sp :: LP () -sp = skipMany1 $ satisfy (\c -> c == ' ' || c == '\t') - <|> try (newline <* lookAhead anyChar <* notFollowedBy blankline) +sp = whitespace <|> endline + +whitespace :: LP () +whitespace = skipMany1 $ satisfy (\c -> c == ' ' || c == '\t') + +endline :: LP () +endline = try (newline >> lookAhead anyChar >> notFollowedBy blankline) isLowerHex :: Char -> Bool isLowerHex x = x >= '0' && x <= '9' || x >= 'a' && x <= 'f' @@ -196,7 +201,8 @@ singleQuote = do inline :: LP Inlines inline = (mempty <$ comment) - <|> (space <$ sp) + <|> (space <$ whitespace) + <|> (softbreak <$ endline) <|> inlineText <|> inlineCommand <|> inlineEnvironment diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs index 24b3f5c7e..e423720df 100644 --- a/src/Text/Pandoc/Readers/MediaWiki.hs +++ b/src/Text/Pandoc/Readers/MediaWiki.hs @@ -555,7 +555,8 @@ inlineHtml :: MWParser Inlines inlineHtml = B.rawInline "html" . snd <$> htmlTag isInlineTag' whitespace :: MWParser Inlines -whitespace = B.space <$ (skipMany1 spaceChar <|> endline <|> htmlComment) +whitespace = B.space <$ (skipMany1 spaceChar <|> htmlComment) + <|> B.softbreak <$ endline endline :: MWParser () endline = () <$ try (newline <* diff --git a/src/Text/Pandoc/Readers/Org.hs b/src/Text/Pandoc/Readers/Org.hs index 3be47cfd4..99a6927e2 100644 --- a/src/Text/Pandoc/Readers/Org.hs +++ b/src/Text/Pandoc/Readers/Org.hs @@ -1103,7 +1103,7 @@ endline = try $ do decEmphasisNewlinesCount guard =<< newlinesCountWithinLimits updateLastPreCharPos - return . return $ B.space + return . return $ B.softbreak cite :: OrgParser (F Inlines) cite = try $ do diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 0e5bb2a87..85f34d9d8 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -1098,7 +1098,7 @@ endline = try $ do then notFollowedBy (anyOrderedListMarker >> spaceChar) >> notFollowedBy' bulletListStart else return () - return B.space + return B.softbreak -- -- links diff --git a/src/Text/Pandoc/Readers/Txt2Tags.hs b/src/Text/Pandoc/Readers/Txt2Tags.hs index 58841f2ce..c28ce1653 100644 --- a/src/Text/Pandoc/Readers/Txt2Tags.hs +++ b/src/Text/Pandoc/Readers/Txt2Tags.hs @@ -550,7 +550,7 @@ endline = try $ do notFollowedBy quote notFollowedBy list notFollowedBy table - return $ B.space + return $ B.softbreak str :: T2T Inlines str = try $ do diff --git a/stack.yaml b/stack.yaml index 5eb4609d4..d034f7265 100644 --- a/stack.yaml +++ b/stack.yaml @@ -9,7 +9,7 @@ packages: - '.' - location: git: 'https://github.com/jgm/pandoc-types' - commit: c46ab17eb17e16c3401a4ed48fc93e034a92b850 + commit: 8aba9332f56fd23bc3c06065193abe5ace3e70b4 extra-dep: true - location: git: 'https://github.com/jgm/texmath' diff --git a/tests/testsuite.native b/tests/testsuite.native index c887e5467..fa234dfc2 100644 --- a/tests/testsuite.native +++ b/tests/testsuite.native @@ -260,7 +260,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa ,Div ("",[],[]) [Div ("",[],[]) [Div ("",[],[]) - [Plain [Str "foo",SoftBreak]]]] + [Plain [Str "foo"]]]] ,Para [Str "This",Space,Str "should",Space,Str "just",Space,Str "be",Space,Str "an",Space,Str "HTML",Space,Str "comment:"] ,RawBlock (Format "html") "" ,Para [Str "Multiline:"] diff --git a/tests/writer.docbook b/tests/writer.docbook index f4491c932..eee19cdd9 100644 --- a/tests/writer.docbook +++ b/tests/writer.docbook @@ -912,7 +912,7 @@ These should not be escaped: \$ \\ \> \[ \{ Now, nested: - foo + foo This should just be an HTML comment: diff --git a/tests/writer.dokuwiki b/tests/writer.dokuwiki index 92569a30f..fe1f8296a 100644 --- a/tests/writer.dokuwiki +++ b/tests/writer.dokuwiki @@ -350,7 +350,7 @@ As should this: Now, nested: -foo +foo diff --git a/tests/writer.html b/tests/writer.html index 10536b714..4a60a7b97 100644 --- a/tests/writer.html +++ b/tests/writer.html @@ -362,7 +362,7 @@ And this is strong
-foo +foo
diff --git a/tests/writer.mediawiki b/tests/writer.mediawiki index af3df65f9..066606c00 100644 --- a/tests/writer.mediawiki +++ b/tests/writer.mediawiki @@ -374,7 +374,7 @@ Now, nested:
-foo +foo
diff --git a/tests/writer.textile b/tests/writer.textile index 01bfae79a..293418ed5 100644 --- a/tests/writer.textile +++ b/tests/writer.textile @@ -424,7 +424,7 @@ Now, nested:
-foo +foo