Skip to content

Commit

Permalink
v2: Port to Thunderbird 82+, rewrite add-on from scratch, 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 may be
backported to version 78 in the future [0].

Various parts of the add-on where refering 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 Sep 20, 2020
1 parent d54c3ab commit ee69f6e
Show file tree
Hide file tree
Showing 89 changed files with 1,126 additions and 5,838 deletions.
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
46 changes: 30 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
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)

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

clean:
rm -f $(ADDON)-*.xpi
JAR=/tmp/colorediffs.cookie
HLJS_ZIP=/tmp/highlight.zip
hljs/highlight.pack.js:
TOKEN=$$(curl -sL --cookie-jar "$(JAR)" 'https://highlightjs.org/download/' | sed -n '/csrfmiddlewaretoken/ s/.*value="\([^"]\+\)".*/\1/p') && \
curl -sL --referer 'https://highlightjs.org/download/' --cookie "$(JAR)" --request POST --data-urlencode "csrfmiddlewaretoken=$$TOKEN" --data-urlencode 'diff.js=on' 'https://highlightjs.org/download/' --output "$(HLJS_ZIP)"
unzip -q -o "$(HLJS_ZIP)" -d hljs
rm -- "$(JAR)" "$(HLJS_ZIP)"
@VERSION=$$(sed -n 's/.*versionString="\([^\"]\+\)".*/\1/p' $@) && printf "[Note] Successfully downloaded highlight.js version $$VERSION.\n"

clean-hljs:
rm -rf -- hljs

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

.PHONY: xpi clean clean-hljs
115 changes: 39 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,98 +1,61 @@
# ![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:

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.
Note that this will download (with curl) the latest version of the highlight.js
library, which is not included in this repository.

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!
## Usage

## Contribution
Once installed, the add-on should automatically detect diffs in your plaintext
messages and color them with the selected theme. Some options are available in
the add-on preference page:

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.
- 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 plaintext 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.

## Firefox extension
## Versions and Branches

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.
This branch is for Thunderbird version 82 and higher. Please refer to the [tb68
branch](https://github.com/Qeole/colorediffs/tree/tb68) for support for version
68 and older. There is no support for the stable version 78 at the moment, as
it does not include the necessary API.

## Version notes
Following Thunderbird's move to MailExtensions, 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 ee69f6e

Please sign in to comment.