From 3a754133dbc138390503341fd2e9beba3e43aa4b Mon Sep 17 00:00:00 2001
From: Jose Antonio Marquez
Date: Fri, 27 Jan 2012 12:05:17 -0800
Subject: Merged old FileIO

---
 imports/codemirror/mode/tiddlywiki/index.html     | 183 +++++++++++
 imports/codemirror/mode/tiddlywiki/tiddlywiki.css |  21 ++
 imports/codemirror/mode/tiddlywiki/tiddlywiki.js  | 374 ++++++++++++++++++++++
 3 files changed, 578 insertions(+)
 create mode 100755 imports/codemirror/mode/tiddlywiki/index.html
 create mode 100755 imports/codemirror/mode/tiddlywiki/tiddlywiki.css
 create mode 100755 imports/codemirror/mode/tiddlywiki/tiddlywiki.js

(limited to 'imports/codemirror/mode/tiddlywiki')

diff --git a/imports/codemirror/mode/tiddlywiki/index.html b/imports/codemirror/mode/tiddlywiki/index.html
new file mode 100755
index 00000000..36d0975c
--- /dev/null
+++ b/imports/codemirror/mode/tiddlywiki/index.html
@@ -0,0 +1,183 @@
+<!doctype html>
+<html>
+  <head>
+    <title>CodeMirror: TiddlyWiki mode</title>
+    <link rel="stylesheet" href="../../lib/codemirror.css">
+    <script src="../../lib/codemirror.js"></script>
+    <script src="tiddlywiki.js"></script>
+    <link rel="stylesheet" href="tiddlywiki.css">
+    <link rel="stylesheet" href="../../doc/docs.css">
+    <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
+  </head>
+  <body>
+    <h1>CodeMirror: TiddlyWiki mode</h1>
+
+<div><textarea id="code" name="code">
+!TiddlyWiki Formatting
+* Rendered versions can be found at: http://www.tiddlywiki.com/#Reference
+
+|!Option|!Syntax|!Output|
+|bold font|{{{''bold''}}}|''bold''|
+|italic type|{{{//italic//}}}|//italic//|
+|underlined text|{{{__underlined__}}}|__underlined__|
+|strikethrough text|{{{--strikethrough--}}}|--strikethrough--|
+|superscript text|{{{^^super^^script}}}|^^super^^script|
+|subscript text|{{{~~sub~~script}}}|~~sub~~script|
+|highlighted text|{{{@@highlighted@@}}}|@@highlighted@@|
+|preformatted text|<html><code>{{{preformatted}}}</code></html>|{{{preformatted}}}|
+
+!Block Elements
+!!Headings
+{{{
+!Heading 1
+!!Heading 2
+!!!Heading 3
+!!!!Heading 4
+!!!!!Heading 5
+}}}
+<<<
+
+!Heading 1
+
+!!Heading 2
+
+!!!Heading 3
+
+!!!!Heading 4
+
+!!!!!Heading 5
+<<<
+
+!!Lists
+{{{
+* unordered list, level 1
+** unordered list, level 2
+*** unordered list, level 3
+
+# ordered list, level 1
+## ordered list, level 2
+### unordered list, level 3
+
+; definition list, term
+: definition list, description
+}}}
+<<<
+* unordered list, level 1
+** unordered list, level 2
+*** unordered list, level 3
+
+# ordered list, level 1
+## ordered list, level 2
+### unordered list, level 3
+
+; definition list, term
+: definition list, description
+<<<
+
+!!Blockquotes
+{{{
+> blockquote, level 1
+>> blockquote, level 2
+>>> blockquote, level 3
+
+<<<
+blockquote
+<<<
+}}}
+<<<
+> blockquote, level 1
+>> blockquote, level 2
+>>> blockquote, level 3
+
+> blockquote
+<<<
+
+!!Preformatted Text
+<html><pre>
+{{{
+preformatted (e.g. code)
+}}}
+</pre></html>
+<<<
+{{{
+preformatted (e.g. code)
+}}}
+<<<
+
+!!Code Sections
+{{{
+Text style code
+}}}
+
+//{{{
+JS styled code. TiddlyWiki mixed mode should support highlighter switching in the future.
+//}}}
+
+<!--{{{-->
+XML styled code. TiddlyWiki mixed mode should support highlighter switching in the future.
+<!--}}}-->
+
+!!Tables
+{{{
+|CssClass|k
+|!heading column 1|!heading column 2|
+|row 1, column 1|row 1, column 2|
+|row 2, column 1|row 2, column 2|
+|>|COLSPAN|
+|ROWSPAN| ... |
+|~| ... |
+|CssProperty:value;...| ... |
+|caption|c
+}}}
+''Annotation:''
+* The {{{>}}} marker creates a "colspan", causing the current cell to merge with the one to the right.
+* The {{{~}}} marker creates a "rowspan", causing the current cell to merge with the one above.
+<<<
+|CssClass|k
+|!heading column 1|!heading column 2|
+|row 1, column 1|row 1, column 2|
+|row 2, column 1|row 2, column 2|
+|>|COLSPAN|
+|ROWSPAN| ... |
+|~| ... |
+|CssProperty:value;...| ... |
+|caption|c
+<<<
+!!Images /% TODO %/
+cf. [[TiddlyWiki.com|http://www.tiddlywiki.com/#EmbeddedImages]]
+
+!Hyperlinks
+* [[WikiWords|WikiWord]] are automatically transformed to hyperlinks to the respective tiddler
+** the automatic transformation can be suppressed by preceding the respective WikiWord with a tilde ({{{~}}}): {{{~WikiWord}}}
+* [[PrettyLinks]] are enclosed in square brackets and contain the desired tiddler name: {{{[[tiddler name]]}}}
+** optionally, a custom title or description can be added, separated by a pipe character ({{{|}}}): {{{[[title|target]]}}}<br>'''N.B.:''' In this case, the target can also be any website (i.e. URL).
+
+!Custom Styling
+* {{{@@CssProperty:value;CssProperty:value;...@@}}}<br>''N.B.:'' CSS color definitions should use lowercase letters to prevent the inadvertent creation of WikiWords.
+* <html><code>{{customCssClass{...}}}</code></html>
+* raw HTML can be inserted by enclosing the respective code in HTML tags: {{{<html> ... </html>}}}
+
+!Special Markers
+* {{{<br>}}} forces a manual line break
+* {{{----}}} creates a horizontal ruler
+* [[HTML entities|http://www.tiddlywiki.com/#HtmlEntities]]
+* [[HTML entities local|HtmlEntities]]
+* {{{<<macroName>>}}} calls the respective [[macro|Macros]]
+* To hide text within a tiddler so that it is not displayed, it can be wrapped in {{{/%}}} and {{{%/}}}.<br/>This can be a useful trick for hiding drafts or annotating complex markup.
+* To prevent wiki markup from taking effect for a particular section, that section can be enclosed in three double quotes: e.g. {{{"""WikiWord"""}}}.
+</textarea></div>
+
+    <script>
+      var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
+        mode: 'tiddlywiki',      
+        lineNumbers: true,
+        enterMode: 'keep',
+        matchBrackets: true
+      });
+    </script>
+
+    <p>TiddlyWiki mode supports a single configuration.</p>
+
+    <p><strong>MIME types defined:</strong> <code>text/x-tiddlywiki</code>.</p>
+  </body>
+</html>
diff --git a/imports/codemirror/mode/tiddlywiki/tiddlywiki.css b/imports/codemirror/mode/tiddlywiki/tiddlywiki.css
new file mode 100755
index 00000000..767f3de2
--- /dev/null
+++ b/imports/codemirror/mode/tiddlywiki/tiddlywiki.css
@@ -0,0 +1,21 @@
+.cm-s-default span.cm-header {color: blue; font-weight:bold;}
+.cm-s-default span.cm-code {color: #a50;}
+.cm-s-default span.cm-code-inline {color: #660;}
+
+.cm-s-default span.cm-quote {color: #555;}
+.cm-s-default span.cm-list {color: #c60;}
+.cm-s-default span.cm-hr {color: #999;}
+.cm-s-default span.cm-em {font-style: italic;}
+.cm-s-default span.cm-strong {font-weight: bold;}
+
+.cm-s-default span.cm-link-external {color: blue;}
+.cm-s-default span.cm-brace {color: #170; font-weight: bold;}
+.cm-s-default span.cm-macro {color: #9E3825;}
+.cm-s-default span.cm-table {color: blue;}
+.cm-s-default span.cm-warning {color: red; font-weight: bold;}
+
+.cm-s-default span.cm-underlined {text-decoration: underline;}
+.cm-s-default span.cm-line-through {text-decoration: line-through;}
+
+.cm-s-default span.cm-comment {color: #666;}
+
diff --git a/imports/codemirror/mode/tiddlywiki/tiddlywiki.js b/imports/codemirror/mode/tiddlywiki/tiddlywiki.js
new file mode 100755
index 00000000..e07124c2
--- /dev/null
+++ b/imports/codemirror/mode/tiddlywiki/tiddlywiki.js
@@ -0,0 +1,374 @@
+/***
+ |''Name''|tiddlywiki.js|
+ |''Description''|Enables TiddlyWikiy syntax highlighting using CodeMirror2|
+ |''Author''|PMario|
+ |''Version''|0.1.6|
+ |''Status''|''beta''|
+ |''Source''|[[GitHub|https://github.com/pmario/CodeMirror2/blob/tw-syntax/mode/tiddlywiki]]|
+ |''Documentation''|http://codemirror.tiddlyspace.com/|
+ |''License''|[[MIT License|http://www.opensource.org/licenses/mit-license.php]]|
+ |''CoreVersion''|2.5.0|
+ |''Requires''|codemirror.js|
+ |''Keywords''|syntax highlighting color code mirror codemirror|
+ ! Info
+ CoreVersion parameter is needed for TiddlyWiki only!
+ ***/
+//{{{
+CodeMirror.defineMode("tiddlywiki", function (config, parserConfig) {
+	var indentUnit = config.indentUnit;
+
+	// Tokenizer
+	var textwords = function () {
+		function kw(type) {
+			return {
+				type: type,
+				style: "text"
+			};
+		}
+		return {};
+	}();
+
+	var keywords = function () {
+		function kw(type) {
+			return { type: type, style: "macro"};
+		}
+		return {
+			"allTags": kw('allTags'), "closeAll": kw('closeAll'), "list": kw('list'),
+			"newJournal": kw('newJournal'), "newTiddler": kw('newTiddler'),
+			"permaview": kw('permaview'), "saveChanges": kw('saveChanges'),
+			"search": kw('search'), "slider": kw('slider'),	"tabs": kw('tabs'),
+			"tag": kw('tag'), "tagging": kw('tagging'),	"tags": kw('tags'),
+			"tiddler": kw('tiddler'), "timeline": kw('timeline'),
+			"today": kw('today'), "version": kw('version'),	"option": kw('option'),
+
+			"with": kw('with'),
+			"filter": kw('filter')
+		};
+	}();
+
+	var isSpaceName = /[\w_\-]/i,
+		reHR = /^\-\-\-\-+$/,
+		reWikiCommentStart = /^\/\*\*\*$/,		// /***
+		reWikiCommentStop = /^\*\*\*\/$/,		// ***/
+		reBlockQuote = /^<<<$/,
+
+		reJsCodeStart = /^\/\/\{\{\{$/,			// //{{{
+		reJsCodeStop = /^\/\/\}\}\}$/,			// //}}}
+		reXmlCodeStart = /^<!--\{\{\{-->$/,
+		reXmlCodeStop = /^<!--\}\}\}-->$/,
+
+		reCodeBlockStart = /^\{\{\{$/,
+		reCodeBlockStop = /^\}\}\}$/,
+
+		reCodeStart = /\{\{\{/,
+		reUntilCodeStop = /.*?\}\}\}/;
+
+	function chain(stream, state, f) {
+		state.tokenize = f;
+		return f(stream, state);
+	}
+
+	// used for strings
+	function nextUntilUnescaped(stream, end) {
+		var escaped = false,
+			next;
+		while ((next = stream.next()) != null) {
+			if (next == end && !escaped) return false;
+			escaped = !escaped && next == "\\";
+		}
+		return escaped;
+	}
+
+	// Used as scratch variables to communicate multiple values without
+	// consing up tons of objects.
+	var type, content;
+
+	function ret(tp, style, cont) {
+		type = tp;
+		content = cont;
+		return style;
+	}
+
+	function jsTokenBase(stream, state) {
+		var sol = stream.sol(), 
+			ch, tch;
+			
+		state.block = false;	// indicates the start of a code block.
+
+		ch = stream.peek(); // don't eat, to make match simpler
+		
+		// check start of  blocks    
+		if (sol && /[<\/\*{}\-]/.test(ch)) {
+			if (stream.match(reCodeBlockStart)) {
+				state.block = true;
+				return chain(stream, state, twTokenCode);
+			}
+			if (stream.match(reBlockQuote)) {
+				return ret('quote', 'quote');
+			}
+			if (stream.match(reWikiCommentStart) || stream.match(reWikiCommentStop)) {
+				return ret('code', 'code');
+			}
+			if (stream.match(reJsCodeStart) || stream.match(reJsCodeStop) || stream.match(reXmlCodeStart) || stream.match(reXmlCodeStop)) {
+				return ret('code', 'code');
+			}
+			if (stream.match(reHR)) {
+				return ret('hr', 'hr');
+			}
+		} // sol
+		var ch = stream.next();
+
+		if (sol && /[\/\*!#;:>|]/.test(ch)) {
+			if (ch == "!") { // tw header
+				stream.skipToEnd();
+				return ret("header", "header");
+			}
+			if (ch == "*") { // tw list
+				stream.eatWhile('*');
+				return ret("list", "list");
+			}
+			if (ch == "#") { // tw numbered list
+				stream.eatWhile('#');
+				return ret("list", "list");
+			}
+			if (ch == ";") { // tw list
+				stream.eatWhile(';');
+				return ret("list", "list");
+			}
+			if (ch == ":") { // tw list
+				stream.eatWhile(':');
+				return ret("list", "list");
+			}
+			if (ch == ">") { // single line quote
+				stream.eatWhile(">");
+				return ret("quote", "quote");
+			}
+			if (ch == '|') {
+				return ret('table', 'table');
+			}
+		}
+
+		if (ch == '{' && stream.match(/\{\{/)) {
+			return chain(stream, state, twTokenCode);
+		}
+
+		// rudimentary html:// file:// link matching. TW knows much more ...
+		if (/[hf]/i.test(ch)) {
+			if (/[ti]/i.test(stream.peek()) && stream.match(/\b(ttps?|tp|ile):\/\/[\-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i)) {
+				return ret("link-external", "link-external");
+			}
+		}
+		// just a little string indicator, don't want to have the whole string covered
+		if (ch == '"') {
+			return ret('string', 'string');
+		}
+		if (/[\[\]]/.test(ch)) { // check for [[..]]
+			if (stream.peek() == ch) {
+				stream.next();
+				return ret('brace', 'brace');
+			}
+		}
+		if (ch == "@") {	// check for space link. TODO fix @@...@@ highlighting
+			stream.eatWhile(isSpaceName);
+			return ret("link-external", "link-external");
+		}
+		if (/\d/.test(ch)) {	// numbers
+			stream.eatWhile(/\d/);
+			return ret("number", "number");
+		}
+		if (ch == "/") { // tw invisible comment
+			if (stream.eat("%")) {
+				return chain(stream, state, twTokenComment);
+			}
+			else if (stream.eat("/")) { // 
+				return chain(stream, state, twTokenEm);
+			}
+		}
+		if (ch == "_") { // tw underline
+			if (stream.eat("_")) {
+				return chain(stream, state, twTokenUnderline);
+			}
+		}
+		if (ch == "-") { // tw strikethrough TODO looks ugly .. different handling see below;
+			if (stream.eat("-")) {
+				return chain(stream, state, twTokenStrike);
+			}
+		}
+		if (ch == "'") { // tw bold
+			if (stream.eat("'")) {
+				return chain(stream, state, twTokenStrong);
+			}
+		}
+		if (ch == "<") { // tw macro
+			if (stream.eat("<")) {
+				return chain(stream, state, twTokenMacro);
+			}
+		}
+		else {
+			return ret(ch);
+		}
+
+		stream.eatWhile(/[\w\$_]/);
+		var word = stream.current(),
+			known = textwords.propertyIsEnumerable(word) && textwords[word];
+
+		return known ? ret(known.type, known.style, word) : ret("text", null, word);
+
+	} // jsTokenBase()
+
+	function twTokenString(quote) {
+		return function (stream, state) {
+			if (!nextUntilUnescaped(stream, quote)) state.tokenize = jsTokenBase;
+			return ret("string", "string");
+		};
+	}
+
+	// tw invisible comment
+	function twTokenComment(stream, state) {
+		var maybeEnd = false,
+			ch;
+		while (ch = stream.next()) {
+			if (ch == "/" && maybeEnd) {
+				state.tokenize = jsTokenBase;
+				break;
+			}
+			maybeEnd = (ch == "%");
+		}
+		return ret("comment", "comment");
+	}
+
+	// tw strong / bold
+	function twTokenStrong(stream, state) {
+		var maybeEnd = false,
+			ch;
+		while (ch = stream.next()) {
+			if (ch == "'" && maybeEnd) {
+				state.tokenize = jsTokenBase;
+				break;
+			}
+			maybeEnd = (ch == "'");
+		}
+		return ret("text", "strong");
+	}
+
+	// tw code
+	function twTokenCode(stream, state) {
+		var ch, sb = state.block;
+		
+		if (sb && stream.current()) {
+			return ret("code", "code");
+		}
+
+		if (!sb && stream.match(reUntilCodeStop)) {
+			state.tokenize = jsTokenBase;
+			return ret("code", "code-inline");
+		}
+
+		if (sb && stream.sol() && stream.match(reCodeBlockStop)) {
+			state.tokenize = jsTokenBase;
+			return ret("code", "code");
+		}
+
+		ch = stream.next();
+		return (sb) ? ret("code", "code") : ret("code", "code-inline");
+	}
+
+	// tw em / italic
+	function twTokenEm(stream, state) {
+		var maybeEnd = false,
+			ch;
+		while (ch = stream.next()) {
+			if (ch == "/" && maybeEnd) {
+				state.tokenize = jsTokenBase;
+				break;
+			}
+			maybeEnd = (ch == "/");
+		}
+		return ret("text", "em");
+	}
+
+	// tw underlined text
+	function twTokenUnderline(stream, state) {
+		var maybeEnd = false,
+			ch;
+		while (ch = stream.next()) {
+			if (ch == "_" && maybeEnd) {
+				state.tokenize = jsTokenBase;
+				break;
+			}
+			maybeEnd = (ch == "_");
+		}
+		return ret("text", "underlined");
+	}
+
+	// tw strike through text looks ugly 
+	// TODO just strike through the first and last 2 chars if possible.
+	function twTokenStrike(stream, state) {
+		var maybeEnd = false,
+			ch, nr;
+			
+		while (ch = stream.next()) {
+			if (ch == "-" && maybeEnd) {
+				state.tokenize = jsTokenBase;
+				break;
+			}
+			maybeEnd = (ch == "-");
+		}
+		return ret("text", "line-through");
+	}
+
+	// macro
+	function twTokenMacro(stream, state) {
+		var ch, tmp, word, known;
+
+		if (stream.current() == '<<') {
+			return ret('brace', 'macro');
+		}
+
+		ch = stream.next();
+		if (!ch) {
+			state.tokenize = jsTokenBase;
+			return ret(ch);
+		}
+		if (ch == ">") {
+			if (stream.peek() == '>') {
+				stream.next();
+				state.tokenize = jsTokenBase;
+				return ret("brace", "macro");
+			}
+		}
+
+		stream.eatWhile(/[\w\$_]/);
+		word = stream.current();
+		known = keywords.propertyIsEnumerable(word) && keywords[word];
+
+		if (known) {
+			return ret(known.type, known.style, word);
+		}
+		else {
+			return ret("macro", null, word);
+		}
+	}
+
+	// Interface
+	return {
+		startState: function (basecolumn) {
+			return {
+				tokenize: jsTokenBase,
+				indented: 0,
+				level: 0
+			};
+		},
+
+		token: function (stream, state) {
+			if (stream.eatSpace()) return null;
+			var style = state.tokenize(stream, state);
+			return style;
+		},
+
+		electricChars: ""
+	};
+});
+
+CodeMirror.defineMIME("text/x-tiddlywiki", "tiddlywiki");
+//}}}
-- 
cgit v1.2.3