Skip to content

Commit

Permalink
Merge pull request #4043 from reece/4029-header-and-footer
Browse files Browse the repository at this point in the history
closes #4029: implement optional markdown header and footer files
  • Loading branch information
kevin-bates authored Jun 19, 2020
2 parents 7866742 + b5a4888 commit 9fa644b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/source/examples/Notebook/header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Notebook Examples

The pages in this section are all converted notebook files. You can also
[view these notebooks on nbviewer](http://nbviewer.jupyter.org/github/jupyter/notebook/blob/master/)
35 changes: 33 additions & 2 deletions notebook/static/tree/js/notebooklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ define([
'base/js/events',
'base/js/keyboard',
'moment',
'bidi/bidi'
], function($, IPython, utils, i18n, dialog, events, keyboard, moment, bidi) {
'bidi/bidi',
'components/marked/lib/marked'
], function($, IPython, utils, i18n, dialog, events, keyboard, moment, bidi, marked) {
"use strict";

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

Expand All @@ -528,6 +530,35 @@ define([
};


/**
* Adds header and/or footer
* @param {Array} list - list of folder contents
*/
NotebookList.prototype.add_header_footer = function (list) {
var that = this;
function create_markdown_row(index, list_item) {
var item = that.new_item(index);
var span12 = item.children().first();
span12.empty();
that.contents.get(list_item.path, {"content": true}).then(
function (data) {
span12.append($('<div style="margin:auto;text-align:center;color:grey"/>').innerHTML = marked(data.content));
},
function(error) {
span12.append(i18n.msg._("Server error: ") + error.message);
});
};
var f = list.content.find(function (el) {return el.name == "header.md"})
if (f !== undefined) {
create_markdown_row(0, f)
}
var f = list.content.find(function (el) {return el.name == "footer.md"})
if (f !== undefined) {
create_markdown_row(-1, f)
}
}


/**
* Creates a new item.
* @param {integer} index
Expand Down

0 comments on commit 9fa644b

Please sign in to comment.