git.iko.soy/typeable/pandoc
on master help sign in
Remove just one leading and one trailing newline
65047e3fiddlosopher
src/Text/Pandoc/Readers/HTML.hs+11−3
@@ -46,7 +46,7 @@ import Text.Pandoc.Shared
46import Text.Pandoc.CharacterReferences ( characterReference,
46import Text.Pandoc.CharacterReferences ( characterReference,
47 decodeCharacterReferences )
47 decodeCharacterReferences )
48import Data.Maybe ( fromMaybe )
48import Data.Maybe ( fromMaybe )
49−import Data.List ( takeWhile, dropWhile )
49+import Data.List ( takeWhile, dropWhile, isPrefixOf, isSuffixOf )
50import Data.Char ( toUpper, toLower, isAlphaNum )
50import Data.Char ( toUpper, toLower, isAlphaNum )
51
51
52-- | Convert HTML-formatted string to 'Pandoc' document.
52-- | Convert HTML-formatted string to 'Pandoc' document.
@@ -321,8 +321,16 @@ codeBlock = try $ do
321 (many1 (satisfy (/= '<')) <|>
321 (many1 (satisfy (/= '<')) <|>
322 ((anyHtmlTag <|> anyHtmlEndTag) >> return ""))
322 ((anyHtmlTag <|> anyHtmlEndTag) >> return ""))
323 (htmlEndTag "pre")
323 (htmlEndTag "pre")
324− return $ CodeBlock $ stripTrailingNewlines $
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''
325− decodeCharacterReferences $ concat result
333+ return $ CodeBlock $ decodeCharacterReferences result'''
326
334
327--
335--
328-- block quotes
336-- block quotes