Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #4029: implement optional markdown header and footer files #4043

Merged
merged 2 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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