Skip to content

Commit 83beab7

Browse files
committed
Merge with upstream nbviewer.js
2 parents dac4d96 + a110692 commit 83beab7

File tree

4 files changed

+14
-222
lines changed

4 files changed

+14
-222
lines changed

nbviewer.js/README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ There are two ways one can use this. You can use the library itself, there is ju
1414

1515
Or you can use [the demo](https://kokes.github.io/nbviewer.js/viewer.html) (or a local copy), which is just a simple wrapper of the library, with dropzones and other basic features. There is no data being transferred anywhere, so feel free to bookmark it and use it.
1616

17-
Two immediate use cases come to mind:
18-
19-
1. ~~In Mac OS, you can preview files and this system, [Quick Look](https://support.apple.com/kb/PH21920?locale=en_US), supports plugins. It would be rather handy to have a notebook preview one keystroke away.~~ This has been done, see [ipynb-quicklook](https://github.com/tuxu/ipynb-quicklook).
20-
2. Ever since GitHub introduced notebook rendering last year, Gitlab users have been [requesting the same](https://gitlab.com/gitlab-org/gitlab-ce/issues/2508). Gitlab itself recently dropped Python as a dependency, so its reintroduction just for converting notebooks is rather unlikely. A browser-based solution like this could be a good substitute.
21-
2217
### Tech details
2318
It's rather simple at this point, all the DOM manipulation is written in vanilla JavaScript, Markdown rendering goes through [marked.js](https://github.com/chjj/marked), syntax highlighting is administered by [Prism.js](http://prismjs.com/). The example implementation leverages a few goodies from modern web design, like File API or drag&drops, so a fairly modern browser is necessary.
2419

nbviewer.js/github-browser.html

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

nbviewer.js/lib/nbv.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ var nbv = (function() {
116116

117117
// no need to join on '\n' - newlines are in the code already
118118
// .source for v4, .input for v3
119-
code.textContent = (cell.source || cell.input).join('');
119+
var raw_source = (cell.source || cell.input)
120+
code.textContent = typeof raw_source === 'string' ? raw_source : raw_source.join('');
120121

121122
pre.appendChild(code);
122123
el.appendChild(pre);
@@ -183,7 +184,7 @@ var nbv = (function() {
183184

184185
dm = d.createElement('pre');
185186
dm.style.margin = 0;
186-
dm.textContent = dt.data[fmt].join('');
187+
dm.textContent = typeof dt.data[fmt] === 'string' ? dt.data[fmt] : dt.data[fmt].join('');
187188
break;
188189

189190
case 'text/html':
@@ -216,6 +217,16 @@ var nbv = (function() {
216217
dm = d.createElement('img');
217218
dm.setAttribute('src', 'data:' + fmt + ';base64,' +
218219
((typeof dt.data[fmt]) == 'string' ? dt.data[fmt] : dt.data[fmt].join('')));
220+
// use width and height attributes supplied in metadata
221+
if (fmt in dt.metadata) {
222+
var metadata = dt.metadata[fmt];
223+
if ('width' in metadata) {
224+
dm.setAttribute('width', metadata.width);
225+
}
226+
if ('height' in metadata) {
227+
dm.setAttribute('height', metadata.height);
228+
}
229+
}
219230
break;
220231
}
221232
console.error('unexpected format: ' + fmt);

nbviewer.js/viewer.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050

5151
<div id='doc'>
5252
<select id='file-selector'></select>
53-
<div id='instructions'>Drag and drop Jupyter notebooks anywhere here<br />
54-
<small>(if you wish to render directly from Github, <a href='github-browser.html'>try our new tool</a>)</small></div>
53+
<div id='instructions'>Drag and drop Jupyter notebooks anywhere here</div>
5554

5655
</div>
5756

0 commit comments

Comments
 (0)