diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-09-17 03:08:14 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-09-17 03:08:14 +0000 |
commit | 65047e354ac574127f190b08d7d7b371e4ed9538 (patch) | |
tree | 30afe0ff554b04739202fb6cdb6e21f5be272931 /src/Text | |
parent | 6f16d52c1185fea757047374100a9f10be7af3fc (diff) | |
download | pandoc-65047e354ac574127f190b08d7d7b371e4ed9538.tar.gz |
Remove just one leading and one trailing newline
from contents of <pre>...</pre> in codeBlock parser.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@1023 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Readers/HTML.hs | 14 |
1 files changed, 11 insertions, 3 deletions
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 |