Skip to content

Commit

Permalink
v2: Port to TB 78.4+/82+, rewrite add-on from scratch, use highlight.js
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
Qeole committed Oct 26, 2020
1 parent d54c3ab commit c8436dd
Show file tree
Hide file tree
Showing 91 changed files with 1,336 additions and 5,837 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.editorconfig
*.xpi
hljs/
2 changes: 1 addition & 1 deletion COPYRIGHT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Copyright 2006-2010 Vadim Atlygin
Copyright 2011-2015 Jesse Glick
Copyright 2016-2018 Qeole
Copyright 2016-2020 Qeole

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
63 changes: 47 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,52 @@
ADDON=colorediffs
XPI=$(ADDON)-$(shell date -u "+%Y%m%d").xpi
SRC=$(shell find chrome defaults ! -path "chrome/content/tests*")
TOPFILES=manifest.json chrome.manifest LICENSE COPYRIGHT
# SPDX-License-Identifier: MPL-2.0

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

xpi: $(XPI)
xpi: $(ADDON) check_css_list

%.xpi: $(SRC) $(TOPFILES)
zip -q $@ $^
%.xpi: \
manifest.json \
README.md LICENSE COPYRIGHT \
misc/icon.png \
options/ \
scripts/ \
hljs/README.md hljs/LICENSE \
hljs/highlight.pack.js \
hljs/styles/
zip -q -r $@ $^

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

clean:
rm -f $(ADDON)-*.xpi
$(HLJS_SCRIPT):
TOKEN=$$(curl -sL --cookie-jar "$(JAR)" $(HLJS_DL) | sed -n '/csrfmiddlewaretoken/ s/.*value="\([^"]\+\)".*/\1/p') && \
curl -sL --referer $(HLJS_DL) --cookie "$(JAR)" --request POST --data-urlencode "csrfmiddlewaretoken=$$TOKEN" --data-urlencode 'diff.js=on' $(HLJS_DL) --output "$(HLJS_ZIP)"
unzip -q -o "$(HLJS_ZIP)" -d hljs
rm -- "$(JAR)" "$(HLJS_ZIP)"
@VERSION=$$(sed -n 's/.*versionString="\([^\"]\+\)".*/\1/p' $@) && printf "\e[;32m[NOTE] Successfully downloaded highlight.js version $$VERSION.\e[0m\n"

$(HLJS_STYLES) hljs/README.md hljs/LICENSE: $(HLJS_SCRIPT)

check_css_list: $(HLJS_STYLES)
@printf 'Checking that all CSS styles from highlight.js are listed in the add-on...\t'
@error=0; for stylepath in $(HLJS_STYLES)*.css; do \
stylesheet=$$(basename $$stylepath); \
stylename=$${stylesheet%.css}; \
if ! grep -q $$stylename options/fill-css-list.js; then \
[ $$error = 0 ] && printf '\n'; \
printf '\e[1;31m[WARNING] Found missing CSS style: "%s".\e[0m\n' $$stylename; \
error=1; \
fi; \
done; [ $$error = 0 ] && printf 'All good.\n' || false

clean-hljs:
rm -rf -- hljs

clean: clean-hljs
rm -f -- $(ADDON)

.PHONY: xpi clean clean-hljs check_css_list
116 changes: 41 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,98 +1,64 @@
# ![Add-on icon](chrome/content/icon.png) Colored diffs
# ![Add-on icon](misc/icon.png) Colorediffs

This is an extension that colors boring diffs sent by notifiers for Git,
Subversion, CVS, Mercurial, etc.

The project was originally authored by Vadim Atlygin, and for a time it has
been maintained by Jesse Glick (jglick). Now the torch has passed to Qeole.

## Presentation

A lot of developers use Git or other version control systems. Most of them also
receive special notifications from the system about changes other people do.
They might be useful in various ways: someone wants to check if there are bugs
in the new code, someone just wants to keep knowledge of code base up-to-date.
But looking over that black-on-white letter is so boring. That's why we decided
to color it up a bit.
Color diffs in the emails you receive. This is typically helpful for reviewing
patches formatted with Git or other version control systems.

## Installation

### Get it from Mozilla add-ons platform
### Get it from Thunderbird's Add-Ons Platform

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

### … Or install it manually
### … Or Install it Manually

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

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

$ cd /path/to/colorediffs/
$ make

## What the add-on can do

![Transformation](misc/transformation.png)

Well, not so much… It can color your diffs, it can show them in side-by-side
mode if you like. Also it converts all the filenames in message log into links
so you can quickly jump to the file you want to review. Ah, and it can make
space and tabs chars visible. You can look through list of SupportedFormats to
see what are the supported VCSs.

## Ideas for future contribution

The original author of the project wanted this add-on to include the following
features:
Note that this will download (with curl) the latest version of the highlight.js
library, which is not included in this repository.

1. Highlighting the actual difference between the lines.
2. Coloring the syntax of the language used.
3. Checking new code against few rules in order to estimate the quality of
it.
## Usage

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

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

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

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

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

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

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

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

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

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

This file was deleted.

7 changes: 0 additions & 7 deletions chrome/content/bindings/bindings.css

This file was deleted.

9 changes: 0 additions & 9 deletions chrome/content/bindings/colorpicker.css

This file was deleted.

97 changes: 0 additions & 97 deletions chrome/content/bindings/main-bindings.xbl

This file was deleted.

38 changes: 0 additions & 38 deletions chrome/content/callbacks.js

This file was deleted.

Loading

0 comments on commit c8436dd

Please sign in to comment.