From 0e04fff0ea80fa5cbe96b8354db38bd334aea83a Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 16 Jul 2012 16:04:05 -0700 Subject: upgrade to codemirror 2.3 Signed-off-by: Ananya Sen Conflicts: js/code-editor/codemirror-ninja/theme/lesser-dark-ninja.css Signed-off-by: Ananya Sen --- imports/codemirror/mode/gfm/gfm.js | 42 +++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'imports/codemirror/mode/gfm/gfm.js') diff --git a/imports/codemirror/mode/gfm/gfm.js b/imports/codemirror/mode/gfm/gfm.js index 01afed7b..8f457c53 100644 --- a/imports/codemirror/mode/gfm/gfm.js +++ b/imports/codemirror/mode/gfm/gfm.js @@ -69,7 +69,7 @@ CodeMirror.defineMode("gfm", function(config, parserConfig) { function handleText(stream, mdState) { var match; if (stream.match(/^\w+:\/\/\S+/)) { - return 'linkhref'; + return 'link'; } if (stream.match(/^[^\[*\\<>` _][^\[*\\<>` ]*[^\[*\\<>` _]/)) { return mdMode.getType(mdState); @@ -102,7 +102,43 @@ CodeMirror.defineMode("gfm", function(config, parserConfig) { }, token: function(stream, state) { - return state.token(stream, state); + /* Parse GFM double bracket links */ + if ((ch = stream.peek()) != undefined && ch == '[') { + stream.next(); // Advance the stream + + /* Only handle double bracket links */ + if ((ch = stream.peek()) == undefined || ch != '[') { + stream.backUp(1); + return state.token(stream, state); + } + + while ((ch = stream.next()) != undefined && ch != ']') {} + + if (ch == ']' && (ch = stream.next()) != undefined && ch == ']') + return 'link'; + + /* If we did not find the second ']' */ + stream.backUp(1); + } + + /* Match GFM latex formulas, as well as latex formulas within '$' */ + if (stream.match(/^\$[^\$]+\$/)) { + return "string"; + } + + if (stream.match(/^\\\((.*?)\\\)/)) { + return "string"; + } + + if (stream.match(/^\$\$[^\$]+\$\$/)) { + return "string"; + } + + if (stream.match(/^\\\[(.*?)\\\]/)) { + return "string"; + } + + return state.token(stream, state); } } -}); +}, "markdown"); -- cgit v1.2.3