Apparently the culprit is the fci
package. A working solution was posted here
For completeness I am copying the code here, but all the credit should go to the author of the gist, @kaushalmodi. Just add this to your .emacs
file.
(use-package htmlize
:defer t
:config
(progn
;; It is required to disable `fci-mode' when `htmlize-buffer' is called;
;; otherwise the invisible fci characters show up as funky looking
;; visible characters in the source code blocks in the html file.
;; http://lists.gnu.org/archive/html/emacs-orgmode/2014-09/msg00777.html
(with-eval-after-load 'fill-column-indicator
(defvar modi/htmlize-initial-fci-state nil
"Variable to store the state of `fci-mode' when `htmlize-buffer' is called.")
(defun modi/htmlize-before-hook-fci-disable ()
(setq modi/htmlize-initial-fci-state fci-mode)
(when fci-mode
(fci-mode -1)))
(defun modi/htmlize-after-hook-fci-enable-maybe ()
(when modi/htmlize-initial-fci-state
(fci-mode 1)))
(add-hook 'htmlize-before-hook #'modi/htmlize-before-hook-fci-disable)
(add-hook 'htmlize-after-hook #'modi/htmlize-after-hook-fci-enable-maybe))
;; `flyspell-mode' also has to be disabled because depending on the
;; theme, the squiggly underlines can either show up in the html file
;; or cause elisp errors like:
;; (wrong-type-argument number-or-marker-p (nil . 100))
(with-eval-after-load 'flyspell
(defvar modi/htmlize-initial-flyspell-state nil
"Variable to store the state of `flyspell-mode' when `htmlize-buffer' is called.")
(defun modi/htmlize-before-hook-flyspell-disable ()
(setq modi/htmlize-initial-flyspell-state flyspell-mode)
(when flyspell-mode
(flyspell-mode -1)))
(defun modi/htmlize-after-hook-flyspell-enable-maybe ()
(when modi/htmlize-initial-flyspell-state
(flyspell-mode 1)))
(add-hook 'htmlize-before-hook #'modi/htmlize-before-hook-flyspell-disable)
(add-hook 'htmlize-after-hook #'modi/htmlize-after-hook-flyspell-enable-maybe))))
C-h C
nil
to find out. Also, what line endings are you using. Are there any extra characters (as far as you can tell) after the closing)
? Can you open the html file and view inhexl-mode
to see what characters those are?utf-8
. The characters added at the end (in thehtml
file) are
e.g.:<span style="color: #51afef;">import</span> seaborn <span style="color: #51afef;">as</span> sns