diff options
author | hwc487 | 2012-05-11 13:52:55 -0700 |
---|---|---|
committer | hwc487 | 2012-05-11 13:52:55 -0700 |
commit | 137bfc9d4c41cc918d969565bec28a834fe10472 (patch) | |
tree | e9fa109fc65218f45e386df48b713ff5858f3d62 /imports/codemirror/mode/markdown | |
parent | d21aaca3d7093b6af968b7f9f764ab54e004f02b (diff) | |
parent | 27f4cacb39de1c2e3910748dadc9fc16d0655480 (diff) | |
download | ninja-137bfc9d4c41cc918d969565bec28a834fe10472.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Textures
Conflicts:
js/lib/geom/geom-obj.js
js/lib/geom/rectangle.js
js/tools/TagTool.js
Diffstat (limited to 'imports/codemirror/mode/markdown')
-rw-r--r-- | imports/codemirror/mode/markdown/index.html | 1 | ||||
-rw-r--r-- | imports/codemirror/mode/markdown/markdown.js | 89 |
2 files changed, 29 insertions, 61 deletions
diff --git a/imports/codemirror/mode/markdown/index.html b/imports/codemirror/mode/markdown/index.html index 3a60c03f..cae8df44 100644 --- a/imports/codemirror/mode/markdown/index.html +++ b/imports/codemirror/mode/markdown/index.html | |||
@@ -6,7 +6,6 @@ | |||
6 | <script src="../../lib/codemirror.js"></script> | 6 | <script src="../../lib/codemirror.js"></script> |
7 | <script src="../xml/xml.js"></script> | 7 | <script src="../xml/xml.js"></script> |
8 | <script src="markdown.js"></script> | 8 | <script src="markdown.js"></script> |
9 | <link rel="stylesheet" href="markdown.css"> | ||
10 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | 9 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> |
11 | <link rel="stylesheet" href="../../doc/docs.css"> | 10 | <link rel="stylesheet" href="../../doc/docs.css"> |
12 | </head> | 11 | </head> |
diff --git a/imports/codemirror/mode/markdown/markdown.js b/imports/codemirror/mode/markdown/markdown.js index 800ff0b4..af95753e 100644 --- a/imports/codemirror/mode/markdown/markdown.js +++ b/imports/codemirror/mode/markdown/markdown.js | |||
@@ -13,11 +13,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { | |||
13 | , strong = 'strong' | 13 | , strong = 'strong' |
14 | , emstrong = 'emstrong'; | 14 | , emstrong = 'emstrong'; |
15 | 15 | ||
16 | var hrRE = /^[*-=_]/ | 16 | var hrRE = /^([*\-=_])(?:\s*\1){2,}\s*$/ |
17 | , ulRE = /^[*-+]\s+/ | 17 | , ulRE = /^[*\-+]\s+/ |
18 | , olRE = /^[0-9]+\.\s+/ | 18 | , olRE = /^[0-9]+\.\s+/ |
19 | , headerRE = /^(?:\={3,}|-{3,})$/ | 19 | , headerRE = /^(?:\={3,}|-{3,})$/ |
20 | , codeRE = /^(k:\t|\s{4,})/ | ||
21 | , textRE = /^[^\[*_\\<>`]+/; | 20 | , textRE = /^[^\[*_\\<>`]+/; |
22 | 21 | ||
23 | function switchInline(stream, state, f) { | 22 | function switchInline(stream, state, f) { |
@@ -33,9 +32,18 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { | |||
33 | 32 | ||
34 | // Blocks | 33 | // Blocks |
35 | 34 | ||
35 | function blankLine(state) { | ||
36 | // Reset EM state | ||
37 | state.em = false; | ||
38 | // Reset STRONG state | ||
39 | state.strong = false; | ||
40 | return null; | ||
41 | } | ||
42 | |||
36 | function blockNormal(stream, state) { | 43 | function blockNormal(stream, state) { |
37 | var match; | 44 | var match; |
38 | if (stream.match(codeRE)) { | 45 | if (state.indentationDiff >= 4) { |
46 | state.indentation -= state.indentationDiff; | ||
39 | stream.skipToEnd(); | 47 | stream.skipToEnd(); |
40 | return code; | 48 | return code; |
41 | } else if (stream.eatSpace()) { | 49 | } else if (stream.eatSpace()) { |
@@ -47,11 +55,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { | |||
47 | state.quote = true; | 55 | state.quote = true; |
48 | } else if (stream.peek() === '[') { | 56 | } else if (stream.peek() === '[') { |
49 | return switchInline(stream, state, footnoteLink); | 57 | return switchInline(stream, state, footnoteLink); |
50 | } else if (hrRE.test(stream.peek())) { | 58 | } else if (stream.match(hrRE, true)) { |
51 | var re = new RegExp('(?:\s*['+stream.peek()+']){3,}$'); | 59 | return hr; |
52 | if (stream.match(re, true)) { | ||
53 | return hr; | ||
54 | } | ||
55 | } else if (match = stream.match(ulRE, true) || stream.match(olRE, true)) { | 60 | } else if (match = stream.match(ulRE, true) || stream.match(olRE, true)) { |
56 | state.indentation += match[0].length; | 61 | state.indentation += match[0].length; |
57 | return list; | 62 | return list; |
@@ -72,39 +77,15 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { | |||
72 | 77 | ||
73 | // Inline | 78 | // Inline |
74 | function getType(state) { | 79 | function getType(state) { |
80 | var styles = []; | ||
75 | 81 | ||
76 | // Set defaults | 82 | if (state.strong) { styles.push(state.em ? emstrong : strong); } |
77 | returnValue = ''; | 83 | else if (state.em) { styles.push(em); } |
78 | |||
79 | // Strong / Emphasis | ||
80 | if(state.strong){ | ||
81 | if(state.em){ | ||
82 | returnValue += (returnValue ? ' ' : '') + emstrong; | ||
83 | } else { | ||
84 | returnValue += (returnValue ? ' ' : '') + strong; | ||
85 | } | ||
86 | } else { | ||
87 | if(state.em){ | ||
88 | returnValue += (returnValue ? ' ' : '') + em; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | // Header | ||
93 | if(state.header){ | ||
94 | returnValue += (returnValue ? ' ' : '') + header; | ||
95 | } | ||
96 | |||
97 | // Quotes | ||
98 | if(state.quote){ | ||
99 | returnValue += (returnValue ? ' ' : '') + quote; | ||
100 | } | ||
101 | |||
102 | // Check valud and return | ||
103 | if(!returnValue){ | ||
104 | returnValue = null; | ||
105 | } | ||
106 | return returnValue; | ||
107 | 84 | ||
85 | if (state.header) { styles.push(header); } | ||
86 | if (state.quote) { styles.push(quote); } | ||
87 | |||
88 | return styles.length ? styles.join(' ') : null; | ||
108 | } | 89 | } |
109 | 90 | ||
110 | function handleText(stream, state) { | 91 | function handleText(stream, state) { |
@@ -238,36 +219,24 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { | |||
238 | 219 | ||
239 | token: function(stream, state) { | 220 | token: function(stream, state) { |
240 | if (stream.sol()) { | 221 | if (stream.sol()) { |
241 | // Reset EM state | 222 | if (stream.match(/^\s*$/, true)) { return blankLine(state); } |
242 | state.em = false; | 223 | |
243 | // Reset STRONG state | ||
244 | state.strong = false; | ||
245 | // Reset state.header | 224 | // Reset state.header |
246 | state.header = false; | 225 | state.header = false; |
247 | // Reset state.quote | 226 | // Reset state.quote |
248 | state.quote = false; | 227 | state.quote = false; |
249 | 228 | ||
250 | state.f = state.block; | 229 | state.f = state.block; |
251 | var previousIndentation = state.indentation | 230 | var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, ' ').length; |
252 | , currentIndentation = 0; | 231 | state.indentationDiff = indentation - state.indentation; |
253 | while (previousIndentation > 0) { | 232 | state.indentation = indentation; |
254 | if (stream.eat(' ')) { | 233 | if (indentation > 0) { return null; } |
255 | previousIndentation--; | ||
256 | currentIndentation++; | ||
257 | } else if (previousIndentation >= 4 && stream.eat('\t')) { | ||
258 | previousIndentation -= 4; | ||
259 | currentIndentation += 4; | ||
260 | } else { | ||
261 | break; | ||
262 | } | ||
263 | } | ||
264 | state.indentation = currentIndentation; | ||
265 | |||
266 | if (currentIndentation > 0) return null; | ||
267 | } | 234 | } |
268 | return state.f(stream, state); | 235 | return state.f(stream, state); |
269 | }, | 236 | }, |
270 | 237 | ||
238 | blankLine: blankLine, | ||
239 | |||
271 | getType: getType | 240 | getType: getType |
272 | }; | 241 | }; |
273 | 242 | ||