From c9cc0d3d378c7f5bfb9628b7d1201a0573082151 Mon Sep 17 00:00:00 2001 From: Eston Bond Date: Wed, 27 Oct 2010 16:47:30 -0700 Subject: [PATCH] Added markdown definition, workin' on the editor --- scratch/js/gollum-editor/langs/markdown.js | 51 +++++++++++++++++++++- scratch/js/gollum.editor.js | 21 ++++++++- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/scratch/js/gollum-editor/langs/markdown.js b/scratch/js/gollum-editor/langs/markdown.js index d77af0c7..1e113962 100644 --- a/scratch/js/gollum-editor/langs/markdown.js +++ b/scratch/js/gollum-editor/langs/markdown.js @@ -1 +1,50 @@ -// meh \ No newline at end of file +/** + * 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" + * } + * +**/ + +var MarkDown = { + + 'function-bold' : { + search: /([^\n]+)([\n]*)/gi, + replace: "**$1**$2" + }, + + 'function-italic' : { + search: /([^\n]+)([\n]*)/gi, + replace: "_$1_$2" + }, + + 'function-code' : { + search: /([^\n]+)([\n]*)/gi, + replace: "`$1`$2" + }, + + 'function-hr' : { + append: "\n***\n" + }, + + 'function-ul' : { + search: /(.+)([\n]?)/gi, + replace: "* $1$2" + } + +}; + +// this is necessary for GollumEditor to pick this up +jQuery.GollumEditor.defineLanguage('markdown', MarkDown); \ No newline at end of file diff --git a/scratch/js/gollum.editor.js b/scratch/js/gollum.editor.js index 34173319..1844199f 100644 --- a/scratch/js/gollum.editor.js +++ b/scratch/js/gollum.editor.js @@ -50,6 +50,14 @@ } }; + $.GollumEditor.defineLanguage = function( language_name, languageObject ) { + if ( typeof languageObject == 'object' ) + LanguageDefinition.define( language_name, languageObject ); + else + debug('GollumEditor.defineLanguage: definition for ' + language_name + + ' is not an object'); + }; + /** @@ -75,7 +83,15 @@ **/ var LanguageDefinition = { - _LOADED_LANGS: [], + _LOADED_LANGS: [], + _LANG: {}, + + /** + * Defines a language + **/ + define: function( name, definitionObject ) { + LanguageDefinition._LANG[name] = definitionObject; + }, /** * loadFor @@ -162,7 +178,8 @@ }, evtFunctionButtonClick: function(e) { - alert('eee'); + e.preventDefault(); + alert($(this).attr('id')); } };