Skip to content

Commit 05aa305

Browse files
authored
Merge pull request #2 from arobrien/arobrien/browserify
Change to nodejs + browserify format
2 parents 30bbe33 + f79c868 commit 05aa305

File tree

15 files changed

+549
-235
lines changed

15 files changed

+549
-235
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
package-lock.json
3+
*bundle.js
4+
*.log

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# nbchrome
22
A lightweight viewer for Jupyter Notebooks as a Chrome Extension.
33
This project differentiates from Jupyter Notebook Viewer by not requiring any server process.
4+
No data is sent or received over the network by the plugin.
45

56
**Note: This project is currently at the proof-of-concept phase and some functionality may be missing.
67
I would appreciate pull requests or git issues.**
@@ -11,10 +12,12 @@ I would appreciate pull requests or git issues.**
1112

1213
Installation:
1314
1. Download to a local folder.
14-
2. Go to chrome://extensions and enable developer mode in the top-right corner.
15-
3. Click 'Load unpacked' from the top-left corner and select the extension.
16-
4. Open any .ipynb file in Chrome.
17-
5. If you edit or update the extension, hit the reload button for the extension in the extension manager.
15+
2. Install nodejs
16+
3. npm install
17+
4. npm build-dev
18+
5. Go to chrome://extensions and enable developer mode in the top-right corner.
19+
6. Click 'Load unpacked' from the top-left corner and select the extension folder.
20+
7. Open any .ipynb file in Chrome.
1821

1922
At the moment, if you hit an error it's probably because of some element that the script isn't handling.
2023
If this happens it will probably just show you the raw json and look like nothing else happened.

filters/ansi.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
module.exports = {
2+
ansi2html: ansi2html,
3+
_get_extended_color: _get_extended_color,
4+
_make_ansi_tags: _make_ansi_tags
5+
};
6+
17
_ANSI_COLORS = [
28
'ansi-black',
39
'ansi-red',
@@ -221,23 +227,3 @@ function _make_ansi_tags(fg, bg, bold, underline, inverse) {
221227

222228
return [starttag, '</span>']
223229
}
224-
225-
226-
if (
227-
typeof module !== 'undefined' &&
228-
module.exports &&
229-
typeof exports !== 'undefined'
230-
) {
231-
module.exports = {
232-
ansi2html: ansi2html,
233-
_get_extended_color: _get_extended_color,
234-
_make_ansi_tags: _make_ansi_tags
235-
};
236-
}
237-
else {
238-
ansi = {
239-
ansi2html: ansi2html,
240-
_get_extended_color: _get_extended_color,
241-
_make_ansi_tags: _make_ansi_tags
242-
};
243-
}

filters/simple_filters.js

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
const showdown = require('showdown');
2+
const hljs = require('highlightjs');
3+
4+
module.exports = {
5+
filter_data_type: filter_data_type,
6+
get_metadata: get_metadata,
7+
highlight_code: highlight_code,
8+
json_dumps: json_dumps,
9+
markdown2html: markdown2html,
10+
posix_path: posix_path,
11+
strip_files_prefix: strip_files_prefix
12+
};
13+
14+
115
DISPLAY_DATA_PRIORITY = [
216
'text/html',
317
'application/pdf',
@@ -35,8 +49,8 @@ function get_metadata(output, key, mimetype=undefined) {
3549
return md[key];
3650
}
3751

38-
function highlight_code(source, language, metadata=undefined) {
39-
return hljs.highlight(language, source, false, false);
52+
function highlight_code(source) {
53+
return hljs.highlight(window.notebook_language, source.join(''), true).value;
4054
}
4155

4256
function json_dumps(obj) {
@@ -45,7 +59,7 @@ function json_dumps(obj) {
4559

4660
function markdown2html(source) {
4761
const converter = new showdown.Converter();
48-
return converter.makeHtml(source);
62+
return converter.makeHtml(source.join(''));
4963
}
5064

5165
function posix_path(path) {
@@ -59,29 +73,5 @@ function strip_files_prefix(dirty_text) {
5973
/(!?)\[(.*?)\]\(\/?files\/(.*?)\)/g, (m,p1,p2,p3) => p1 + '[' + p2 + '](' + p3 + ')');
6074
}
6175

62-
if (
63-
typeof module !== 'undefined' &&
64-
module.exports &&
65-
typeof exports !== 'undefined'
66-
) {
67-
module.exports = {
68-
filter_data_type: filter_data_type,
69-
get_metadata: get_metadata,
70-
highlight_code: highlight_code,
71-
json_dumps: json_dumps,
72-
markdown2html: markdown2html,
73-
posix_path: posix_path,
74-
strip_files_prefix: strip_files_prefix
75-
};
76-
}
77-
else {
78-
simple_filters = {
79-
filter_data_type: filter_data_type,
80-
get_metadata: get_metadata,
81-
highlight_code: highlight_code,
82-
json_dumps: json_dumps,
83-
markdown2html: markdown2html,
84-
posix_path: posix_path,
85-
strip_files_prefix: strip_files_prefix
86-
};
87-
}
76+
77+

highlight/docco.css

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
Docco style used in http://jashkenas.github.com/docco/ converted by Simon Madine (@thingsinjars)
3+
*/
4+
5+
.hljs {
6+
display: block;
7+
overflow-x: auto;
8+
padding: 0.5em;
9+
color: #000;
10+
background: #f8f8ff;
11+
}
12+
13+
.hljs-comment,
14+
.hljs-quote {
15+
color: #408080;
16+
font-style: italic;
17+
}
18+
19+
.hljs-keyword,
20+
.hljs-selector-tag,
21+
.hljs-literal,
22+
.hljs-subst {
23+
color: #954121;
24+
}
25+
26+
.hljs-number {
27+
color: #40a070;
28+
}
29+
30+
.hljs-string,
31+
.hljs-doctag {
32+
color: #219161;
33+
}
34+
35+
.hljs-selector-id,
36+
.hljs-selector-class,
37+
.hljs-section,
38+
.hljs-type {
39+
color: #19469d;
40+
}
41+
42+
.hljs-params {
43+
color: #00f;
44+
}
45+
46+
.hljs-title {
47+
color: #458;
48+
font-weight: bold;
49+
}
50+
51+
.hljs-tag,
52+
.hljs-name,
53+
.hljs-attribute {
54+
color: #000080;
55+
font-weight: normal;
56+
}
57+
58+
.hljs-variable,
59+
.hljs-template-variable {
60+
color: #008080;
61+
}
62+
63+
.hljs-regexp,
64+
.hljs-link {
65+
color: #b68;
66+
}
67+
68+
.hljs-symbol,
69+
.hljs-bullet {
70+
color: #990073;
71+
}
72+
73+
.hljs-built_in,
74+
.hljs-builtin-name {
75+
color: #0086b3;
76+
}
77+
78+
.hljs-meta {
79+
color: #999;
80+
font-weight: bold;
81+
}
82+
83+
.hljs-deletion {
84+
background: #fdd;
85+
}
86+
87+
.hljs-addition {
88+
background: #dfd;
89+
}
90+
91+
.hljs-emphasis {
92+
font-style: italic;
93+
}
94+
95+
.hljs-strong {
96+
font-weight: bold;
97+
}

highlight/highlight.min.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

manifest.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Notebook Chrome Viewer",
3-
"version": "0.1",
3+
"version": "0.2.0",
44
"description": "A lightweight viewer for Jupyter Notebooks",
55
"author": "Andrew O'Brien",
66
"permissions": ["declarativeContent"],
@@ -10,14 +10,10 @@
1010
"run_at": "document_end",
1111
"css": [
1212
"styles.css",
13-
"highlight/default.min.css"
13+
"highlight/docco.css"
1414
],
1515
"js": [
16-
"showdown/showdown.min.js",
17-
"highlight/highlight.min.js",
18-
"mathjax_config.js",
19-
"mathjax/tex-chtml.js",
20-
"view_notebook.js"
16+
"view_notebook_bundle.js"
2117
]
2218
}
2319
],

mathjax/tex-chtml.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)