What did you expect to happen?
Exporting source blocks with org-mode and babel to HTML should just work, with formatting of source code as shown in org file
What actually happened?
The exported source blocks have newlines before every change of text colour (i.e. before every span).
The exported html code gets transformed, presumably by the auto-formatted, from:
<pre class="src">
some_function(<span style="color: #50a14f;">"string"</span>)
</pre>
to
<pre class="src">
some_function(
<span style="color: #50a14f;">"string"</span>)
</pre>
This breaks formatting, causing a line break before every change of colour in the source output.
This seems to be due to a known issue in html-tidy:
https://github.com/htacg/tidy-html5/tree/release/5.6
Are there actions that need to be taken in doom? A check in doom doctor? Or disable auto-formatting during html output?
It isn't clear to me what the best choice might be.
It seems format-all is overzealously reformatting those HTML buffers. See if any of the following solve your issue (try them separately):
;; add either of these to ~/.doom.d/config.el
(defadvice! inhibit-formatting-while-exporting (&rest _)
:before-while #'+format-probe-a
(not (bound-and-true-p org-export-current-backend)))
;; or
(defadvice! inhibit-formatting-while-exporting (&rest _)
:before-while #'+format-buffer-a
(not (bound-and-true-p org-export-current-backend)))
As of 4c61f22 the auto formatter will no longer kick in in temporary or special buffers, only file buffers. Let me know if that doesn't resolve your issue and I'll reopen it. Thanks for bringing it to my attention!
Sorry to be the bearer of bad news.
I don't think this works, I think I may in fact have just had the format module off when I tested it. Sorry!
After some digging with edebug, I think I've got an idea of what might be going wrong.
When exporting to file, the org-export-to-file function is used, which writes the outputs to filw with the lines:
(with-temp-buffer
(insert output)
(let ((coding-system-for-write ',encoding))
(write-file ,file)))
The files is being saved with write-file, and in the save hook the +format-probe-a is being called function. But inside that function, current buffer is set to the name of the .html, and tests for a temp or special buffer return nil.
Traceback for call to +format-probe-a is:
_(at this point, (current-buffer) is "analysis-of-regions.html")
...
format-all--probe()
format-all-buffer--from-hook()
run-hooks(before-save-hook)
basic-save-buffer(nil)
save-buffer()
write-file("analysis-of-regions.html")
(let ((coding-system-for-write encoding)) (write-file file))
(progn (insert output) (let ((coding-system-for-write encoding)) (write-file file)))
(unwind-protect (progn (insert output) (let ((coding-system-for-write encoding)) (write-file file))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))
(save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert output) (let ((coding-system-for-write encoding)) (write-file file))) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))
(let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer)
...
org-export-to-file(html "analysis-of-regions.html" nil nil nil nil nil)
The files is being saved with write-file, and in the save hook the +format-probe-a is being called function. But inside that function, current buffer is set to the name of the .html, and tests for a temp or special buffer return nil.
This might be considered a bug with Emacs or org: should write-file invoke before-save-hook and after-save-hook? It uses save-buffer under the hood, so it does, but write-region doesn't. Why should write-file? write-file should be the programmatic way to write to files; it triggering save hooks doesn't make sense to me.
Otherwise, why is org-export-to-file using write-file, which could trigger save hooks? Why not use write-region instead?
In any case, I've inhibited save hooks in org-export-to-file as of d5d0fb9, which should resolve this issue for now.
I'll keep this open until it is addressed upstream.
Most helpful comment
As of 4c61f22 the auto formatter will no longer kick in in temporary or special buffers, only file buffers. Let me know if that doesn't resolve your issue and I'll reopen it. Thanks for bringing it to my attention!