From c2805e03c84b6e598556fd06d1ede7aaeea7ce9c Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 6 Mar 2012 16:17:54 -0800 Subject: Squashed commit FileIO-Build-Candidate into Master Fixing issues with HTML and CSS URLs. Adjusted RegEx logic. Also code a mirror update and undo/redo changes were merged into this request. Signed-off-by: Valerio Virgillito --- 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