Project

General

Profile

Revision 229 trunk/scripts/codemirror/mode/tiddlywiki

View differences:

tiddlywiki.css
11 11
.cm-s-default span.cm-link-external {color: blue;}
12 12
.cm-s-default span.cm-brace {color: #170; font-weight: bold;}
13 13
.cm-s-default span.cm-macro {color: #9E3825;}
14
.cm-s-default span.cm-table {color: blue;}
14
.cm-s-default span.cm-table {color: blue; font-weight: bold;}
15 15
.cm-s-default span.cm-warning {color: red; font-weight: bold;}
16 16

  
17 17
.cm-s-default span.cm-underlined {text-decoration: underline;}
tiddlywiki.js
1 1
/***
2
 |''Name''|tiddlywiki.js|
3
 |''Description''|Enables TiddlyWikiy syntax highlighting using CodeMirror2|
4
 |''Author''|PMario|
5
 |''Version''|0.1.6|
6
 |''Status''|''beta''|
7
 |''Source''|[[GitHub|https://github.com/pmario/CodeMirror2/blob/tw-syntax/mode/tiddlywiki]]|
8
 |''Documentation''|http://codemirror.tiddlyspace.com/|
9
 |''License''|[[MIT License|http://www.opensource.org/licenses/mit-license.php]]|
10
 |''CoreVersion''|2.5.0|
11
 |''Requires''|codemirror.js|
12
 |''Keywords''|syntax highlighting color code mirror codemirror|
13
 ! Info
14
 CoreVersion parameter is needed for TiddlyWiki only!
15
 ***/
2
|''Name''|tiddlywiki.js|
3
|''Description''|Enables TiddlyWikiy syntax highlighting using CodeMirror|
4
|''Author''|PMario|
5
|''Version''|0.1.7|
6
|''Status''|''stable''|
7
|''Source''|[[GitHub|https://github.com/pmario/CodeMirror2/blob/tw-syntax/mode/tiddlywiki]]|
8
|''Documentation''|http://codemirror.tiddlyspace.com/|
9
|''License''|[[MIT License|http://www.opensource.org/licenses/mit-license.php]]|
10
|''CoreVersion''|2.5.0|
11
|''Requires''|codemirror.js|
12
|''Keywords''|syntax highlighting color code mirror codemirror|
13
! Info
14
CoreVersion parameter is needed for TiddlyWiki only!
15
***/
16 16
//{{{
17 17
CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) {
18 18
	var indentUnit = config.indentUnit;
......
47 47
	}();
48 48

  
49 49
	var isSpaceName = /[\w_\-]/i,
50
		reHR = /^\-\-\-\-+$/,
50
		reHR = /^\-\-\-\-+$/,					// <hr>
51 51
		reWikiCommentStart = /^\/\*\*\*$/,		// /***
52 52
		reWikiCommentStop = /^\*\*\*\/$/,		// ***/
53 53
		reBlockQuote = /^<<<$/,
54 54

  
55
		reJsCodeStart = /^\/\/\{\{\{$/,			// //{{{
56
		reJsCodeStop = /^\/\/\}\}\}$/,			// //}}}
57
		reXmlCodeStart = /^<!--\{\{\{-->$/,
58
		reXmlCodeStop = /^<!--\}\}\}-->$/,
55
		reJsCodeStart = /^\/\/\{\{\{$/,			// //{{{ js block start
56
		reJsCodeStop = /^\/\/\}\}\}$/,			// //}}} js stop
57
		reXmlCodeStart = /^<!--\{\{\{-->$/,		// xml block start
58
		reXmlCodeStop = /^<!--\}\}\}-->$/,		// xml stop
59 59

  
60
		reCodeBlockStart = /^\{\{\{$/,
61
		reCodeBlockStop = /^\}\}\}$/,
60
		reCodeBlockStart = /^\{\{\{$/,			// {{{ TW text div block start
61
		reCodeBlockStop = /^\}\}\}$/,			// }}} TW text stop
62 62

  
63
		reCodeStart = /\{\{\{/,
63
		reCodeStart = /\{\{\{/,					// {{{ code span start
64 64
		reUntilCodeStop = /.*?\}\}\}/;
65 65

  
66 66
	function chain(stream, state, f) {
......
95 95
			
96 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 101
		if (sol && /[<\/\*{}\-]/.test(ch)) {
102 102
			if (stream.match(reCodeBlockStart)) {
103 103
				state.block = true;
......
116 116
				return ret('hr', 'hr');
117 117
			}
118 118
		} // sol
119
		var ch = stream.next();
119
		ch = stream.next();
120 120

  
121 121
		if (sol && /[\/\*!#;:>|]/.test(ch)) {
122 122
			if (ch == "!") { // tw header
......
131 131
				stream.eatWhile('#');
132 132
				return ret("list", "list");
133 133
			}
134
			if (ch == ";") { // tw list
134
			if (ch == ";") { // definition list, term
135 135
				stream.eatWhile(';');
136 136
				return ret("list", "list");
137 137
			}
138
			if (ch == ":") { // tw list
138
			if (ch == ":") { // definition list, description
139 139
				stream.eatWhile(':');
140 140
				return ret("list", "list");
141 141
			}
......
162 162
		if (ch == '"') {
163 163
			return ret('string', 'string');
164 164
		}
165
		if (ch == '~') {	// _no_ CamelCase indicator should be bold
166
			return ret('text', 'brace');
167
		}
165 168
		if (/[\[\]]/.test(ch)) { // check for [[..]]
166 169
			if (stream.peek() == ch) {
167 170
				stream.next();
......
189 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 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 206
		if (ch == "'") { // tw bold
......
208 217
			return ret(ch);
209 218
		}
210 219

  
220
		// core macro handling
211 221
		stream.eatWhile(/[\w\$_]/);
212 222
		var word = stream.current(),
213 223
			known = textwords.propertyIsEnumerable(word) && textwords[word];
......
301 311
		return ret("text", "underlined");
302 312
	}
303 313

  
304
	// tw strike through text looks ugly 
305
	// TODO just strike through the first and last 2 chars if possible.
314
	// tw strike through text looks ugly
315
	// change CSS if needed
306 316
	function twTokenStrike(stream, state) {
307 317
		var maybeEnd = false,
308 318
			ch, nr;
index.html
16 16
!TiddlyWiki Formatting
17 17
* Rendered versions can be found at: http://www.tiddlywiki.com/#Reference
18 18

  
19
|!Option|!Syntax|!Output|
20
|bold font|{{{''bold''}}}|''bold''|
21
|italic type|{{{//italic//}}}|//italic//|
22
|underlined text|{{{__underlined__}}}|__underlined__|
23
|strikethrough text|{{{--strikethrough--}}}|--strikethrough--|
24
|superscript text|{{{^^super^^script}}}|^^super^^script|
25
|subscript text|{{{~~sub~~script}}}|~~sub~~script|
26
|highlighted text|{{{@@highlighted@@}}}|@@highlighted@@|
27
|preformatted text|<html><code>{{{preformatted}}}</code></html>|{{{preformatted}}}|
19
|!Option            | !Syntax            |
20
|bold font          | ''bold''           |
21
|italic type        | //italic//         |
22
|underlined text    | __underlined__     |
23
|strikethrough text | --strikethrough--  |
24
|superscript text   | super^^script^^    |
25
|subscript text     | sub~~script~~      |
26
|highlighted text   | @@highlighted@@    |
27
|preformatted text  | {{{preformatted}}} |
28 28

  
29 29
!Block Elements
30
!!Headings
31
{{{
32
!Heading 1
33
!!Heading 2
34
!!!Heading 3
35
!!!!Heading 4
36
!!!!!Heading 5
37
}}}
38 30
<<<
39

  
40 31
!Heading 1
41 32

  
42 33
!!Heading 2
......
49 40
<<<
50 41

  
51 42
!!Lists
52
{{{
53
* unordered list, level 1
54
** unordered list, level 2
55
*** unordered list, level 3
56

  
57
# ordered list, level 1
58
## ordered list, level 2
59
### unordered list, level 3
60

  
61
; definition list, term
62
: definition list, description
63
}}}
64 43
<<<
65 44
* unordered list, level 1
66 45
** unordered list, level 2
......
75 54
<<<
76 55

  
77 56
!!Blockquotes
78
{{{
79
> blockquote, level 1
80
>> blockquote, level 2
81
>>> blockquote, level 3
82

  
83 57
<<<
84
blockquote
85
<<<
86
}}}
87
<<<
88 58
> blockquote, level 1
89 59
>> blockquote, level 2
90 60
>>> blockquote, level 3
......
93 63
<<<
94 64

  
95 65
!!Preformatted Text
96
<html><pre>
97
{{{
98
preformatted (e.g. code)
99
}}}
100
</pre></html>
101 66
<<<
102 67
{{{
103 68
preformatted (e.g. code)
......
105 70
<<<
106 71

  
107 72
!!Code Sections
73
<<<
108 74
{{{
109 75
Text style code
110 76
}}}
......
116 82
<!--{{{-->
117 83
XML styled code. TiddlyWiki mixed mode should support highlighter switching in the future.
118 84
<!--}}}-->
85
<<<
119 86

  
120 87
!!Tables
121
{{{
88
<<<
122 89
|CssClass|k
123 90
|!heading column 1|!heading column 2|
124 91
|row 1, column 1|row 1, column 2|
......
128 95
|~| ... |
129 96
|CssProperty:value;...| ... |
130 97
|caption|c
131
}}}
98

  
132 99
''Annotation:''
133 100
* The {{{>}}} marker creates a "colspan", causing the current cell to merge with the one to the right.
134 101
* The {{{~}}} marker creates a "rowspan", causing the current cell to merge with the one above.
135 102
<<<
136
|CssClass|k
137
|!heading column 1|!heading column 2|
138
|row 1, column 1|row 1, column 2|
139
|row 2, column 1|row 2, column 2|
140
|>|COLSPAN|
141
|ROWSPAN| ... |
142
|~| ... |
143
|CssProperty:value;...| ... |
144
|caption|c
145
<<<
146 103
!!Images /% TODO %/
147 104
cf. [[TiddlyWiki.com|http://www.tiddlywiki.com/#EmbeddedImages]]
148 105

  

Also available in: Unified diff