hniksic / emacs-htmlize Goto Github PK
View Code? Open in Web Editor NEWConvert buffer text and decorations to HTML.
Convert buffer text and decorations to HTML.
This comparison shows emacs 29 (current git) with ediff that uses ediff-odd-diff-A
face which defaults to:
Face: ediff-odd-diff-A (sample) (customize this face)
Documentation:
Face for highlighting odd-numbered non-current differences in buffer A.
Defined in ‘ediff-init.el’.
Family: unspecified
Foundry: unspecified
Width: unspecified
Height: unspecified
Weight: unspecified
Slant: unspecified
Foreground: unspecified
DistantForeground: unspecified
Background: #3e3e5e
Underline: unspecified
Overline: unspecified
Strike-through: unspecified
Box: unspecified
Inverse: unspecified
Stipple: unspecified
Font: unspecified
Fontset: unspecified
Extend: t
Inherit: unspecified
(require 'loadhist)
(file-dependents (feature-file 'cl))
Shows that htmlize/htmlize.elc depends on cl which is deprecated in emacs 27.
EDIT: I made I typo on (feature-file 'htmlize)
, it was cl
Hi, I'm seeing this exact same issue as #6 and am not able to resolve it by restarting emacs, or any other means. I am able to call html-buffer
just fine, however htmlize-region
always fails with that exact same error.
Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p (nil . 100))
<((nil . 100) 99)
#[514 "\300 �! �!\"\207" [< cl-key] 6 "\n\n(fn CL-X CL-Y)"](#<overlay from 50652 to 51034 in BrandController.scala> #<overlay from 50652 to 51034 in BrandController.scala>)
sort((#<overlay from 50652 to 51034 in BrandController.scala>) #[514 "\300 �! �!\"\207" [< cl-key] 6 "\n\n(fn CL-X CL-Y)"])
cl-sort((#<overlay from 50652 to 51034 in BrandController.scala>) < :key #[257 "\300�\301\"\206\302\207" [overlay-get priority 0] 4 "\n\n(fn O)"]))
stable-sort((#<overlay from 50652 to 51034 in BrandController.scala>) < :key #[257 "\300�\301\"\206�\302\207" [overlay-get priority 0] 4 "\n\n(fn O)"])
htmlize-faces-at-point()
htmlize-buffer-1()
htmlize-region(50652 51034)
funcall-interactively(htmlize-region 50652 51034)
call-interactively(htmlize-region record nil)
command-execute(htmlize-region record)
#[257 "\304\305!\203\f
I've only just used htmlize for the first time, and simply calling htmlize-region
interactively is failing for me. I tried it on files of different types and sizes and it continues to fail.
I've narrowed this problem down the following lines: https://github.com/hniksic/emacs-htmlize/blob/master/htmlize.el#L1383-L1389
If I comment them out, then this function runs perfectly.
Thanks!
@hniksic , @yantar92 , @tarsius :
This issue affects both melpa-stable
as well as nongnu
ELPA. The latest
version available on both is 1.56, from three years ago. Since then, a fix for
issue #49 has been merged which fixes an issue when exporting SVG images.
As noted in #36 , while melpa-stable
uses tagged commits, nongnu
ELPA uses
commits that increment the version tag in the package header to identify new
(stable) versions.
Could version 1.57
be released and made available (preferably on both, but
even if only on melpa-stable
it would be okay)?
Hello,
Recently this discussion came up on Emacs help and Org mode mailing lists: https://lists.gnu.org/r/emacs-orgmode/2018-09/msg00110.html
Currently Org mode suggests users to download your awesome htmlize package from GitHub so that ox-html
can export proper syntax highlighted code blocks.
While I don't mind that (and I already use htmlize
), there are some people who wouldn't prefer that?
Do you have an objection to assigning your copyright to FSF? With that in place, this package can be a part of Emacs/Org mode, and resolve the issue discussed in that mailing list thread.
If interested, please email [email protected] for instructions with this assignment process (I've done it, and it's very easy).
If I run htmlize-{buffer,file}
on any of my files, the result has no syntax highlighting.
Additionally, if I turn on debug-on-error
I find the following
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
string-match("[\11\n]" nil 0)
htmlize-untabify-string(nil 0)
htmlize-extract-text(1 2 nil)
...
htmlize-buffer-1()
htmlize-region(1 1817)
org-html-htmlize-region-for-paste(1 1817)
Here's an example output: colophon.zip
I use Emacs27.1 with Doom, which uses the latest version of Htmlize, and does not appear to modify the settings/behaviour.
Following up from https://list.orgmode.org/87il9hpx0b.fsf@localhost/T/#u
CC: @hniksic @tarsius
As discussed, let see how we can provide write access to the repo.
The following lisp-code creates a buffer *test*
with an embedded svg image data.
If htmlize-untabify
is t, then the image appears as replacement for every tab in the HTML file generated with htmlize-buffer
– three times overall.
This is because htmlize-untabify-string
accidently puts the display property
with the image on the corresponding table entry in htmlize-tab-spaces
.
(with-current-buffer (get-buffer-create "*test*")
(let (b e)
(erase-buffer)
(insert "\t Text before\n\t")
(setq b (point))
(insert (propertize "bold\n" 'face 'bold)
(propertize "\titalic\n" 'face 'italic))
(setq e (point))
(insert "\n\tText after")
(let ((ol (make-overlay b e)))
(overlay-put
ol
'display
(create-image
"<svg height=\"140\" width=\"500\" xmlns=\"http://www.w3.org/2000/svg\">
<ellipse rx=\"100\" ry=\"50\" cx=\"120\" cy=\"80\"
style=\"fill:yellow;stroke:green;stroke-width:3\" />
</svg>"
'svg
t)))))
Hi, I was wondering if you could figure out why I might be getting the following error when I call htmlize-region:
Wrong type argument: number-or-marker-p, (nil . 100)
I toggled debug-on-error
and I got the following backtrace which shows that the parameters to the sort
function are wrong but I couldn't really see how to fix this wrong key that is being fed to the sort function
debug(error (wrong-type-argument number-or-marker-p (nil . 100)))
<((nil . 100) 110)
#[514 "\300 �! �!\"\207" [< cl-key] 6 "\n\n(fn CL-X CL-Y)"](#<overlay from 1 to 1087 in benchmark.py> #<overlay from 1 to 7 in benchmark.py>)
sort((#<overlay from 1 to 7 in benchmark.py>) #[514 "\300 �! �!\"\207" [< cl-key] 6 "\n\n(fn CL-X CL-Y)"])
cl-sort((#<overlay from 1 to 7 in benchmark.py>) < :key #[257 "\300�\301\"\206��\302\207" [overlay-get priority 0] 4 "\n\n(fn O)"])
apply(cl-sort (#<overlay from 1 to 7 in benchmark.py>) < (:key #[257 "\300�\301\"\206��\302\207" [overlay-get priority 0] 4 "\n\n(fn O)"]))
stable-sort((#<overlay from 1 to 7 in benchmark.py>) < :key #[257 "\300�\301\"\206��\302\207" [overlay-get priority 0] 4 "\n\n(fn O)"])
htmlize-faces-at-point()
htmlize-buffer-1()
htmlize-region(1 1087)
funcall-interactively(htmlize-region 1 1087)
call-interactively(htmlize-region record nil)
The above error happens when I try to run org-html-export-to-html in org-mode in htmlize-20180317.1549.
There is not issue when I use version 1.51.
Hi,
I have a problem with htmlize. If I open I simple text file, and try to run htmlize on it, I have the following error:
------->8-------------8<--------
Debugger entered--Lisp error: (void-variable overlays)
htmlize-sorted-overlays-at(1)
htmlize-faces-at-point()
htmlize-buffer-1()
htmlize-file("~/tmp/prova-org/example.txt")
call-interactively(htmlize-file record nil)
command-execute(htmlize-file record)
execute-extended-command(nil "htmlize-file")
call-interactively(execute-extended-command nil nil)
command-execute(execute-extended-command)
------->8-------------8<--------
I have emacs 24.5.1, and I use the htmlize package from downloaded from the git. Here is my .emacs:
------->8-------------8<--------
(add-to-list 'load-path "/elisp/")/elisp/org-mode/lisp")
(add-to-list 'load-path "
(add-to-list 'load-path "~/elisp/emacs-htmlize" t)
(require 'org)
(org-babel-load-file
(expand-file-name "minimal_init.org"
user-emacs-directory))
------->8-------------8<--------
and here is my minimal_init.org file
------->8-------------8<--------
#+BEGIN_SRC emacs-lisp
(setq-default)
(setq inhibit-splash-screen t)
#+END_SRC
------->8-------------8<--------
I run into this problem a few days ago when I tried to export a org-mode file containing src code blocks to html. It was working until a few weeks ago, then suddenly this error. For some reason, it seems I am the only one having this problem; nobody else noticed it, or can reproduce it in the org mailing list.
Can you help me solving this issue?
Best regards,
Giuseppe Lipari
This was noticed by a user (sulami/literate-calc-mode.el#17).
I have not done any extensive research, but I can provide a traceback & a minimal example.
#+begin_src literate-calc
Pi = 3.14159
#+end_src
Debugger entered--Lisp error: (args-out-of-range "Pi " 0 12)
substring("Pi " 0 12)
htmlize-add-before-after-strings(1 4 "Pi ")
htmlize-get-text-with-display(1 4)
htmlize-buffer-substring-no-invisible(1 4)
htmlize-extract-text(1 4 nil)
htmlize-buffer-1()
htmlize-region(1 13)
org-html-htmlize-region-for-paste(1 13)
org-html-fontify-code("Pi = 3.14159" "literate-calc")
org-html-do-format-code("Pi = 3.14159" "literate-calc" nil t nil nil)
[ more frames omitted ]
This is where the traceback leads me.
With Emacs 25.3, byte-compiling htmlize.el
triggers a warning:
In htmlize-file:
htmlize.el:1893:17:Warning: `font-lock-fontify-buffer' is for interactive use
only; use `font-lock-ensure' or `font-lock-flush' instead.
The following patch solves this (while still fontifying the output :-)):
--- /dev/fd/63 2018-01-07 01:24:02.790734877 +0000
+++ emacs-htmlize-release-1.51/htmlize.el 2018-01-07 00:42:57.278556882 +0000
@@ -1889,11 +1889,7 @@
(let ((buffer-file-name file))
;; Set the major mode for the sake of font-lock.
(normal-mode)
- (font-lock-mode 1)
- (unless font-lock-mode
- ;; In GNU Emacs (font-lock-mode 1) doesn't force font-lock,
- ;; contrary to the documentation. This seems to work.
- (font-lock-fontify-buffer))
+ (font-lock-ensure)
;; htmlize the buffer and save the HTML.
(with-current-buffer (htmlize-buffer-1)
(unwind-protect
As I don't know the best way to preserve compatibility with Emacs 21/21, I won't submit this as a pull request (BTW, htmlize.el
"aims for compatibility with Emacsen version 21 and later", while README.md
"aims for compatibility with Emacsen version 22 and later").
Org mode needs htmlize
(in some cases) and even complains about it:
Please install htmlize from https://github.com/hniksic/emacs-htmlize"
I would like it if I could install htmlize
from the official GNU ELPA.
Would you mind tagging releases, so MELPA Stable can pick them up? Thanks!
I'm using color-identifiers-mode with some custom setup to change most of the highlighting from the code. IOW the code highlight I see is drastically different from just the theme in use.
However htmlize-buffer
makes html which instead looks like the theme in use.
Steps to reproduce:
emacs -Q
(it will open a scratch buffer with a comment).load-file
to load htmlize.el
(face-remap-add-relative 'font-lock-comment-face '((:weight bold)))
htmlize-buffer
Expected result: resulting html should have a bold
text.
Actual result: bold keyword is ignored.
The following lisp-code creates a buffer *test*
with an embedded svg image data.
The image is broken in the HTML file generated by htmlize-buffer
in buffer *test*
.
The reason is that the data is exported with Mime type svg
instead of svg+xml
.
(with-current-buffer (get-buffer-create "*test*")
(let (b e)
(erase-buffer)
(insert "\t Text before\n\t")
(setq b (point))
(insert (propertize "bold\n" 'face 'bold)
(propertize "\t italic\n" 'face 'italic))
(setq e (point))
(insert "\n\tText after")
(let ((ol (make-overlay b e)))
(overlay-put
ol
'display
(create-image
"<svg height=\"140\" width=\"500\" xmlns=\"http://www.w3.org/2000/svg\">
<ellipse rx=\"100\" ry=\"50\" cx=\"120\" cy=\"80\"
style=\"fill:yellow;stroke:green;stroke-width:3\" />
</svg>"
'svg
t)))))
is it possible to not convert tab to spaces inside pre tag?
in golang, its a community convention to use tabs, enforced by the bundled tool gofmt.
(and i think tabs are critical in makefile.)
I write tutorials. So my primary use of htmlize is to convert programing language source code to a htmlized form. With golang, this maybe be a minor problem. thanks.
Hi,
I use org-re-reveal
which uses htmlize.el
to render the orgmode src blocks.
It works well except that an exclamation character "!" begins every line.
When looking into the html file, there is indeed an exclamation point.
I wonder if it is on purpose of it can be removed ?
Regards
Hi
I'm using this htmlize with highlight2clipboard to copy a region to a clipboard in Mac OSX and it is very useful to present to mail or some other purpose.
However, it doesn't look that htmlize converts a region with the background color.
Is there an option or workaround for it?
Hey, this is just to let you know that htmlize was added to the NonGNU ELPA package repository: https://elpa.nongnu.org/nongnu/htmlize.html
This shouldn't affect packaging, the main difference is that while MELPA uses tagged commits to identify new (stable) versions, NonGNU ELPA uses those commits that increment the version tag in the package header.
As the repository will be active by default from Emacs 28 onwards, you might be interested in adding a note that it can be installed without any further configuration.
I have code that execute lot of
(hlt-highlight-region start-pos end-pos '((t (:background "green")))))
and I got lot of errors Invalid face reference: t
.
Org bundles an old version of htmlize.el
, which identifies itself as 1.43. The version in this repository is 1.51.
org-agenda.el
, ox-org.el
, and ox-html.el
require htmlize
. It would probably be a good idea to check whether those libraries are compatible with 1.51.Thanks everyone!
Sorry if I'm asking stupid questions here, I just like to understand the problem, and would understand if there would not be a solution.
I tried to htmlize a Gnus summary buffer. This is a list of mails in a folder. But htmlizing did not preserve styling. And after running htmlize, all styling was removed from the region or buffer.
So I started investigation, and describe-face
didn't learn me much, cause it didn't automatically pick up the face where point was on.
So I did describe-char
and this is what it gave me:
position: 2880 of 13413 (21%), column: 70
character: i (displayed as i) (codepoint 105, #o151, #x69)
charset: ascii (ASCII (ISO646 IRV))
code point in charset: 0x69
script: latin
syntax: w which means: word
category: .:Base, L:Left-to-right (strong), a:ASCII, l:Latin, r:Roman
to input: type "C-x 8 RET 69" or "C-x 8 RET LATIN SMALL LETTER I"
buffer code: #x69
file code: #x69 (encoded by coding system utf-8)
display: by this font (glyph code)
ftcr:-CTDB-FuraCode Nerd Font Mono-normal-normal-normal-*-32-*-*-*-*-0-iso10646-1 (#x4B)
Character code properties: customize what to show
name: LATIN SMALL LETTER I
general-category: Ll (Letter, Lowercase)
decomposition: (105) ('i')
There are text properties here:
face (org-agenda-restriction-lock gnus-summary-normal-unread)
gnus-face t
gnus-number 31997
mouse-face highlight
[back]
I downloaded the code from:
https://github.com/hniksic/emacs-htmlize
master branch commit dd27bc3
I'm running:
GNU Emacs 24.3.1 (x86_64-redhat-linux-gnu, GTK+ Version 3.22.30) of 2018-11-02 on x86-01.bsys.centos.org
When I try to foramt a buffer with M-x htmlize-buffer
I get the error:
nreverse: Wrong number of arguments: overlays-at, 2
Can you help me? Thanks!
My emacs buffer looks like this:
I grab it using ox-clip and paste it to google docs, and it looks ugly:
After I remove extra line spacing in gdocs, it looks a bit better:
But still the best way is to have an option to ignore the background color.
I think the right function to change is:
https://github.com/hniksic/emacs-htmlize/blob/master/htmlize.el#L947
In issue #23 org mode developers suggested having an official mirror for htmlize, and set one up. This issue is for making this mirror a documented mirror of htmlize source.
Using this MarkDown file: https://github.com/balamaci/rxjava-walkthrough/blob/master/README.md , I notice the links are not clickable.
Maybe this is intentional but It'd be nice to have an option to enable it, specially for MarkDown and Org files.
I have lot of errors on big file and keep showing then in message buffer and M-g doesn't do anything. How can I stop processing?
When htmlize-region-for-paste
is used, the background color of the buffer is not used, which can lead to weird-looking outputs (eg with whitespace-mode
). Please have inline-css
put style in the <pre>
tag, like for <body>
.
Run emacs as emacs --daemon
and emacsclient -c
choose a theme (example modus-vivendi) then htmlize a buffer
it was htmlized with modus-vivendi theme colors
now close the emacsclient window C-x C-c
then htmlize a buffer without any emacsclient window running (use functions running in emacs daemon)
now it was htmlized without theme colors
it is a problem if you're running emacs as a server
I noticed when exporting org-mode buffers to html that some characters got rendered in an undesired way:
py-number-face
and py-variable-name-face
from python-mode.el
, which get an own <span>
container when htmlized, and from me trying to tinker around I found that the background colour for this container is taken from the current Emacs theme's background colour of the respective characters.highlight-indentation.el
@antonj (see here). I have not tracked down the variable which is picked up here yet, but I examined it with some browser developer tools and it looks exactly like the issue above - these characters get a <span>
container and the background colour of the Emacs theme. I made a screenshot:As described in the SO issue regarding the python-mode.el
variables, there is a workaround in setting them to nil
like this:
(setq py-number-face nil)
(setq py-variable-name-face nil)
But I think this is a quite dirty fix. Also, I could not yet fix the highlight-indentation problem (deactivating the minor mode didn't help).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.