From d696260294d84178716fbd32832bf2eeda600693 2014-05-21 18:00:47 From: Jonathan Frederic Date: 2014-05-21 18:00:47 Subject: [PATCH] Create ipythongfm mode --- diff --git a/IPython/html/static/notebook/js/codemirror-ipythongfm.js b/IPython/html/static/notebook/js/codemirror-ipythongfm.js new file mode 100644 index 0000000..f4804ec --- /dev/null +++ b/IPython/html/static/notebook/js/codemirror-ipythongfm.js @@ -0,0 +1,45 @@ +// IPython GFM (GitHub Flavored Markdown) mode is just a slightly altered GFM +// Mode with support for latex. +// +// Latex support was supported by Codemirror GFM as of +// https://github.com/marijnh/CodeMirror/pull/567 +// But was later removed in +// https://github.com/marijnh/CodeMirror/commit/d9c9f1b1ffe984aee41307f3e927f80d1f23590c + +CodeMirror.requireMode('gfm', function(){ + CodeMirror.requireMode('stex', function(){ + console.log('defining custom mode...'); + CodeMirror.defineMode("ipythongfm", function(config, parserConfig) { + + var gfm_mode = CodeMirror.getMode(config, "gfm"); + var tex_mode = CodeMirror.getMode(config, "stex"); + + return CodeMirror.multiplexingMode( + gfm_mode, + { + open: "$", close: "$", + mode: tex_mode, + delimStyle: "delimit" + }, + { + open: "$$", close: "$$", + mode: tex_mode, + delimStyle: "delimit" + }, + { + open: "\\(", close: "\\)", + mode: tex_mode, + delimStyle: "delimit" + }, + { + open: "\\[", close: "\\]", + mode: tex_mode, + delimStyle: "delimit" + } + // .. more multiplexed styles can follow here + ); + }, 'gfm'); + + CodeMirror.defineMIME("text/x-ipythongfm", "ipythongfm"); + }); +}); diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index 9b7724a..78a56da 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -234,7 +234,7 @@ var IPython = (function (IPython) { MarkdownCell.options_default = { cm_config: { - mode: 'gfm' + mode: 'ipythongfm' }, placeholder: "Type *Markdown* and LaTeX: $\\alpha^2$" }; diff --git a/IPython/html/templates/notebook.html b/IPython/html/templates/notebook.html index 45ab6fa..db19052 100644 --- a/IPython/html/templates/notebook.html +++ b/IPython/html/templates/notebook.html @@ -316,6 +316,7 @@ class="notebook_app" +