From 8671bc5a1be38f6555e34d7ccc542ebbe91f69fd Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sat, 5 Dec 2009 05:33:24 +0000 Subject: [PATCH] Markdown reader: Treat a backslash followed by a newline as hard linebreak. Resolves Issue #154. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1646 788f1e2b-df1e-0410-8736-df70ead52e1b --- README | 9 ++++++++- changelog | 5 +++++ src/Text/Pandoc/Readers/Markdown.hs | 8 ++++---- tests/markdown-reader-more.native | 4 +++- tests/markdown-reader-more.txt | 5 +++++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/README b/README index 10dc66cc5..c1fd7cbde 100644 --- a/README +++ b/README @@ -463,7 +463,14 @@ which allows only the following characters to be backslash-escaped: \`*_{}[]()>#+-.! A backslash-escaped space is parsed as a nonbreaking space. It will -appear in TeX output as '~' and in HTML and XML as '\ ' or '\ '. +appear in TeX output as '`~`' and in HTML and XML as '`\ `' or +'`\ `'. + +A backslash-escaped newline (i.e. a backslash occurring at the end of +a line) is parsed as a hard line break. It will appear in TeX output as +'`\\`' and in HTML as '`
`'. This is a nice alternative to +markdown's "invisible" way of indicating hard line breaks using +two trailing spaces on a line. Subscripts and superscripts --------------------------- diff --git a/changelog b/changelog index c3d46f782..2f726f90c 100644 --- a/changelog +++ b/changelog @@ -15,6 +15,11 @@ pandoc (1.3) to use for indented code blocks. (Thanks to buttock for the patch; resolves Issue #87.) + * Treat a backslash followed by a newline as a hard line break + in markdown. Resolves Issue #154. This is a nice alternative + to markdown's "invisible" way of indicating hardline breaks + using lines that end with two spaces. + * Improved performance of markdown reader by ~10% by eliminating the need for a separate parsing pass for notes. Raw notes are now stored on the first pass (which parses diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 4f0d1b6ad..c6926e3c1 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -863,10 +863,10 @@ escapedChar = do result <- option '\\' $ if stateStrict state then oneOf "\\`*_{}[]()>#+-.!~" else satisfy (not . isAlphaNum) - let result' = if result == ' ' - then '\160' -- '\ ' is a nonbreaking space - else result - return $ Str [result'] + return $ case result of + ' ' -> Str "\160" -- "\ " is a nonbreaking space + '\n' -> LineBreak -- "\[newline]" is a linebreak + _ -> Str [result] ltSign :: GenParser Char ParserState Inline ltSign = do diff --git a/tests/markdown-reader-more.native b/tests/markdown-reader-more.native index 0e76ace86..e6665591a 100644 --- a/tests/markdown-reader-more.native +++ b/tests/markdown-reader-more.native @@ -19,5 +19,7 @@ Pandoc (Meta [] [] "") , Header 2 [Str "Commented",Str "-",Str "out",Space,Str "list",Space,Str "item"] , BulletList [ [ Plain [Str "one"] - , RawHtml "" ], [ Plain [Str "three"] ] ] ] + , RawHtml "" ], [ Plain [Str "three"] ] ] +, Header 2 [Str "Backslash",Space,Str "newline"] +, Para [Str "hi",LineBreak,Str "there"] ] diff --git a/tests/markdown-reader-more.txt b/tests/markdown-reader-more.txt index 02b425e11..4689ee84a 100644 --- a/tests/markdown-reader-more.txt +++ b/tests/markdown-reader-more.txt @@ -59,3 +59,8 @@ $\$2 + \$3$ --> - three +## Backslash newline + +hi\ +there +