git.iko.soy/typeable/pandoc
on master help sign in
HTML writer: In code blocks, change leading newlines to <br /> tags.

(Some browsers ignore them.) Resolves Issue #71. See http://six.pairlist.net/pipermail/markdown-discuss/2008-May/001297.html git-svn-id: https://pandoc.googlecode.com/svn/trunk@1277 788f1e2b-df1e-0410-8736-df70ead52e1b

commit69c2bde7d999e689f89aee2203ad1923c7a24037 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 15 May 2008, 00:54 (18 years ago) parent6a46ffc
1 file changed+8−4
Text/Pandoc/Writers/HTML.hs+8−4
Text/Pandoc/Writers/HTML.hs+8−4
@@ -273,10 +273,14 @@ blockToHtml opts (RawHtml str) = return $ primHtml str
273273blockToHtml opts (HorizontalRule) = return $ hr
274274blockToHtml opts (CodeBlock attr@(_,classes,_) rawCode) = do
275275 case highlightHtml attr rawCode of
276− Left _ -> return $ pre ! (if null classes
277− then []
278− else [theclass $ unwords classes]) $ thecode <<
279− (rawCode ++ "\n")
276+ Left _ -> -- change leading newlines into <br /> tags, because some
277+ -- browsers ignore leading newlines in pre blocks
278+ let (leadingBreaks, rawCode') = span (=='\n') rawCode
279+ in return $ pre ! (if null classes
280+ then []
281+ else [theclass $ unwords classes]) $ thecode <<
282+ (replicate (length leadingBreaks) br +++
283+ [stringToHtml $ rawCode' ++ "\n"])
280284 Right h -> addToCSS defaultHighlightingCss >> return h
281285blockToHtml opts (BlockQuote blocks) =
282286 -- in S5, treat list in blockquote specially