diff options
Diffstat (limited to 'imports/codemirror/mode/tiddlywiki/tiddlywiki.js')
-rw-r--r-- | imports/codemirror/mode/tiddlywiki/tiddlywiki.js | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/imports/codemirror/mode/tiddlywiki/tiddlywiki.js b/imports/codemirror/mode/tiddlywiki/tiddlywiki.js index e07124c2..1d26967e 100644 --- a/imports/codemirror/mode/tiddlywiki/tiddlywiki.js +++ b/imports/codemirror/mode/tiddlywiki/tiddlywiki.js | |||
@@ -1,18 +1,18 @@ | |||
1 | /*** | 1 | /*** |
2 | |''Name''|tiddlywiki.js| | 2 | |''Name''|tiddlywiki.js| |
3 | |''Description''|Enables TiddlyWikiy syntax highlighting using CodeMirror2| | 3 | |''Description''|Enables TiddlyWikiy syntax highlighting using CodeMirror| |
4 | |''Author''|PMario| | 4 | |''Author''|PMario| |
5 | |''Version''|0.1.6| | 5 | |''Version''|0.1.7| |
6 | |''Status''|''beta''| | 6 | |''Status''|''stable''| |
7 | |''Source''|[[GitHub|https://github.com/pmario/CodeMirror2/blob/tw-syntax/mode/tiddlywiki]]| | 7 | |''Source''|[[GitHub|https://github.com/pmario/CodeMirror2/blob/tw-syntax/mode/tiddlywiki]]| |
8 | |''Documentation''|http://codemirror.tiddlyspace.com/| | 8 | |''Documentation''|http://codemirror.tiddlyspace.com/| |
9 | |''License''|[[MIT License|http://www.opensource.org/licenses/mit-license.php]]| | 9 | |''License''|[[MIT License|http://www.opensource.org/licenses/mit-license.php]]| |
10 | |''CoreVersion''|2.5.0| | 10 | |''CoreVersion''|2.5.0| |
11 | |''Requires''|codemirror.js| | 11 | |''Requires''|codemirror.js| |
12 | |''Keywords''|syntax highlighting color code mirror codemirror| | 12 | |''Keywords''|syntax highlighting color code mirror codemirror| |
13 | ! Info | 13 | ! Info |
14 | CoreVersion parameter is needed for TiddlyWiki only! | 14 | CoreVersion parameter is needed for TiddlyWiki only! |
15 | ***/ | 15 | ***/ |
16 | //{{{ | 16 | //{{{ |
17 | CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) { | 17 | CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) { |
18 | var indentUnit = config.indentUnit; | 18 | var indentUnit = config.indentUnit; |
@@ -47,20 +47,20 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) { | |||
47 | }(); | 47 | }(); |
48 | 48 | ||
49 | var isSpaceName = /[\w_\-]/i, | 49 | var isSpaceName = /[\w_\-]/i, |
50 | reHR = /^\-\-\-\-+$/, | 50 | reHR = /^\-\-\-\-+$/, // <hr> |
51 | reWikiCommentStart = /^\/\*\*\*$/, // /*** | 51 | reWikiCommentStart = /^\/\*\*\*$/, // /*** |
52 | reWikiCommentStop = /^\*\*\*\/$/, // ***/ | 52 | reWikiCommentStop = /^\*\*\*\/$/, // ***/ |
53 | reBlockQuote = /^<<<$/, | 53 | reBlockQuote = /^<<<$/, |
54 | 54 | ||
55 | reJsCodeStart = /^\/\/\{\{\{$/, // //{{{ | 55 | reJsCodeStart = /^\/\/\{\{\{$/, // //{{{ js block start |
56 | reJsCodeStop = /^\/\/\}\}\}$/, // //}}} | 56 | reJsCodeStop = /^\/\/\}\}\}$/, // //}}} js stop |
57 | reXmlCodeStart = /^<!--\{\{\{-->$/, | 57 | reXmlCodeStart = /^<!--\{\{\{-->$/, // xml block start |
58 | reXmlCodeStop = /^<!--\}\}\}-->$/, | 58 | reXmlCodeStop = /^<!--\}\}\}-->$/, // xml stop |
59 | 59 | ||
60 | reCodeBlockStart = /^\{\{\{$/, | 60 | reCodeBlockStart = /^\{\{\{$/, // {{{ TW text div block start |
61 | reCodeBlockStop = /^\}\}\}$/, | 61 | reCodeBlockStop = /^\}\}\}$/, // }}} TW text stop |
62 | 62 | ||
63 | reCodeStart = /\{\{\{/, | 63 | reCodeStart = /\{\{\{/, // {{{ code span start |
64 | reUntilCodeStop = /.*?\}\}\}/; | 64 | reUntilCodeStop = /.*?\}\}\}/; |
65 | 65 | ||
66 | function chain(stream, state, f) { | 66 | function chain(stream, state, f) { |
@@ -95,9 +95,9 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) { | |||
95 | 95 | ||
96 | state.block = false; // indicates the start of a code block. | 96 | state.block = false; // indicates the start of a code block. |
97 | 97 | ||
98 | ch = stream.peek(); // don't eat, to make match simpler | 98 | ch = stream.peek(); // don't eat, to make matching simpler |
99 | 99 | ||
100 | // check start of blocks | 100 | // check start of blocks |
101 | if (sol && /[<\/\*{}\-]/.test(ch)) { | 101 | if (sol && /[<\/\*{}\-]/.test(ch)) { |
102 | if (stream.match(reCodeBlockStart)) { | 102 | if (stream.match(reCodeBlockStart)) { |
103 | state.block = true; | 103 | state.block = true; |
@@ -116,7 +116,7 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) { | |||
116 | return ret('hr', 'hr'); | 116 | return ret('hr', 'hr'); |
117 | } | 117 | } |
118 | } // sol | 118 | } // sol |
119 | var ch = stream.next(); | 119 | ch = stream.next(); |
120 | 120 | ||
121 | if (sol && /[\/\*!#;:>|]/.test(ch)) { | 121 | if (sol && /[\/\*!#;:>|]/.test(ch)) { |
122 | if (ch == "!") { // tw header | 122 | if (ch == "!") { // tw header |
@@ -131,11 +131,11 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) { | |||
131 | stream.eatWhile('#'); | 131 | stream.eatWhile('#'); |
132 | return ret("list", "list"); | 132 | return ret("list", "list"); |
133 | } | 133 | } |
134 | if (ch == ";") { // tw list | 134 | if (ch == ";") { // definition list, term |
135 | stream.eatWhile(';'); | 135 | stream.eatWhile(';'); |
136 | return ret("list", "list"); | 136 | return ret("list", "list"); |
137 | } | 137 | } |
138 | if (ch == ":") { // tw list | 138 | if (ch == ":") { // definition list, description |
139 | stream.eatWhile(':'); | 139 | stream.eatWhile(':'); |
140 | return ret("list", "list"); | 140 | return ret("list", "list"); |
141 | } | 141 | } |
@@ -162,6 +162,9 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) { | |||
162 | if (ch == '"') { | 162 | if (ch == '"') { |
163 | return ret('string', 'string'); | 163 | return ret('string', 'string'); |
164 | } | 164 | } |
165 | if (ch == '~') { // _no_ CamelCase indicator should be bold | ||
166 | return ret('text', 'brace'); | ||
167 | } | ||
165 | if (/[\[\]]/.test(ch)) { // check for [[..]] | 168 | if (/[\[\]]/.test(ch)) { // check for [[..]] |
166 | if (stream.peek() == ch) { | 169 | if (stream.peek() == ch) { |
167 | stream.next(); | 170 | stream.next(); |
@@ -189,9 +192,15 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) { | |||
189 | return chain(stream, state, twTokenUnderline); | 192 | return chain(stream, state, twTokenUnderline); |
190 | } | 193 | } |
191 | } | 194 | } |
192 | if (ch == "-") { // tw strikethrough TODO looks ugly .. different handling see below; | 195 | // strikethrough and mdash handling |
196 | if (ch == "-") { | ||
193 | if (stream.eat("-")) { | 197 | if (stream.eat("-")) { |
194 | return chain(stream, state, twTokenStrike); | 198 | // if strikethrough looks ugly, change CSS. |
199 | if (stream.peek() != ' ') | ||
200 | return chain(stream, state, twTokenStrike); | ||
201 | // mdash | ||
202 | if (stream.peek() == ' ') | ||
203 | return ret('text', 'brace'); | ||
195 | } | 204 | } |
196 | } | 205 | } |
197 | if (ch == "'") { // tw bold | 206 | if (ch == "'") { // tw bold |
@@ -208,6 +217,7 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) { | |||
208 | return ret(ch); | 217 | return ret(ch); |
209 | } | 218 | } |
210 | 219 | ||
220 | // core macro handling | ||
211 | stream.eatWhile(/[\w\$_]/); | 221 | stream.eatWhile(/[\w\$_]/); |
212 | var word = stream.current(), | 222 | var word = stream.current(), |
213 | known = textwords.propertyIsEnumerable(word) && textwords[word]; | 223 | known = textwords.propertyIsEnumerable(word) && textwords[word]; |
@@ -301,8 +311,8 @@ CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) { | |||
301 | return ret("text", "underlined"); | 311 | return ret("text", "underlined"); |
302 | } | 312 | } |
303 | 313 | ||
304 | // tw strike through text looks ugly | 314 | // tw strike through text looks ugly |
305 | // TODO just strike through the first and last 2 chars if possible. | 315 | // change CSS if needed |
306 | function twTokenStrike(stream, state) { | 316 | function twTokenStrike(stream, state) { |
307 | var maybeEnd = false, | 317 | var maybeEnd = false, |
308 | ch, nr; | 318 | ch, nr; |