From 65047e354ac574127f190b08d7d7b371e4ed9538 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Mon, 17 Sep 2007 03:08:14 +0000 Subject: Remove just one leading and one trailing newline from contents of
...
in codeBlock parser. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1023 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Readers/HTML.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs index 69ce97eff..70a071152 100644 --- a/src/Text/Pandoc/Readers/HTML.hs +++ b/src/Text/Pandoc/Readers/HTML.hs @@ -46,7 +46,7 @@ import Text.Pandoc.Shared import Text.Pandoc.CharacterReferences ( characterReference, decodeCharacterReferences ) import Data.Maybe ( fromMaybe ) -import Data.List ( takeWhile, dropWhile ) +import Data.List ( takeWhile, dropWhile, isPrefixOf, isSuffixOf ) import Data.Char ( toUpper, toLower, isAlphaNum ) -- | Convert HTML-formatted string to 'Pandoc' document. @@ -321,8 +321,16 @@ codeBlock = try $ do (many1 (satisfy (/= '<')) <|> ((anyHtmlTag <|> anyHtmlEndTag) >> return "")) (htmlEndTag "pre") - return $ CodeBlock $ stripTrailingNewlines $ - decodeCharacterReferences $ concat result + let result' = concat result + -- drop leading newline if any + let result'' = if "\n" `isPrefixOf` result' + then drop 1 result' + else result' + -- drop trailing newline if any + let result''' = if "\n" `isSuffixOf` result'' + then init result'' + else result'' + return $ CodeBlock $ decodeCharacterReferences result''' -- -- block quotes -- cgit v1.2.3