Skip to content

Commit

Permalink
Use highlight.js instead of prettify for syntax coloring
Browse files Browse the repository at this point in the history
Originally based from work by @dotandimet.

Additional changes:

* highlight.js: Update to latest (10.3.1)

Install custom build limiting highlights for diff, plaintext, makefile,
bash, html/xml, sql, css, and perl only, to reduce from the normal
common pack size (100k to just 40k.)

This also adds the Mojolicious language plugin for highlight.js.

* debug.html.ep: Simplifiy highlight.js loading

Follow https://highlightjs.org/usage for this case, it seems more
reliable to let it highlight as well as determine the language to
be highlighted on its own.

* highlight-mojo-dark.css: Remake based on newer upstream dark theme

* Drop highligh-mojo-light.css

No longer needed here.

* Mojolicious.pm: Add license section for highlight.js

* Remove prettify.js

highlight.js now replaces it.  Thanks for the service, prettify.js!
  • Loading branch information
zakame committed Oct 24, 2020
1 parent 2df309b commit be6dc11
Show file tree
Hide file tree
Showing 8 changed files with 472 additions and 72 deletions.
6 changes: 3 additions & 3 deletions lib/Mojolicious.pm
Original file line number Diff line number Diff line change
Expand Up @@ -744,11 +744,11 @@ Licensed under the CC-SA License, Version 4.0 L<http://creativecommons.org/licen
Licensed under the MIT License, L<http://creativecommons.org/licenses/MIT>.
=head2 prettify.js
=head2 highlight.js
Copyright (C) 2006, 2013 Google Inc..
Copyright (C) 2006, Ivan Sagalaev.
Licensed under the Apache License, Version 2.0 L<http://www.apache.org/licenses/LICENSE-2.0>.
Licensed under the BSD License, L<https://github.com/highlightjs/highlight.js/blob/master/LICENSE>.
=head1 CODE NAMES
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.hljs {
display: block;
overflow-x: auto;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-section,
.hljs-link {
color:#fcf0a4;
}

.hljs,
.hljs-subst {
color:#889dbc;
}

.hljs-string,
.hljs-title,
.hljs-name,
.hljs-type,
.hljs-attribute,
.hljs-symbol,
.hljs-bullet,
.hljs-built_in,
.hljs-addition,
.hljs-variable,
.hljs-template-tag,
.hljs-template-variable {
color: #9daa7e;
}

.hljs-comment,
.hljs-quote,
.hljs-deletion,
.hljs-meta {
color:#726d73;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-title,
.hljs-section,
.hljs-doctag,
.hljs-type,
.hljs-name,
.hljs-strong {
font-weight: bold;
color:#d5b57c;
}

.hljs-emphasis {
font-style: italic;
}
402 changes: 402 additions & 0 deletions lib/Mojolicious/resources/public/mojo/highlight.js/highlight.min.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

63 changes: 0 additions & 63 deletions lib/Mojolicious/resources/public/mojo/prettify/run_prettify.js

This file was deleted.

10 changes: 7 additions & 3 deletions lib/Mojolicious/resources/templates/mojo/debug.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
%= javascript '/mojo/jquery/jquery.js'
%= javascript '/mojo/prettify/run_prettify.js'
%= stylesheet '/mojo/prettify/prettify-mojo-dark.css'
%= javascript '/mojo/highlight.js/highlight.min.js'
%= javascript '/mojo/highlight.js/mojolicious.min.js'
%= stylesheet '/mojo/highlight.js/highlight-mojo-dark.css'
<script>
hljs.initHighlightingOnLoad();
</script>
<style>
a img {
border: 0;
Expand Down Expand Up @@ -263,7 +267,7 @@
%= tag 'tr', $i ? (class => 'important') : (), begin
<td class="key"><%= $key %></td>
<td class="value wide">
<pre><code class="prettyprint"><%= $value %></code></pre>
<pre><code><%= $value %></code></pre>
</td>
% end
% end
Expand Down
5 changes: 3 additions & 2 deletions t/mojolicious/exception_lite_app.t
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,9 @@ subtest 'Reuse exception' => sub {
subtest 'Bundled static files' => sub {
$t->get_ok('/mojo/jquery/jquery.js')->status_is(200)->content_type_is('application/javascript');

$t->get_ok('/mojo/prettify/run_prettify.js')->status_is(200)->content_type_is('application/javascript');
$t->get_ok('/mojo/prettify/prettify-mojo-dark.css')->status_is(200)->content_type_is('text/css');
$t->get_ok('/mojo/highlight.js/highlight.min.js')->status_is(200)->content_type_is('application/javascript');
$t->get_ok('/mojo/highlight.js/mojolicious.min.js')->status_is(200)->content_type_is('application/javascript');
$t->get_ok('/mojo/highlight.js/highlight-mojo-dark.css')->status_is(200)->content_type_is('text/css');

$t->get_ok('/mojo/failraptor.png')->status_is(200)->content_type_is('image/png');
$t->get_ok('/mojo/logo.png')->status_is(200)->content_type_is('image/png');
Expand Down

0 comments on commit be6dc11

Please sign in to comment.