jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.91k stars 3.39k forks source link

All newlines in code blocks seem to be prefixed with ~11 spaces #3391

Closed schell closed 7 years ago

schell commented 7 years ago

I'm going from markdown and literate haskell to html and it seems that all my code blocks end up misaligned due to some extra indentation. For example the following markdown

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.haskell}
runFreeType :: IO FT_Error -> IO ()
runFreeType m = do
    r <- m
    unless (r == 0) $ fail $ "FreeType Error:" ++ show r
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

produces this output

<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">runFreeType ::</span> <span class="dt">IO</span> <span class="dt">FT_Error</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()
            runFreeType m <span class="fu">=</span> <span class="kw">do</span>
                r <span class="ot">&lt;-</span> m
                unless (r <span class="fu">==</span> <span class="dv">0</span>) <span class="fu">$</span> fail <span class="fu">$</span> <span class="st">"FreeType Error:"</span> <span class="fu">++</span> show r</code></pre></div>

which ends up looking like

screenshot 2017-01-28 11 56 07

I think the issue is in the writer, as when I inspect the read block, I see

CodeBlock ("",["haskell"],[]) "runFreeType :: IO FT_Error -> IO ()\nrunFreeType m = do\n    r <- m\n    unless (r == 0) $ fail $ \"FreeType Error:\" ++ show r"

I'm writing the document using

\pandoc ->
let opts  = def{ writerExtensions = allMyPandocExtensions <> pandocExtensions
                   , writerHighlight = True
                   , writerHtml5 = True
                  -- , writerHighlightStyle = zenburn
                   , writerStandalone = False
                   }
in writeHtmlString opts pandoc

where

allMyPandocExtensions :: S.Set Extension
allMyPandocExtensions = S.fromList [ Ext_link_attributes
                                   , Ext_mmd_link_attributes
                                   , Ext_literate_haskell
                                   ]
schell commented 7 years ago

Actually it looks like the output of writeHtmlString is fine, it produces the newlines that are expected. I've tracked the problem further down my pipeline, where I take that string and use it as the body variable in a template that is being compiled with renderTemplate.

jgm commented 7 years ago

I can't reproduce this. Can you send output of pandoc --version, plus information about how you installed pandoc (from source, from a binary package, etc.)?

And, can you reproduce this with command line pandoc, or only with the Haskell program? If you can reproduce it with the pandoc command, please send the exact command used.

jgm commented 7 years ago

+++ Schell Carl Scivally [Jan 28 17 12:32 ]:

Actually it looks like the output of writeHtmlString is fine, it produces the newlines that are expected. I've tracked the problem further down my pipeline, where I take that string and use it as the body variable in a template that is being compiled with renderTemplate.

Ah, okay. Well, then, the issue is that the template rendering respects indentation. Put the variable for the code flush with the left margin.

schell commented 7 years ago

Wow! Magic! Thank you, I didn't think about that.