Skip to content

Commit 9fa644b

Browse files
authored
Merge pull request #4043 from reece/4029-header-and-footer
closes #4029: implement optional markdown header and footer files
2 parents 7866742 + b5a4888 commit 9fa644b

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Notebook Examples
2+
3+
The pages in this section are all converted notebook files. You can also
4+
[view these notebooks on nbviewer](http://nbviewer.jupyter.org/github/jupyter/notebook/blob/master/)

notebook/static/tree/js/notebooklist.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ define([
1010
'base/js/events',
1111
'base/js/keyboard',
1212
'moment',
13-
'bidi/bidi'
14-
], function($, IPython, utils, i18n, dialog, events, keyboard, moment, bidi) {
13+
'bidi/bidi',
14+
'components/marked/lib/marked'
15+
], function($, IPython, utils, i18n, dialog, events, keyboard, moment, bidi, marked) {
1516
"use strict";
1617

1718
var extension = function(path){
@@ -509,6 +510,7 @@ define([
509510
console.log('Error adding link: ' + err);
510511
}
511512
}
513+
this.add_header_footer(list)
512514
// Trigger an event when we've finished drawing the notebook list.
513515
events.trigger('draw_notebook_list.NotebookList');
514516

@@ -528,6 +530,35 @@ define([
528530
};
529531

530532

533+
/**
534+
* Adds header and/or footer
535+
* @param {Array} list - list of folder contents
536+
*/
537+
NotebookList.prototype.add_header_footer = function (list) {
538+
var that = this;
539+
function create_markdown_row(index, list_item) {
540+
var item = that.new_item(index);
541+
var span12 = item.children().first();
542+
span12.empty();
543+
that.contents.get(list_item.path, {"content": true}).then(
544+
function (data) {
545+
span12.append($('<div style="margin:auto;text-align:center;color:grey"/>').innerHTML = marked(data.content));
546+
},
547+
function(error) {
548+
span12.append(i18n.msg._("Server error: ") + error.message);
549+
});
550+
};
551+
var f = list.content.find(function (el) {return el.name == "header.md"})
552+
if (f !== undefined) {
553+
create_markdown_row(0, f)
554+
}
555+
var f = list.content.find(function (el) {return el.name == "footer.md"})
556+
if (f !== undefined) {
557+
create_markdown_row(-1, f)
558+
}
559+
}
560+
561+
531562
/**
532563
* Creates a new item.
533564
* @param {integer} index

0 commit comments

Comments
 (0)