Skip to content

Commit c8436dd

Browse files
committed
v2: Port to TB 78.4+/82+, rewrite add-on from scratch, use highlight.js
Following Thunderbird's switch to MailExtensions, the add-on had to be ported as a "legacy" extension for v68. This proved to be a short relief, since the following stable, v78, does not support those anymore. The new version of the add-on is a pure MailExtension that should be compatible with new Thunderbird versions. It relies on the messagesModify API that appeared in Thunderbird 82, but has since been backported to version 78.4 [0]. Various parts of the add-on were referring to XUL overlays or chrome components, but none are available with MailExtensions. Instead of struggling to adapt these parts, the add-on was entirely rewritten from scratch, and with a different approach. We no longer parse and reformat the diffs: Instead, we embed and inject the highlight.js library that takes care of coloring the diff [1]. Consequences and main changes: - We loose some accuracy, because we do not rely on "what part of the diff we are in". Concretely, all lines starting with "+" or "-" will be colored, even if in the commit log. - We gain in stability, with less parsing susceptible to break. - We loose the different modes, unified / context / side-by-side. The diffs are not rewritten, we simply add colors. - We keep the ability to replace tabs and spaces, but loose the line numbers. - It is not possible at this time to specify custom colors for the diffs, but we can pick a style amongst the hundred or so that are supported by highlight.js. Bumping the major version number. [0] https://bugzilla.mozilla.org/show_bug.cgi?id=1504475 [1] https://highlightjs.org/
1 parent d54c3ab commit c8436dd

File tree

91 files changed

+1336
-5837
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1336
-5837
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.editorconfig
2+
*.xpi
3+
hljs/

COPYRIGHT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Copyright 2006-2010 Vadim Atlygin
22
Copyright 2011-2015 Jesse Glick
3-
Copyright 2016-2018 Qeole
3+
Copyright 2016-2020 Qeole
44

55
This Source Code Form is subject to the terms of the Mozilla Public
66
License, v. 2.0. If a copy of the MPL was not distributed with this

Makefile

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,52 @@
1-
ADDON=colorediffs
2-
XPI=$(ADDON)-$(shell date -u "+%Y%m%d").xpi
3-
SRC=$(shell find chrome defaults ! -path "chrome/content/tests*")
4-
TOPFILES=manifest.json chrome.manifest LICENSE COPYRIGHT
1+
# SPDX-License-Identifier: MPL-2.0
52

6-
.PHONY: clean test
3+
VERSION=$(shell sed -n '/"version"/ s/.*: "\(.*\)",/\1/p' manifest.json)
4+
ADDON=colorediffs-$(VERSION).xpi
75

8-
xpi: $(XPI)
6+
xpi: $(ADDON) check_css_list
97

10-
%.xpi: $(SRC) $(TOPFILES)
11-
zip -q $@ $^
8+
%.xpi: \
9+
manifest.json \
10+
README.md LICENSE COPYRIGHT \
11+
misc/icon.png \
12+
options/ \
13+
scripts/ \
14+
hljs/README.md hljs/LICENSE \
15+
hljs/highlight.pack.js \
16+
hljs/styles/
17+
zip -q -r $@ $^
1218

13-
test:
14-
@echo 'Wait, it does not work! :('
15-
@#java -cp test-framework/js.jar org.mozilla.javascript.tools.shell.Main \
16-
#-version 170 \
17-
#-debug test-framework/main.js \
18-
#--test-directory chrome/content/tests/
19+
JAR=/tmp/colorediffs.cookie
20+
HLJS_DL='https://highlightjs.org/download/'
21+
HLJS_ZIP=/tmp/highlight.zip
22+
HLJS_SCRIPT=hljs/highlight.pack.js
23+
HLJS_STYLES=hljs/styles/
1924

20-
clean:
21-
rm -f $(ADDON)-*.xpi
25+
$(HLJS_SCRIPT):
26+
TOKEN=$$(curl -sL --cookie-jar "$(JAR)" $(HLJS_DL) | sed -n '/csrfmiddlewaretoken/ s/.*value="\([^"]\+\)".*/\1/p') && \
27+
curl -sL --referer $(HLJS_DL) --cookie "$(JAR)" --request POST --data-urlencode "csrfmiddlewaretoken=$$TOKEN" --data-urlencode 'diff.js=on' $(HLJS_DL) --output "$(HLJS_ZIP)"
28+
unzip -q -o "$(HLJS_ZIP)" -d hljs
29+
rm -- "$(JAR)" "$(HLJS_ZIP)"
30+
@VERSION=$$(sed -n 's/.*versionString="\([^\"]\+\)".*/\1/p' $@) && printf "\e[;32m[NOTE] Successfully downloaded highlight.js version $$VERSION.\e[0m\n"
31+
32+
$(HLJS_STYLES) hljs/README.md hljs/LICENSE: $(HLJS_SCRIPT)
33+
34+
check_css_list: $(HLJS_STYLES)
35+
@printf 'Checking that all CSS styles from highlight.js are listed in the add-on...\t'
36+
@error=0; for stylepath in $(HLJS_STYLES)*.css; do \
37+
stylesheet=$$(basename $$stylepath); \
38+
stylename=$${stylesheet%.css}; \
39+
if ! grep -q $$stylename options/fill-css-list.js; then \
40+
[ $$error = 0 ] && printf '\n'; \
41+
printf '\e[1;31m[WARNING] Found missing CSS style: "%s".\e[0m\n' $$stylename; \
42+
error=1; \
43+
fi; \
44+
done; [ $$error = 0 ] && printf 'All good.\n' || false
45+
46+
clean-hljs:
47+
rm -rf -- hljs
48+
49+
clean: clean-hljs
50+
rm -f -- $(ADDON)
51+
52+
.PHONY: xpi clean clean-hljs check_css_list

README.md

Lines changed: 41 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,64 @@
1-
# ![Add-on icon](chrome/content/icon.png) Colored diffs
1+
# ![Add-on icon](misc/icon.png) Colorediffs
22

3-
This is an extension that colors boring diffs sent by notifiers for Git,
4-
Subversion, CVS, Mercurial, etc.
5-
6-
The project was originally authored by Vadim Atlygin, and for a time it has
7-
been maintained by Jesse Glick (jglick). Now the torch has passed to Qeole.
8-
9-
## Presentation
10-
11-
A lot of developers use Git or other version control systems. Most of them also
12-
receive special notifications from the system about changes other people do.
13-
They might be useful in various ways: someone wants to check if there are bugs
14-
in the new code, someone just wants to keep knowledge of code base up-to-date.
15-
But looking over that black-on-white letter is so boring. That's why we decided
16-
to color it up a bit.
3+
Color diffs in the emails you receive. This is typically helpful for reviewing
4+
patches formatted with Git or other version control systems.
175

186
## Installation
197

20-
### Get it from Mozilla add-ons platform
8+
### Get it from Thunderbird's Add-Ons Platform
219

22-
[Available here](https://addons.mozilla.org/en-US/thunderbird/addon/colored-diffs/)
10+
[Available here](https://addons.thunderbird.net/en-US/thunderbird/addon/colored-diffs/)
2311

24-
### … Or install it manually
12+
### … Or Install it Manually
2513

26-
[Install locally](https://developer.mozilla.org/en-US/Add-ons/Thunderbird/Building_a_Thunderbird_extension_7:_Installation)
27-
or
28-
[package it into a .xpi file](https://developer.mozilla.org/en-US/Add-ons/Thunderbird/Building_a_Thunderbird_extension_8:_packaging).
14+
Pack the add-on as an .xpi file and install it from the “gear” menu in
15+
Thunderbird's add-on manager.
2916

30-
Under UNIX-like systems you can create the .xpi file by simply running:
17+
On UNIX-like systems, you can create the .xpi file by simply running:
3118

3219
$ cd /path/to/colorediffs/
3320
$ make
3421

35-
## What the add-on can do
36-
37-
![Transformation](misc/transformation.png)
38-
39-
Well, not so much… It can color your diffs, it can show them in side-by-side
40-
mode if you like. Also it converts all the filenames in message log into links
41-
so you can quickly jump to the file you want to review. Ah, and it can make
42-
space and tabs chars visible. You can look through list of SupportedFormats to
43-
see what are the supported VCSs.
44-
45-
## Ideas for future contribution
46-
47-
The original author of the project wanted this add-on to include the following
48-
features:
22+
Note that this will download (with curl) the latest version of the highlight.js
23+
library, which is not included in this repository.
4924

50-
1. Highlighting the actual difference between the lines.
51-
2. Coloring the syntax of the language used.
52-
3. Checking new code against few rules in order to estimate the quality of
53-
it.
25+
## Usage
5426

55-
But these are pretty big tasks, and development of the add-on is not so active
56-
by now. If you want to help, though, do not hesitate to contribute by dropping
57-
an issue or a PR!
27+
Once installed, the add-on should automatically detect diffs in your plain-text
28+
messages and color them with the selected theme. Some options are available in
29+
the add-on preference page:
5830

59-
## Contribution
31+
- You can select the color scheme amongst all the styles supported by
32+
highlight.js.
33+
- You can have tabs and white space characters replaced by visible characters.
34+
- You can set the length for tab characters (defaults to 8).
35+
- You can choose to color all plain-text messages (even with no diffs), which is
36+
mostly useful to avoid visual discomfort when using a style with a dark
37+
background and browsing a mailing list.
6038

61-
If you know how to do something better, whether it's code, icons, default color
62-
scheme, just contact me. Also please visit the [issues
63-
list](https://github.com/jglick/colorediffs/issues) and comment on issues you'd
64-
really like to be done first.
39+
## Versions
6540

66-
## Firefox extension
41+
**Version 2+ of the add-on is compatible with Thunderbird stable version 78.4
42+
and onward.** It uses the `messageDisplayScripts` API which was added in
43+
Thunderbird 82, and backported to 78.4.
6744

68-
There isn't one and probably never will be, sorry. I could make it work for
69-
diff in `<pre>` sections (most mail lists archives format them like this) but
70-
it would never work in GMail and other Web mail systems where it would be
71-
actually useful. It's just plain hard to find the code between the lines of
72-
normal text. But you could ease you pain with [Bookmarklet](Bookmarklet.md) I
73-
wrote when your needs is simple (like mail list archives) and [GreaseMonkey
74-
script](http://userscripts.org/scripts/show/26684) written by Fabrice
75-
Bellingard for GMail. Thanks for understanding.
45+
Older versions of the add-on work with Thunderbird
46+
[up to the version 68](https://github.com/Qeole/colorediffs/tree/e51d1aab6390d11a5ee2ec84e1cf42fd08564a41#version-notes).
7647

77-
## Version notes
48+
The distinction is due to Thunderbird's move to MailExtensions. As a
49+
consequence of this change, version 2.0.0 of the add-on is a complete rewrite
50+
(by Qeole) and works differently from the previous versions. Instead of parsing
51+
the diffs and rebuilding the messages itself, the add-on embeds and injects the
52+
[highlight.js library](https://highlightjs.org/) which takes care of the
53+
colors, without reformatting the content of the message.
7854

79-
* Version 0.5 is the last one with support for Thunderbird 2. I'm too tired of
80-
more than two years old JavaScript engine.
55+
## Status
8156

82-
* Version 0.7 does not support SeaMonkey anymore, because the new maintainer
83-
does not use it and does not wish to test add-on compatibility. But the code
84-
has not changed much, and this is probably just a matter of enabling support
85-
again in install.rdf file. So if some tech-savvy SeaMonkey user tests and
86-
confirms compatibility, I will enable it again.
57+
The project was originally authored by Vadim Atlygin. For a time it has
58+
been maintained by Jesse Glick (jglick), and it has now passed to Qeole.
8759

88-
* Versions 0.8 and 0.9 should work with Thunderbird 60 (although I did not
89-
manage to fix preferences settings, so it comes with fixed color choices,
90-
unless users resort to the config editor). Later Thunderbird versions are
91-
expected to deprecate XUL-based extensions, which means the add-on will not
92-
remain compatible unless it undergoes major rework.
60+
This add-on is mostly in maintenance mode, do not expect new features. Several
61+
people are using it to review patches for their daily jobs, so the objective is
62+
essentially to keep something basic, but that works.
9363

94-
* Version 1.9 works with Thunderbird 68. Note that the preference menu remains
95-
completely broken (I even removed the button to display it), therefore you'll
96-
have to work with the default options or to use Thunderbird's config editor.
97-
This version has not been tested on older Thunderbird versions. Conversely,
98-
version 0.9 and earlier of the add-on cannot be loaded on Thunderbird 68+.
64+
Nonetheless, you are welcome to report issues or to submit pull requests.

chrome.manifest

Lines changed: 0 additions & 6 deletions
This file was deleted.

chrome/content/bindings/bindings.css

Lines changed: 0 additions & 7 deletions
This file was deleted.

chrome/content/bindings/colorpicker.css

Lines changed: 0 additions & 9 deletions
This file was deleted.

chrome/content/bindings/main-bindings.xbl

Lines changed: 0 additions & 97 deletions
This file was deleted.

chrome/content/callbacks.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)