diff --git a/.travis.yml b/.travis.yml index 368445f..4f1a31a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ before_install: - time sudo apt-get update - time sudo apt-get install pandoc casperjs nodejs libzmq3-dev - time pip install -f https://nipy.bic.berkeley.edu/wheelhouse/travis jinja2 sphinx pygments tornado requests mock pyzmq jsonschema jsonpointer + - time npm install requirejs r.js jquery install: - time python setup.py install -q script: diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index ce30bc2..f1db79a 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -8,7 +8,8 @@ define([ 'base/js/security', 'notebook/js/mathjaxutils', 'notebook/js/celltoolbar', -], function(IPython, $, cell, security, mathjaxutils, celltoolbar) { + 'components/marked/lib/marked', +], function(IPython, $, cell, security, mathjaxutils, celltoolbar, marked) { "use strict"; var Cell = cell.Cell; diff --git a/IPython/nbconvert/filters/marked.js b/IPython/nbconvert/filters/marked.js index 2816630..aa98ac7 100644 --- a/IPython/nbconvert/filters/marked.js +++ b/IPython/nbconvert/filters/marked.js @@ -5,50 +5,59 @@ // IPython static_path dir relative to here: var static_path = __dirname + "/../../html/static/"; -var fs = require('fs'); -var IPython; -// marked can be loaded with require, -// the others must be execfiled -var marked = require(static_path + 'components/marked/lib/marked.js'); - -eval(fs.readFileSync(static_path + "components/highlight.js/build/highlight.pack.js", 'utf8')); -eval(fs.readFileSync(static_path + "base/js/namespace.js", 'utf8')); +// Excerpt from the example in require.js docs +// http://requirejs.org/docs/node.html +var requirejs = require('requirejs'); +requirejs.config({ + //Pass the top-level main.js/index.js require + //function to requirejs so that node modules + //are loaded relative to the top-level JS file. + nodeRequire: require, + baseUrl: static_path, +}); -eval(fs.readFileSync(static_path + "base/js/utils.js", 'utf8')); -eval(fs.readFileSync(static_path + "notebook/js/mathjaxutils.js", 'utf8')); +requirejs([ + 'fs', + 'components/marked/lib/marked', + 'components/highlight.js/build/highlight.pack', + 'base/js/utils', + 'notebook/js/mathjaxutils', + ], function(fs, marked, hljs, utils, mathjaxutils) { -// this is copied from notebook.main. Should it be moved somewhere we can reuse it? -marked.setOptions({ - gfm : true, - tables: true, - langPrefix: "language-", - highlight: function(code, lang) { - if (!lang) { - // no language, no highlight - return code; - } - var highlighted; - try { - highlighted = hljs.highlight(lang, code, false); - } catch(err) { - highlighted = hljs.highlightAuto(code); + // this is copied from notebook.main. Should it be moved somewhere we can reuse it? + marked.setOptions({ + gfm : true, + tables: true, + langPrefix: "language-", + highlight: function(code, lang) { + if (!lang) { + // no language, no highlight + return code; + } + var highlighted; + try { + highlighted = hljs.highlight(lang, code, false); + } catch(err) { + highlighted = hljs.highlightAuto(code); + } + return highlighted.value; } - return highlighted.value; - } -}); + }); -// read the markdown from stdin -var md=''; -process.stdin.on("data", function (data) { - md += data; -}); + // read the markdown from stdin + var md=''; + process.stdin.on("data", function (data) { + md += data; + }); + + // perform the md2html transform once stdin is complete + process.stdin.on("end", function () { + var text_and_math = mathjaxutils.remove_math(md); + var text = text_and_math[0]; + var math = text_and_math[1]; + var html = marked.parser(marked.lexer(text)); + html = mathjaxutils.replace_math(html, math); + process.stdout.write(html); + }); -// perform the md2html transform once stdin is complete -process.stdin.on("end", function () { - var text_and_math = IPython.mathjaxutils.remove_math(md); - var text = text_and_math[0]; - var math = text_and_math[1]; - var html = marked.parser(marked.lexer(text)); - html = IPython.mathjaxutils.replace_math(html, math); - process.stdout.write(html); });