Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Commit

Permalink
Add lineNumbers option
Browse files Browse the repository at this point in the history
  • Loading branch information
lelinhtinh committed Aug 18, 2020
1 parent 0d974ef commit fc15fb9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
3 changes: 3 additions & 0 deletions _data/options.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- key: lineNumbers
name: Line numbers
checked: false
- key: _unescape
name: Unescape
checked: false
Expand Down
1 change: 1 addition & 0 deletions _includes/highlight-js/styles/hljs-line-numbers.css

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

1 change: 1 addition & 0 deletions assets/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $special-disabled-color: #000000;

@import "{{ site.theme }}";
{% include highlight-js/styles/hljs-theme.css %}
{% include highlight-js/styles/hljs-line-numbers.css %}
.hljs{
background: #030303;
}
Expand Down
14 changes: 9 additions & 5 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
renderRemove = document.getElementById('renderRemove'),
view = document.getElementById('view'),
encode = document.getElementsByName('encode'),
options,
none = document.getElementById('none'),
readable = document.getElementById('readable'),
form = document.de4js,
Expand Down Expand Up @@ -117,6 +118,11 @@
clear.disabled = true;
autoBtn.disabled = true;
disableAll(true);

options = Array.from(document.querySelectorAll('.de4js-option')).reduce((obj, e) => {
obj[e.name] = e.checked;
return obj;
}, {});
},
stopEffect = function () {
isAuto = false;
Expand All @@ -137,7 +143,7 @@
}, 800);
},
externalStyle =
'*{margin:0;padding:0}html{line-height:1em;background:#1d1f21;color:#c5c8c6}pre{white-space:pre-wrap;word-wrap:break-word;word-break:break-all}{% include highlight-js/styles/hljs-theme.css %}html,body,.hljs{background:#030303}',
'*{margin:0;padding:0}html{line-height:1em;background:#1d1f21;color:#c5c8c6}pre{white-space:pre-wrap;word-wrap:break-word;word-break:break-all}{% include highlight-js/styles/hljs-theme.css %}{% include highlight-js/styles/hljs-line-numbers.css %}html,body,.hljs{background:#030303}',
externalUrl,
externalPreview = function (source) {
if (externalUrl) URL.revokeObjectURL(externalUrl);
Expand Down Expand Up @@ -192,6 +198,7 @@
startEffect();
workerFormat.postMessage({
source: temp,
options: options,
});
}, 250),
detect = function (source) {
Expand Down Expand Up @@ -262,10 +269,7 @@
workerDecode.postMessage({
source: temp,
packer: packer,
options: Array.from(document.querySelectorAll('.de4js-option')).reduce((obj, e) => {
obj[e.name] = e.checked;
return obj;
}, {}),
options: options,
});
}, 250),
changeEncode = function (e) {
Expand Down
7 changes: 7 additions & 0 deletions assets/js/worker/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

self.addEventListener('message', (e) => {
let source = e.data.source;
const options = e.data.options;

try {
self._window = self.window;
Expand All @@ -37,6 +38,12 @@ self.addEventListener('message', (e) => {
self.importScripts('{{ "/assets/js/vendor/highlight-js/highlight.min.js" | relative_url }}');

source = self.hljs.highlight('javascript', source).value;

if (options.lineNumbers) {
source = source.split('\n');
source = source.join('</code><code>');
source = `<code>${source}</code>`;
}
} catch (err) {
console.log(err);
}
Expand Down

0 comments on commit fc15fb9

Please sign in to comment.