From 51ed781953bc44bba3c70938aa57b856394cbc88 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 27 Feb 2012 14:41:21 -0800 Subject: updating to codemirror 2.22 Signed-off-by: Ananya Sen --- imports/codemirror/mode/markdown/index.html | 0 imports/codemirror/mode/markdown/markdown.js | 82 ++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 24 deletions(-) mode change 100755 => 100644 imports/codemirror/mode/markdown/index.html mode change 100755 => 100644 imports/codemirror/mode/markdown/markdown.js (limited to 'imports/codemirror/mode/markdown') diff --git a/imports/codemirror/mode/markdown/index.html b/imports/codemirror/mode/markdown/index.html old mode 100755 new mode 100644 diff --git a/imports/codemirror/mode/markdown/markdown.js b/imports/codemirror/mode/markdown/markdown.js old mode 100755 new mode 100644 index 455bb43c..800ff0b4 --- a/imports/codemirror/mode/markdown/markdown.js +++ b/imports/codemirror/mode/markdown/markdown.js @@ -15,7 +15,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { var hrRE = /^[*-=_]/ , ulRE = /^[*-+]\s+/ - , olRE = /^[0-9]\.\s+/ + , olRE = /^[0-9]+\.\s+/ , headerRE = /^(?:\={3,}|-{3,})$/ , codeRE = /^(k:\t|\s{4,})/ , textRE = /^[^\[*_\\<>`]+/; @@ -34,35 +34,25 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { // Blocks function blockNormal(stream, state) { + var match; if (stream.match(codeRE)) { stream.skipToEnd(); return code; - } - - if (stream.eatSpace()) { + } else if (stream.eatSpace()) { return null; - } - - if (stream.peek() === '#' || stream.match(headerRE)) { - stream.skipToEnd(); - return header; - } - if (stream.eat('>')) { + } else if (stream.peek() === '#' || stream.match(headerRE)) { + state.header = true; + } else if (stream.eat('>')) { state.indentation++; - return quote; - } - if (stream.peek() === '[') { + state.quote = true; + } else if (stream.peek() === '[') { return switchInline(stream, state, footnoteLink); - } - if (hrRE.test(stream.peek())) { + } else if (hrRE.test(stream.peek())) { var re = new RegExp('(?:\s*['+stream.peek()+']){3,}$'); if (stream.match(re, true)) { return hr; } - } - - var match; - if (match = stream.match(ulRE, true) || stream.match(olRE, true)) { + } else if (match = stream.match(ulRE, true) || stream.match(olRE, true)) { state.indentation += match[0].length; return list; } @@ -82,8 +72,39 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { // Inline function getType(state) { - return state.strong ? (state.em ? emstrong : strong) - : (state.em ? em : null); + + // Set defaults + returnValue = ''; + + // Strong / Emphasis + if(state.strong){ + if(state.em){ + returnValue += (returnValue ? ' ' : '') + emstrong; + } else { + returnValue += (returnValue ? ' ' : '') + strong; + } + } else { + if(state.em){ + returnValue += (returnValue ? ' ' : '') + em; + } + } + + // Header + if(state.header){ + returnValue += (returnValue ? ' ' : '') + header; + } + + // Quotes + if(state.quote){ + returnValue += (returnValue ? ' ' : '') + quote; + } + + // Check valud and return + if(!returnValue){ + returnValue = null; + } + return returnValue; + } function handleText(stream, state) { @@ -192,7 +213,9 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { inline: inlineNormal, text: handleText, em: false, - strong: false + strong: false, + header: false, + quote: false }; }, @@ -207,12 +230,23 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { inline: s.inline, text: s.text, em: s.em, - strong: s.strong + strong: s.strong, + header: s.header, + quote: s.quote }; }, token: function(stream, state) { if (stream.sol()) { + // Reset EM state + state.em = false; + // Reset STRONG state + state.strong = false; + // Reset state.header + state.header = false; + // Reset state.quote + state.quote = false; + state.f = state.block; var previousIndentation = state.indentation , currentIndentation = 0; -- cgit v1.2.3