Skip to content

Commit 99821c9

Browse files
committed
Switch to web extension framework
Update all the source code to have a working web extension, compatible with Firefox 48+? (tested on version 57). Background script has been completely rewritten, even though much of the logics remain the same. Content script remains closer to its previous version. Option handling must now be done by the extension (no more by the SDK): add an option page. The popup for language selection did not change much. Since we changed a lot of things, this commit (or rather, the previous one) also makes some cleanup in the files tracked by Git. Furthermore, README.md and icons have been updated. Of course, this new version of the add-on is no more compatible with the jpm tool, or with the add-on SDK APIs. Change version number to 2+. Since the new reference for version numbers allows for more dot-separated values, the add-on will follow the following scheme: A.B.X.Y, where - A is the major version, bumped to 2, - B is the minor version, incremented for each modification to the add-on internal code, - X is the major version of embedded highlight.js, - Y is the minor version of embedded highlight.js. highlight.js also has a third (build) number, that will not appear in the add-on version number. Differences in behavior: - The icon of the button no longer changes aspect when the button is clicked. - Some options disappeared, as I suspect nobody used them: namely, the option for preventing background coloring, as well as the option for using alternate icon set (now handled directly in the manifest) have both been removed. Known issue: the add-on keeps one global state to remember if the tab has already been colored or not. Of course, in the case when several tabs are to be highlighted, this is a problem. This is not so big an issue, since in this case: - If the tab should be colored but the state is not correct, the first click to the add-on button is without effect. Second click works as expected and opens the language selection popup. - If the tab should be reset (to no-color) but the state is not correct, the language selection pops up (instead of not showing), and a click will un-highlight tab contents, whatever language was selected. Next click will have status in order, and will act as expected. As a workaround, maybe the background script could probe the tab to see if content script has been injected already. But I haven't been successful with this so far, background script seems to hang if it fails to connect to a content script. The issue will probably stay there for a while, until I find something better.
1 parent 36c54d5 commit 99821c9

16 files changed

+725
-762
lines changed

README.md

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,80 @@
1-
![Add-on icon](misc/spot64.png) Enlight
2-
========================================
1+
![Add-on icon](icons/spot64.png) Enlight
2+
=========================================
33

4-
Firefox add-on providing syntax highlighting for raw code, based on the
5-
highlight.js project.
4+
Enlight is a Firefox add-on providing syntax highlighting for raw source code
5+
files, based on the highlight.js project.
66

7-
Syntax highlighting relies on highlight.js project (see [project
8-
homepage][hljs]. Currently packaged with the add-on is the version
7+
Syntax highlighting relies on the highlight.js library (see [project
8+
homepage][hljs]). Currently packaged with the add-on is the version
99
9.12.0 of highlight.js, which provides
1010
78 color themes <!-- darkula is an alias, doesn't count --> and syntax for
1111
175 languages.
1212

1313
## Install
1414

15-
\>>> [Get it from Mozilla add-ons platform][amo]. <<<
15+
▶▶▶ [Get it from Mozilla add-ons platform][amo]! ◀◀◀
1616

1717
As a general rule, it is no longer possible to manually install the version
1818
provided here with the vanilla Firefox release. See [Mozilla policy on add-ons
19-
signature][signing] for details. On some specific Firefox versions where add-on
19+
signature][policy] for details. On some specific Firefox versions where add-on
2020
signing has been disabled (_Developer Edition_ or _Nightly_ with the option
2121
manually deactivated, or on special stable releases), it may be possible to use
22-
a version of the add-on coming from this repository.
22+
a version of the add-on coming from this repository ([see also Mozilla's
23+
wiki][signing]).
2324

24-
If you run one of those specific versions: just open the
25-
`enlight_highlightjs@jetpack-<version>.xpi` file (`File->Open`) in Firefox.
26-
Confirm you want to install, and you're done.
25+
If you run one of those specific versions and want to run or build the add-on,
26+
use the [web-ext tool][webext-start]. To test it with a temporary Firefox
27+
profile, use:
2728

28-
To build the add-on, one needs the `jpm` tool ([documentation][jpm]). If you
29-
wish to build from sources, the `xpi` add-on file itself can easily be
30-
generated with a `jpm xpi` command from the Mozilla add-on SDK (see
31-
[documentation on MDN][sdk]).
29+
web-ext run
3230

33-
Building with `cfx` is no longer supported. I intend to work on a version based
34-
on WebExtensions, … when I can find some spare time!
31+
Or to compile an add-on `.xpi` file, use instead:
32+
33+
web-ext build
34+
35+
See the [documentation for web-ext tool][webext-ref] if you need more
36+
information about the available commands and options.
37+
38+
Building with `cfx` or `jpm` (used for older versions) is no longer supported.
3539

3640
## Usage
3741

3842
### Basics
3943

40-
On install, a new button with a ~~spotlight~~ light bulb
41-
![buttonOff](data/lightbulb_off-32.png) (yes, it's supposed to be a
42-
~~spotlight~~ light bulb − but the magnificent spotlight remains the add-on
43-
icon in the add-on manager tab for now) should appear in Firefox toolbar.
44+
On install, a new button with a light bulb
45+
![button](icons/lightbulb-dark-19x32.png) should appear in Firefox toolbar.
4446

4547
To highlight raw source code in the active tab, click on this button and select
4648
the language syntax you want to use (or “Autodetect” for automatic detection).
47-
If you want to undo highlighting, just click again on the button
48-
![buttonOn](data/lightbulb_on-32.png) (reloading the page also works).
49+
If you want to undo highlighting, just click again on the button. Reloading the
50+
page also works.
4951

5052
### Options
5153

5254
You can also customize some options through Firefox add-on manager tab:
55+
5356
* Color theme selection (_default: Solarized Dark_): change the CSS theme in
5457
use for syntax highlight.
5558
* Automatic highlighting (_default: off_): check it to automatically trigger
5659
syntax highlighting for all plain text files.
57-
* Alternate icon set (_default: off_): use white icons; useful if you use a
58-
dark theme for Firefox, such as the default theme for Developer Edition
59-
* Adapt background body color (_default: on_): remove white border due to
60-
body background color. There is no reason to deactivate this, unless you try
61-
to highlight non-plain text pages and get strange background modification.
6260
* Add line numbers (_default: off_): add line numbers on the left of file
6361
content. Line numbers are created with CSS and are not part of the file
6462
contents.
6563

66-
When line numbering is enabled, it is possible to jump to line passed through
67-
URL (_default: on_): scroll to e.g. line 27 and select it if a suffix such as
64+
When line numbering is enabled, it is possible to jump to the line passed
65+
through URL: e.g. scroll to line 27 and select it if a suffix such as
6866
`#Line27` or `#line27` or `#L27` or `#l27` is appended to the URL **before**
6967
the script loads (this does not relies on HTML anchors and cannot be triggered
70-
by simple URL modification; reload the script for current page if you added the
71-
suffix afterward).
68+
by simple URL modification; reload syntax highlighting for current page if you
69+
added the suffix afterward).
70+
71+
### New languages, color schemes
72+
73+
Enlight relies on highlight.js library for coloring the code. It does not
74+
modify this library, nor does it add support for additional languages or color
75+
schemes. Therefore, fixes for language syntax and auto-detection accuracy,
76+
suggestions or contributions to new languages and styles should be addressed to
77+
the [highlight.js project community][hljs].
7278

7379
## License
7480

@@ -82,15 +88,16 @@ for details).
8288
## Miscellaneous
8389

8490
Other than on the [hilight.js homesite][hljs], you can find a list of supported
85-
languages in [data/languages-all.json][languages], and of available color schemes in
86-
[package.json][package].
91+
languages in [data/languages-all.json][languages], and of available color
92+
schemes in [package.json][package].
8793

8894
[hljs]: https://highlightjs.org
89-
[signing]: https://blog.mozilla.org/addons/2015/02/10/extension-signing-safer-experience
95+
[policy]: https://blog.mozilla.org/addons/2015/02/10/extension-signing-safer-experience
96+
[signing]: https://wiki.mozilla.org/Add-ons/Extension_Signing
9097
[amo]: https://addons.mozilla.org/firefox/addon/enlight
91-
[sdk]: https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Getting_started
98+
[webext-start]: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Getting_started_with_web-ext
99+
[webext-ref]: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/web-ext_command_reference
92100
[mpl]: https://github.com/Qeole/Enlight/blob/master/LICENSE
93101
[bsd]: https://github.com/isagalaev/highlight.js/blob/master/LICENSE
94102
[languages]: https://github.com/Qeole/Enlight/blob/master/data/languages-all.json
95103
[package]: https://github.com/Qeole/Enlight/blob/master/package.json
96-
[jpm]: https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/jpm

_locales/en/messages.json

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,6 @@
1-
# Vim: set spelllang=en:
2-
3-
# Metadata
4-
# Currently in master branch of add-on SDK, but not in current stable v1.17
5-
addon_description = Syntax highlight for raw source code.
6-
7-
# Preferences
8-
style_title = Color theme
9-
style_description = Select the color theme you want to use for syntax highlighting.
10-
autohl_title = Auto-highlight source code files
11-
autohl_description = Automatically apply highlighting to pages detected as source code (technically, detection occurs when HTML body contains a single child of name <pre></pre>).
12-
invert_title = Alternate icon set
13-
invert_description = Use white (instead of dark gray) icons for the button, for a better contrast on dark themes.
14-
bgColor_title = Adapt body background color
15-
bgColor_description = Make HTML body background color the same as background color for the code block. Should remove white border around highlighted code. Disable if you use the add-on on web pages other than plain text source code files.
16-
lineNumbers_title = Add line numbering
17-
lineNumbers_description = Display line numbers on the left of highlighted content. When this option is enabled, one can also scroll to e.g. line 27 and select it if a suffix such as “#Line27” or “#line27” or “#L27” or “#l27” is appended to the URL BEFORE the script loads (this does not relies on HTML anchors and cannot be triggered by simple URL modification; reload the script for current page if you added the suffix afterward).
18-
19-
# Button
20-
button_label = Highlight raw source code
21-
22-
# Language selection panel
23-
autodetect = Auto-detect
24-
no_language = None
25-
26-
# Logs
27-
log_highlight = Let's (try to) highlight code for language “%s” with style “%s”.
28-
log_undo = Oh, well, let's get back to initial content.
29-
log_toggleoff = Received toggle off request from content script for reason “%s”.
30-
log_toff_r1 = nothing to work on in this document
31-
log_toff_r2 = document is unloaded
1+
{
2+
"description": {
3+
"message": "Syntax highlighting for raw source code files.",
4+
"description": "Description of the extension."
5+
}
6+
}

_locales/fr/messages.json

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,6 @@
1-
# Vim: set spelllang=fr:
2-
3-
# Métadata
4-
# Currently in master branch of add-on SDK, but not in current stable v1.17
5-
addon_description = Coloration syntaxique sur code source brut.
6-
7-
# Préférences
8-
style_title = Thème
9-
style_description = Sélectionnez le jeu de couleurs à utiliser pour la coloration syntaxique.
10-
autohl_title = Coloration automatique du code source
11-
autohl_description = Lance automatiquement la coloration syntaxique à l'ouverture des pages détectées comme étant des fichiers sources (du point de vue technique, cette détection survient lorsque l'élément HTML body contient un unique nœud, de type <pre></pre>).
12-
invert_title = Icônes alternatives
13-
invert_description = Utiliser des icônes blanches (plutôt que gris foncé) pour le bouton, pour un meilleur contraste sur un thème foncé.
14-
bgColor_title = Adapter la couleur d'arrière-plan de l'élément body
15-
bgColor_description = Étend la couleur d'arrière plan du bloc de code coloré à l'élément body du document HTML. Cela permet en principe de retirer la bordure blanche qui apparaît autour du bloc coloré. Désactivez cette option si vous utilisez cette extension pour des pages web autres que contenant seulement du code source au format texte.
16-
lineNumbers_title = Numéroter les lignes
17-
lineNumbers_description = Affiche le numéro de chaque ligne à gauche du contenu coloré. Lorsque cette option est activée, il est possible de sauter à la ligne fournie, par exemple 27, et de la mettre en surbrillance si l'URL comporte un suffixe de la forme « #Line27 » ou « #line27 » ou « #L27 » ou « #l27 ». Ce suffixe doit être ajouté AVANT le chargement du script (la fonctionnalité ne repose pas sur les ancres HTML et ne peut pas détecter une simple modification de l'URL. Si le suffixe est ajouté après le chargement du script pour la page en cours, il suffit de recharger ce dernier).
18-
19-
# Bouton
20-
button_label = Coloration syntaxique de code
21-
22-
# Panneau de sélection du langage
23-
autodetect = Détection auto
24-
no_language = Aucun
25-
26-
# Logs
27-
log_highlight = Essayons la coloration syntaxique pour le langage « %s » avec le thème « %s ».
28-
log_undo = Retour au contenu initial du document.
29-
log_toggleoff = Le script de contenu signale l'absence de coloration pour la raison « %s ».
30-
log_toff_r1 = aucun bloc sur lequel travailler dans ce document
31-
log_toff_r2 = le document est déchargé du navigateur
1+
{
2+
"description": {
3+
"message": "Coloration syntaxique pour code source brut.",
4+
"description": "Description of the extension."
5+
}
6+
}

icons/lightbulb-dark-19x32.png

1.11 KB
Loading

icons/lightbulb-dark.svg

Lines changed: 76 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)