From 6d11f1bc85b49ce292dee518620a1d05b3c647b9 Mon Sep 17 00:00:00 2001 From: Eston Bond Date: Wed, 10 Nov 2010 17:00:17 -0800 Subject: [PATCH] Adding basic rdoc editor definition --- .../javascript/gollum-editor/langs/rdoc.js | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 lib/gollum/frontend/public/javascript/gollum-editor/langs/rdoc.js diff --git a/lib/gollum/frontend/public/javascript/gollum-editor/langs/rdoc.js b/lib/gollum/frontend/public/javascript/gollum-editor/langs/rdoc.js new file mode 100644 index 00000000..592af965 --- /dev/null +++ b/lib/gollum/frontend/public/javascript/gollum-editor/langs/rdoc.js @@ -0,0 +1,75 @@ +/** + * Markdown Language Definition + * + * A language definition for string manipulation operations, in this case + * for the Markdown, uh, markup language. Uses regexes for various functions + * by default. If regexes won't do and you need to do some serious + * manipulation, you can declare a function in the object instead. + * + * Code example: + * 'functionbar-id' : { + * exec: function(text, selectedText) { + * functionStuffHere(); + * }, + * search: /somesearchregex/gi, + * replace: 'replace text for RegExp.replace', + * append: "just add this where the cursor is" + * } + * +**/ +(function() { + +var RDoc = { + + 'function-bold' : { + search: /([^\n]+)([\n]*)/gi, + replace: "((*$1*))$2" + } + 'function-code' : { + search: /([^\n]+)([\n]*)/gi, + replace: "(({$1}))$2" + }, + + 'function-ul' : { + search: /(.+)([\n]?)/gi, + replace: "* $1$2" + }, + + /* This looks silly but is completely valid Markdown */ + 'function-ol' : { + exec: function( txt, selText, $field ) { + var count = 1; + // split into lines + var repText = ''; + var lines = selText.split("\n"); + var hasContent = /[\w]+/; + for ( var i = 0; i < lines.length; i++ ) { + if ( hasContent.test(lines[i]) ) { + repText += '(' + (i + 1).toString() + ') ' + + lines[i]; + } + } + $.GollumEditor.replaceSelection( repText ); + } + }, + + 'function-h1' : { + search: /(.+)([\n]?)/gi, + replace: "= $1$2" + }, + + 'function-h2' : { + search: /(.+)([\n]?)/gi, + replace: "== $1$2" + }, + + 'function-h3' : { + search: /(.+)([\n]?)/gi, + replace: "=== $1$2" + } + +}; + +jQuery.GollumEditor.defineLanguage('rdoc', RDoc); + +})();