git.iko.soy/typeable/pandoc
on master help sign in
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

commit65047e354ac574127f190b08d7d7b371e4ed9538 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateMon 17 Sep 2007, 03:08 (19 years ago) parent6f16d52
1 file changed+11−3
src/Text/Pandoc/Readers/HTML.hs+11−3
src/Text/Pandoc/Readers/HTML.hs+11−3
@@ -46,7 +46,7 @@ import Text.Pandoc.Shared
4646import Text.Pandoc.CharacterReferences ( characterReference,
4747 decodeCharacterReferences )
4848import Data.Maybe ( fromMaybe )
49−import Data.List ( takeWhile, dropWhile )
49+import Data.List ( takeWhile, dropWhile, isPrefixOf, isSuffixOf )
5050import Data.Char ( toUpper, toLower, isAlphaNum )
5151
5252-- | Convert HTML-formatted string to 'Pandoc' document.
@@ -321,8 +321,16 @@ codeBlock = try $ do
321321 (many1 (satisfy (/= '<')) <|>
322322 ((anyHtmlTag <|> anyHtmlEndTag) >> return ""))
323323 (htmlEndTag "pre")
324− return $ CodeBlock $ stripTrailingNewlines $
325− decodeCharacterReferences $ concat result
324+ let result' = concat result
325+ -- drop leading newline if any
326+ let result'' = if "\n" `isPrefixOf` result'
327+ then drop 1 result'
328+ else result'
329+ -- drop trailing newline if any
330+ let result''' = if "\n" `isSuffixOf` result''
331+ then init result''
332+ else result''
333+ return $ CodeBlock $ decodeCharacterReferences result'''
326334
327335--
328336-- block quotes