From 427bc961ee20152097fb7f77c52514bf7dedbf37 Mon Sep 17 00:00:00 2001 From: Reece Hart Date: Wed, 26 Sep 2018 21:29:05 -0700 Subject: [PATCH 1/2] closes #4029: implement optional markdown header and footer files --- docs/source/examples/Notebook/header.md | 4 +++ notebook/static/tree/js/notebooklist.js | 37 +++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 docs/source/examples/Notebook/header.md diff --git a/docs/source/examples/Notebook/header.md b/docs/source/examples/Notebook/header.md new file mode 100644 index 000000000..532919d1f --- /dev/null +++ b/docs/source/examples/Notebook/header.md @@ -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/) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 010a95a56..74fd0a905 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -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){ @@ -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'); @@ -528,6 +530,37 @@ 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) { + // input_area.getDoc().setValue(data.content); + // span12.append($('
').text(data.content)); + span12.append($('
').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 From b5a488835e2a40eb43b06d653fb41cde0e894815 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 8 Jun 2020 05:12:07 -0500 Subject: [PATCH 2/2] remove commented out code --- notebook/static/tree/js/notebooklist.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/notebook/static/tree/js/notebooklist.js b/notebook/static/tree/js/notebooklist.js index 74fd0a905..eefc9992e 100644 --- a/notebook/static/tree/js/notebooklist.js +++ b/notebook/static/tree/js/notebooklist.js @@ -542,8 +542,6 @@ define([ span12.empty(); that.contents.get(list_item.path, {"content": true}).then( function (data) { - // input_area.getDoc().setValue(data.content); - // span12.append($('
').text(data.content)); span12.append($('
').innerHTML = marked(data.content)); }, function(error) {