From 258470e19cd653b3c317bc9c2c8c5599e79f7e4b Mon Sep 17 00:00:00 2001 From: Peter Parente Date: Tue, 8 Dec 2015 22:31:52 -0500 Subject: [PATCH] Support multicell selection in markdown conversion Fixes #803 (c) Copyright IBM Corp. 2015 --- notebook/static/notebook/js/actions.js | 2 +- notebook/static/notebook/js/maintoolbar.js | 2 +- notebook/static/notebook/js/notebook.js | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/notebook/static/notebook/js/actions.js b/notebook/static/notebook/js/actions.js index 2774fe80b..9674b35c5 100644 --- a/notebook/static/notebook/js/actions.js +++ b/notebook/static/notebook/js/actions.js @@ -254,7 +254,7 @@ define(function(require){ help : 'to markdown', help_index : 'cb', handler : function (env) { - env.notebook.to_markdown(); + env.notebook.cells_to_markdown(); } }, 'change-cell-to-raw' : { diff --git a/notebook/static/notebook/js/maintoolbar.js b/notebook/static/notebook/js/maintoolbar.js index 10af1d07d..f6ad540c9 100644 --- a/notebook/static/notebook/js/maintoolbar.js +++ b/notebook/static/notebook/js/maintoolbar.js @@ -111,7 +111,7 @@ define([ that.notebook.cells_to_code(); break; case 'markdown': - that.notebook.to_markdown(); + that.notebook.cells_to_markdown(); break; case 'raw': that.notebook.cells_to_raw(); diff --git a/notebook/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js index 3d91a5274..fca65f0cd 100644 --- a/notebook/static/notebook/js/notebook.js +++ b/notebook/static/notebook/js/notebook.js @@ -1191,6 +1191,7 @@ define(function (require) { this.to_code(indices[i]); } }; + /** * Turn a cell into a code cell. * @@ -1222,6 +1223,21 @@ define(function (require) { } }; + /** + * Turn one or more cells into Markdown. + * + * @param {Array} indices - cell indices to convert + */ + Notebook.prototype.cells_to_markdown = function (indices) { + if (indices === undefined) { + indices = this.get_selected_cells_indices(); + } + + for(var i=0; i < indices.length; i++) { + this.to_markdown(indices[i]); + } + }; + /** * Turn a cell into a Markdown cell. *