DRY language definitions (#1411)

* Dryer language defs
* Fix markup modes after move to Primer
* Fix rest function buttons
This commit is contained in:
Dawa Ometto
2019-09-03 11:58:17 +02:00
committed by GitHub
parent 77aaeef5ff
commit 3740a7f6ff
12 changed files with 591 additions and 1257 deletions
@@ -6,6 +6,7 @@
//= require gollum.dialog //= require gollum.dialog
//= require gollum.placeholder //= require gollum.placeholder
//= require editor/gollum.editor //= require editor/gollum.editor
//= require editor/langs/default
//= require_tree ./editor/langs //= require_tree ./editor/langs
//= require ace/ace //= require ace/ace
//= require ace/mode-markdown //= require ace/mode-markdown
@@ -162,7 +162,6 @@
$(this).parent().toggleClass('collapsed'); $(this).parent().toggleClass('collapsed');
buttons = $(this).parent().children("button"); buttons = $(this).parent().children("button");
console.log(buttons);
hidden_button = buttons.filter(':hidden')[0]; hidden_button = buttons.filter(':hidden')[0];
shown_button = buttons.not(':hidden')[0]; shown_button = buttons.not(':hidden')[0];
hidden_button.hidden = false; hidden_button.hidden = false;
@@ -623,7 +622,6 @@
isActive: false, isActive: false,
/** /**
* FunctionBar.activate * FunctionBar.activate
* Activates the function bar, attaching all click events * Activates the function bar, attaching all click events
@@ -638,9 +636,11 @@
if ( LanguageDefinition.getDefinitionFor( $(this).attr('id') ) ) { if ( LanguageDefinition.getDefinitionFor( $(this).attr('id') ) ) {
$(this).click( FunctionBar.evtFunctionButtonClick ); $(this).click( FunctionBar.evtFunctionButtonClick );
$(this).removeClass('disabled'); $(this).removeClass('disabled');
$(this).attr('disabled', false);
} }
else if ( !['function-help', 'function-text-direction'].includes( $(this).attr('id') ) ) { else if ( !['function-help', 'function-text-direction'].includes( $(this).attr('id') ) ) {
$(this).addClass('disabled'); $(this).addClass('disabled');
$(this).attr('disabled', true);
} }
}); });
@@ -651,7 +651,7 @@
deactivate: function() { deactivate: function() {
$('#gollum-editor-function-bar a.function-button').unbind('click'); $('#gollum-editor-function-bar button.function-button').unbind('click');
$('#gollum-editor-function-bar').removeClass( 'active' ); $('#gollum-editor-function-bar').removeClass( 'active' );
FunctionBar.isActive = false; FunctionBar.isActive = false;
}, },
@@ -713,7 +713,7 @@
// the text area, but on the editor. But since a lot functions // the text area, but on the editor. But since a lot functions
// does not use the third args, this works in these cases. But // does not use the third args, this works in these cases. But
// we shall fix it. // we shall fix it.
definitionObject.exec( txt, selText, $('#gollum-editor-body') ); definitionObject.exec( txt, selText, $('#gollum-editor-body'), selRange );
return; return;
} }
@@ -786,7 +786,7 @@
if ( EditorHas.functionBar() ) { if ( EditorHas.functionBar() ) {
debug('Refreshing function bar'); debug('Refreshing function bar');
if ( LanguageDefinition.isValid() ) { if ( LanguageDefinition.isValid() ) {
$('#gollum-editor-function-bar a.function-button').unbind('click'); $('#gollum-editor-function-bar button.function-button').unbind('click');
FunctionBar.activate(); FunctionBar.activate();
if ( Help ) { if ( Help ) {
Help.setActiveHelp( LanguageDefinition.getActiveLanguage() ); Help.setActiveHelp( LanguageDefinition.getActiveLanguage() );
@@ -1,174 +1,60 @@
/** /**
* AsciiDoc Language Definition * AsciiDoc Language Definition
* See default.js for documentation
* *
*/ */
(function($) { (function($) {
var AsciiDoc = { // No need to set all the replacements, only those different from the default language (Markdown).
var AsciiDoc = {
'function-bold' : { 'function-bold': {
search: /([^\n]+)([\n\s]*)/g, 'replace': "*$1*$2"
replace: "*$1*$2"
}, },
'function-italic' : { 'function-hr': undefined,
search: /([^\n]+)([\n\s]*)/g,
replace: "_$1_$2" 'function-blockquote': {
'replace': "----\n$1$2\n----"
}, },
'function-code' : { 'function-h1': {
search: /([^\n]+)([\n\s]*)/g, 'replace': "= $1$2"
replace: "`$1`$2"
}, },
'function-ul' : { 'function-h2': {
exec: function( txt, selText, $field ) { 'replace': "== $1$2"
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += '* ' + lines[i] + "\n";
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
}, },
'function-ol' : { 'function-h3': {
exec: function( txt, selText, $field ) { 'replace': "=== $1$2"
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += '. ' + lines[i] + "\n";
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
}, },
'function-blockquote' : { 'function-link': {
search: /(.+)([\n]?)/g, 'replace': function ( res ) {
replace: "----\n$1$2\n----", var rep = '';
break_line: true,
},
'function-h1' : {
search: /(.+)([\n]?)/g,
replace: "= $1$2",
break_line: true,
whole_line: true
},
'function-h2' : {
search: /(.+)([\n]?)/g,
replace: "== $1$2",
break_line: true,
whole_line: true
},
'function-h3' : {
search: /(.+)([\n]?)/g,
replace: "=== $1$2",
break_line: true,
whole_line: true
},
'function-link' : {
exec: function( txt, selText, $field ) {
var results = null;
$.GollumEditor.Dialog.init({
title: 'Insert Link',
fields: [
{
id: 'text',
name: 'Link Text',
type: 'text',
help: 'The text to display to the user.',
defaultValue: selText
},
{
id: 'href',
name: 'URL',
type: 'text',
help: 'The URL to link to.'
}
],
OK: function( res ) {
var h = '';
if ( res['text'] && res['href'] ) { if ( res['text'] && res['href'] ) {
h = res['href'] + '[' + rep = res['href'] + '[' + res['text'] + ']';
res['text'] + ']';
} }
$.GollumEditor.replaceSelection( h ); return rep;
}
});
} }
}, },
'function-image' : { 'function-image': {
exec: function( txt, selText, $field ) { 'replace': function ( res ) {
var results = null; var rep = '';
$.GollumEditor.Dialog.init({
title: 'Insert Image',
fields: [
{
id: 'url',
name: 'Image URL',
type: 'text'
},
{
id: 'alt',
name: 'Alt Text',
type: 'text'
}
],
OK: function( res ) {
var h = '';
if ( res['url'] && res['alt'] ) { if ( res['url'] && res['alt'] ) {
h = 'image::' + res['url'] + rep = 'image::' + res['url'] + '[' + res['alt'] + ']';
'[' + res['alt'] + ']';
} }
$.GollumEditor.replaceSelection( h ); return rep;
} }
});
} }
}, };
'function-critic-accept' : { $.GollumEditor.defineLanguage('asciidoc', $.constructLanguageDefinition(AsciiDoc));
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
}, var AsciiDocHelp = [
'function-critic-reject' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
}
};
$.GollumEditor.defineLanguage('asciidoc', AsciiDoc);
var AsciiDocHelp = [
{ {
menuName: 'Text Formatting', menuName: 'Text Formatting',
content: [ content: [
@@ -224,8 +110,8 @@ var AsciiDocHelp = [
} }
] ]
} }
]; ];
$.GollumEditor.defineHelp('asciidoc', AsciiDocHelp); $.GollumEditor.defineHelp('asciidoc', AsciiDocHelp);
})(jQuery); })(jQuery);
@@ -1,145 +1,70 @@
/** /**
* Creole Language Definition * Creole Language Definition
* See default.js for documentation
* *
*/ */
(function($) { (function($) {
var Creole = { // No need to set all the replacements, only those different from the default language (Markdown).
var Creole = {
'function-bold' : { 'function-italic': {
search: /([^\n]+)([\n]*)/gi, 'replace': "//$1//$2"
replace: "**$1**$2"
}, },
'function-italic' : { 'function-code': {
search: /([^\n]+)([\n]*)/gi, 'replace': "{{{$1}}}$2"
replace: "//$1//$2"
}, },
'function-code' : { 'function-hr': {
search: /([^\n]+)([\n]*)/gi, 'append': "\n\n----\n\n"
replace: "{{{$1}}}$2"
}, },
'function-hr' : { 'function-blockquote': undefined,
append: "\n\n----\n\n"
},
'function-ul' : {
exec: function( txt, selText, $field ) {
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += '* ' + lines[i] + "\n";
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
},
/* This looks silly but is completely valid Markdown */
'function-ol' : {
exec: function( txt, selText, $field ) {
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += '# ' + lines[i] + "\n";
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
},
'function-link' : {
exec: function( txt, selText, $field ) {
var results = null;
$.GollumEditor.Dialog.init({
title: 'Insert Link',
fields: [
{
id: 'text',
name: 'Link Text',
type: 'text',
help: 'The text to display to the user.',
defaultValue: selText
},
{
id: 'href',
name: 'URL',
type: 'text',
help: 'The URL to link to.'
}
],
OK: function( res ) {
var h = '[[' + res['href'] + '|' +
res['text'] + ']]';
$.GollumEditor.replaceSelection( h );
}
});
'function-ol': {
'line': function ( index, line) {
return '# ' + line + "\n";
} }
}, },
'function-image' : { 'function-h1': {
exec: function( txt, selText, $field ) { 'replace': "== $1$2"
var results = null;
$.GollumEditor.Dialog.init({
title: 'Insert Image',
fields: [
{
id: 'url',
name: 'Image URL',
type: 'text'
}, },
{
id: 'alt', 'function-h2': {
name: 'Alt Text', 'replace': "=== $1$2"
type: 'text' },
'function-h3': {
'replace': "==== $1$2"
},
'function-link': {
'replace': function ( res ) {
var rep = '';
if ( res['text'] && res['href'] ) {
rep = '[[' + res['href'] + '|' + res['text'] + ']]';
} }
], return rep;
OK: function( res ) { }
var h = ''; },
'function-image': {
'replace': function ( res ) {
var rep = '';
if ( res['url'] && res['alt'] ) { if ( res['url'] && res['alt'] ) {
h = '{{' + res['url']; rep = '{{' + res['url'];
if ( res['alt'] != '' ) { if ( res['alt'] != '' ) {
h += '|' + res['alt'] + '}}'; rep += '|' + res['alt'];
}
rep = rep + '}}';
}
return rep;
} }
} }
$.GollumEditor.replaceSelection( h ); };
}
});
}
},
'function-critic-accept' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
}, $.GollumEditor.defineLanguage('creole', $.constructLanguageDefinition(Creole));
'function-critic-reject' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
}
};
$.GollumEditor.defineLanguage('creole', Creole);
})(jQuery); })(jQuery);
@@ -0,0 +1,201 @@
/**
* Default Language Definition
*
* Standard language definition for string manipulation operations which can be used
* to generate others language definition. The default rules below describe
* the Markdown markup language. (The Markdown definition is therefore just a
* deep clone of $.DefaultLanguage.)
*
* Language definitions use 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.
*
* If the 'append' property is set for a function, its value will be appended at the cursor position.
*
* Some functions have the 'break_line' and 'whole_line' boolean properties set.
* You can use these to indicate whether a function inserts a newline (break_line),
* and whether just the selection or the whole line should be replaced (whole_line).
* These also influence cursor placement after text in the editor has been replaced.
*
**/
(function($) {
$.constructLanguageDefinition = function (newLang) {
var result = $.extend(true, {}, $.DefaultLang, newLang);
Object.keys(newLang).forEach(function (key) {
if(typeof newLang[key] === 'undefined'){
delete result[key];
}
});
return result;
};
var initDialog = function( title, fields, onResult) {
$.GollumEditor.Dialog.init({
title: title,
fields: fields,
OK: function( res ) {
$.GollumEditor.replaceSelection( onResult(res) );
}
});
};
$.DefaultLang = {
'function-bold' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "**$1**$2"
},
'function-italic' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "_$1_$2"
},
'function-code' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "`$1`$2"
},
'function-hr' : {
append: "\n***\n"
},
'function-ul' : {
exec: function( txt, selText, $field ) {
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += '* ' + lines[i] + "\n";
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
},
/* based on rdoc.js */
'function-ol' : {
line: function ( index, line) {
// This function generates the markup for a line of the ol, based on the line number (index) and the content of the line (line).
// Override this function for alternative markups when needed.
return index.toString() + '. ' + line + "\n"; // result e.g. "1. Previously existing text\n"
},
exec: function( txt, selText, $field ) {
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += this.line(i+1, lines[i]);
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
},
'function-blockquote' : {
search: /(.+)([\n]?)/g,
replace: "> $1$2",
break_line: true,
},
'function-h1' : {
search: /(.+)([\n]?)/g,
replace: "# $1$2",
break_line: true,
whole_line: true
},
'function-h2' : {
search: /(.+)([\n]?)/g,
replace: "## $1$2",
break_line: true,
whole_line: true
},
'function-h3' : {
search: /(.+)([\n]?)/g,
replace: "### $1$2",
break_line: true,
whole_line: true
},
'function-link' : {
replace: function ( res ) {
// The replace function generates the markup to be inserted from the result of the Dialog (res).
// Set a different replace function if your markup requires it.
var rep = '';
if ( res['text'] && res['href'] ) {
rep = '[' + res['text'] + '](' + res['href'] + ')';
}
return rep;
},
exec: function (txt, selText, $field) {
initDialog('Insert Link', [
{
id: 'text',
name: 'Link Text',
type: 'text',
defaultValue: selText
},
{
id: 'href',
name: 'URL',
type: 'text'
}
], this.replace)
}
},
'function-image' : {
replace: function( res ) {
// The replace function generates the markup to be inserted from the result of the Dialog (res).
// Set a different replace function if your markup requires it.
var rep = '';
if ( res['url'] && res['alt'] ) {
rep = '![' + res['alt'] + ']' + '(' + res['url'] + ')';
}
return rep;
},
exec: function (txt, selText, $field) {
initDialog('Insert Image', [
{
id: 'url',
name: 'Image Url',
type: 'text',
defaultValue: selText
},
{
id: 'alt',
name: 'Alt Text',
type: 'text'
}
], this.replace)
}
},
'function-critic-accept' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
},
'function-critic-reject' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
}
};
})(jQuery);
@@ -1,183 +1,13 @@
/** /**
* Markdown Language Definition * Markdown Language Definition
* * See default.js for documentation
* 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($) { (function($) {
var MarkDown = { var MarkDown = $.extend(true, {}, $.DefaultLang); // The default language definition is markdown, so copy it into a new variable.
$.GollumEditor.defineLanguage('markdown', MarkDown);
'function-bold' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "**$1**$2"
},
'function-italic' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "_$1_$2"
},
'function-code' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "`$1`$2"
},
'function-hr' : {
append: "\n***\n"
},
'function-ul' : {
exec: function( txt, selText, $field ) {
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += '* ' + lines[i] + "\n";
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
},
/* based on rdoc.js */
'function-ol' : {
exec: function( txt, selText, $field ) {
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += (i+1).toString() + '. ' +
lines[i] + "\n";
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
},
'function-blockquote' : {
search: /(.+)([\n]?)/g,
replace: "> $1$2",
break_line: true,
},
'function-h1' : {
search: /(.+)([\n]?)/g,
replace: "# $1$2",
break_line: true,
whole_line: true
},
'function-h2' : {
search: /(.+)([\n]?)/g,
replace: "## $1$2",
break_line: true,
whole_line: true
},
'function-h3' : {
search: /(.+)([\n]?)/g,
replace: "### $1$2",
break_line: true,
whole_line: true
},
'function-link' : {
exec: function( txt, selText, $field ) {
var results = null;
$.GollumEditor.Dialog.init({
title: 'Insert Link',
fields: [
{
id: 'text',
name: 'Link Text',
type: 'text',
defaultValue: selText
},
{
id: 'href',
name: 'URL',
type: 'text'
}
],
OK: function( res ) {
var rep = '';
if ( res['text'] && res['href'] ) {
rep = '[' + res['text'] + '](' +
res['href'] + ')';
}
$.GollumEditor.replaceSelection( rep );
}
});
}
},
'function-image' : {
exec: function( txt, selText, $field ) {
var results = null;
$.GollumEditor.Dialog.init({
title: 'Insert Image',
fields: [
{
id: 'url',
name: 'Image URL',
type: 'text'
},
{
id: 'alt',
name: 'Alt Text',
type: 'text'
}
],
OK: function( res ) {
var rep = '';
if ( res['url'] && res['alt'] ) {
rep = '![' + res['alt'] + ']' +
'(' + res['url'] + ')';
}
$.GollumEditor.replaceSelection( rep );
}
});
}
},
'function-critic-accept' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
},
'function-critic-reject' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
}
};
var MarkDownHelp = [ var MarkDownHelp = [
@@ -257,8 +87,6 @@ var MarkDownHelp = [
} }
]; ];
$.GollumEditor.defineLanguage('markdown', MarkDown);
$.GollumEditor.defineHelp('markdown', MarkDownHelp); $.GollumEditor.defineHelp('markdown', MarkDownHelp);
})(jQuery); })(jQuery);
@@ -1,19 +1,19 @@
/** /**
* MediaWiki Language Definition * MediaWiki Language Definition
* See default.js for documentation
* *
*/ */
(function($) { (function($) {
// No need to set all the replacements, only those different from the default language (Markdown).
var MediaWiki = { var MediaWiki = {
'function-bold' : { 'function-bold' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "'''$1'''$2" replace: "'''$1'''$2"
}, },
'function-italic' : { 'function-italic' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "''$1''$2" replace: "''$1''$2"
}, },
'function-hr' : { 'function-hr' : {
@@ -21,125 +21,41 @@ var MediaWiki = {
}, },
'function-code' : { 'function-code' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "<code>$1</code>$2" replace: "<code>$1</code>$2"
}, },
'function-ul' : {
exec: function( txt, selText, $field ) {
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += '* ' + lines[i] + "\n";
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
},
'function-ol' : { 'function-ol' : {
exec: function( txt, selText, $field ) { link: function ( index, line) {
var repText = ''; return '# ' + line + "\n";
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += '# ' + lines[i] + "\n";
} }
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
}, },
},
'function-blockquote' : { 'function-blockquote' : {
search: /(.+)([\n]?)/g,
replace: "<blockquote>\n$1$2\n</blockquote>", replace: "<blockquote>\n$1$2\n</blockquote>",
break_line: true,
}, },
'function-h1' : { 'function-h1' : {
search: /(.+)([\n]?)/g,
replace: "= $1$2 =", replace: "= $1$2 =",
break_line: true,
whole_line: true
}, },
'function-h2' : { 'function-h2' : {
search: /(.+)([\n]?)/g,
replace: "== $1$2 ==", replace: "== $1$2 ==",
break_line: true,
whole_line: true
}, },
'function-h3' : { 'function-h3' : {
search: /(.+)([\n]?)/g,
replace: "=== $1$2 ===", replace: "=== $1$2 ===",
break_line: true,
whole_line: true
}, },
'function-link' : { 'function-link' : {
exec: function( txt, selText, $field ) { replace: function( res ) {
var results = null; var rep = '';
$.GollumEditor.Dialog.init({
title: 'Insert Link',
fields: [
{
id: 'text',
name: 'Link Text',
type: 'text',
help: 'The text to display to the user.',
defaultValue: selText
},
{
id: 'href',
name: 'URL',
type: 'text',
help: 'The URL to link to.'
}
],
OK: function( res ) {
var h = '';
if ( res['text'] && res['href'] ) { if ( res['text'] && res['href'] ) {
h = '[' + res['href'] + ' | ' + rep = '[' + res['href'] + ' | ' + res['text'] + ']';
res['text'] + ']';
} }
$.GollumEditor.replaceSelection( h ); return rep;
} }
});
} }
},
'function-critic-accept' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
},
'function-critic-reject' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
}
}; };
$.GollumEditor.defineLanguage('mediawiki', MediaWiki); $.GollumEditor.defineLanguage('mediawiki', $.constructLanguageDefinition(MediaWiki));
var MediaWikiHelp = [ var MediaWikiHelp = [
@@ -1,162 +1,69 @@
/** /**
* Org-mode Language Definition * Org-mode Language Definition
* See default.js for documentation
**/ **/
(function($) { (function($) {
// No need to set all the replacements, only those different from the default language (Markdown).
var OrgMode = { var OrgMode = {
'function-bold' : { 'function-bold': {
search: /([^\n]+)([\n\s]*)/g,
replace: "*$1*$2" replace: "*$1*$2"
}, },
'function-italic' : { 'function-italic': {
search: /([^\n]+)([\n\s]*)/g,
replace: "/$1/$2" replace: "/$1/$2"
}, },
'function-code' : { 'function-code': {
search: /(^[\n]+)([\n\s]*)/g,
replace: "=$1=$2" replace: "=$1=$2"
}, },
'function-ul' : { 'function-hr': undefined,
exec: function( txt, selText, $field ) {
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += '* ' + lines[i] + "\n";
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
},
'function-ol' : {
exec: function( txt, selText, $field ) {
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += (i+1).toString() + '. ' +
lines[i] + "\n";
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
},
'function-blockquote' : { 'function-blockquote' : {
search: /(.+)([\n]?)/g, replace: "#+BEGIN_QUOTE\n$1$2\n#+END_QUOTE"
replace: "#+BEGIN_QUOTE\n$1$2\n#+END_QUOTE",
break_line: true,
}, },
'function-h1' : { 'function-h1' : {
search: /(.+)([\n]?)/g, replace: "* $1$2"
replace: "* $1$2",
break_line: true,
whole_line: true
}, },
'function-h2' : { 'function-h2' : {
search: /(.+)([\n]?)/g, replace: "** $1$2"
replace: "** $1$2",
break_line: true,
whole_line: true
}, },
'function-h3' : { 'function-h3' : {
search: /(.+)([\n]?)/g, replace: "*** $1$2"
replace: "*** $1$2",
break_line: true,
whole_line: true
}, },
'function-link' : { 'function-link' : {
exec: function( txt, selText, $field ) { replace: function ( res ) {
var results = null;
$.GollumEditor.Dialog.init({
title: 'Insert Link',
fields: [
{
id: 'text',
name: 'Link Text',
type: 'text',
defaultValue: selText
},
{
id: 'href',
name: 'URL',
type: 'text'
}
],
OK: function( res ) {
var rep = ''; var rep = '';
if ( res['text'] && res['href'] ) { if ( res['text'] && res['href'] ) {
rep = '[[' + res['href'] + '][' + rep = '[[' + res['href'] + '][' + res['text'] + ']]';
res['text'] + ']]';
} }
else if ( res['href'] ) { else if ( res['href'] ) {
rep = '[[' + res['href'] + ']]'; rep = '[[' + res['href'] + ']]';
} }
$.GollumEditor.replaceSelection( rep ); return rep;
}
});
} }
}, },
'function-image' : { 'function-image' : {
exec: function( txt, selText, $field ) { replace: function ( res ) {
var results = null;
$.GollumEditor.Dialog.init({
title: 'Insert Image',
fields: [
{
id: 'url',
name: 'Image URL',
type: 'text'
}
],
OK: function( res ) {
var rep = ''; var rep = '';
if ( res['url'] ) { if ( res['url'] ) {
rep = '[[' + res['url'] + ']]'; rep = '[[' + res['url'] + ']]';
} }
$.GollumEditor.replaceSelection( rep ); return rep;
} }
});
} }
},
'function-critic-accept' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
},
'function-critic-reject' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
}
}; };
$.GollumEditor.defineLanguage('org', $.constructLanguageDefinition(OrgMode));
var OrgModeHelp = [ var OrgModeHelp = [
{ {
@@ -216,7 +123,6 @@ var OrgModeHelp = [
]; ];
$.GollumEditor.defineLanguage('org', OrgMode);
$.GollumEditor.defineHelp('org', OrgModeHelp); $.GollumEditor.defineHelp('org', OrgModeHelp);
})(jQuery); })(jQuery);
@@ -1,106 +1,54 @@
/** /**
* Pod Language Definition * Pod Language Definition
* See default.js for documentation
**/ **/
(function($) { (function($) {
// No need to set all the replacements, only those different from the default language (Markdown).
var Pod = { var Pod = {
'function-bold' : { 'function-bold' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "B<$1>$2" replace: "B<$1>$2"
}, },
'function-italic' : { 'function-italic' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "I<$1>$2" replace: "I<$1>$2"
}, },
'function-hr' : undefined,
'function-code' : { 'function-code' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "C<$1>$2" replace: "C<$1>$2"
}, },
'function-h1' : { 'function-h1' : {
search: /(.+)([\n]?)/gi, replace: "=head1 $1$2"
replace: "=head1 $1$2",
break_line: true,
whole_line: true
}, },
'function-h2' : { 'function-h2' : {
search: /(.+)([\n]?)/gi, replace: "=head2 $1$2"
replace: "=head2 $1$2",
break_line: true,
whole_line: true
}, },
'function-h3' : { 'function-h3' : {
search: /(.+)([\n]?)/gi, replace: "=head3 $1$2"
replace: "=head3 $1$2",
break_line: true,
whole_line: true
}, },
'function-link' : { 'function-link' : {
exec: function( txt, selText, $field ) { replace: function ( res ) {
var results = null;
$.GollumEditor.Dialog.init({
title: 'Insert Link',
fields: [
{
id: 'text',
name: 'Link Text',
type: 'text',
defaultValue: selText
},
{
id: 'href',
name: 'URL',
type: 'text'
}
],
OK: function( res ) {
var rep = ''; var rep = '';
if ( res['text'] && res['href'] ) { if ( res['text'] && res['href'] ) {
rep = 'L<' + res['text'] + '|' + rep = 'L<' + res['text'] + '|' + res['href'] + '>';
res['href'] + '>';
} }
$.GollumEditor.replaceSelection( rep ); return rep;
}
});
} }
}, },
'function-image' : undefined,
'function-critic-accept' : { 'function-ul' : undefined,
exec: function( txt, selText, $field) { 'function-ol' : undefined,
var toReplace = selText. 'function-blockquote' : undefined
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
},
'function-critic-reject' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
}
}; };
$.GollumEditor.defineLanguage('pod', Pod); $.GollumEditor.defineLanguage('pod', $.constructLanguageDefinition(Pod));
var PodHelp = [ var PodHelp = [
@@ -1,110 +1,23 @@
/** /**
* Markdown Language Definition * Rdoc Language Definition
* * See default.js for documentation
* 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($) { (function($) {
// No need to set all the replacements, only those different from the default language (Markdown).
// RDoc is pretty bare bones, so we only need to unset some functions.
var RDoc = { var RDoc = {
'function-code' : undefined,
'function-bold' : { 'function-h1' : undefined,
search: /([^\n]+)([\n\s]*)/g, 'function-h2' : undefined,
replace: "((*$1*))$2" 'function-h3' : undefined,
}, 'function-link' : undefined,
'function-code' : { 'function-image' : undefined,
search: /([^\n]+)([\n\s]*)/g, 'function-hr' : undefined,
replace: "(({$1}))$2" 'function-blockquote' : undefined,
},
'function-ul' : {
exec: function( txt, selText, $field ) {
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += '* ' + lines[i] + "\n";
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
},
'function-ol' : {
exec: function( txt, selText, $field ) {
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += (i+1).toString() + '. ' +
lines[i] + "\n";
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
},
'function-h1' : {
search: /(.+)([\n]?)/gi,
replace: "= $1$2",
break_line: true,
whole_line: true
},
'function-h2' : {
search: /(.+)([\n]?)/gi,
replace: "== $1$2",
break_line: true,
whole_line: true
},
'function-h3' : {
search: /(.+)([\n]?)/gi,
replace: "=== $1$2",
break_line: true,
whole_line: true,
},
'function-critic-accept' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
},
'function-critic-reject' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
}
}; };
$.GollumEditor.defineLanguage('rdoc', RDoc); $.GollumEditor.defineLanguage('rdoc', $.constructLanguageDefinition(RDoc));
})(jQuery); })(jQuery);
@@ -1,38 +1,29 @@
/** /**
* reStructuredText Language Definition * reStructuredText Language Definition
* * See default.js for documentation
* A language definition for string manipulation operations, in this case
* for the reStructuredText 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($) { (function($) {
var reStructuredText = {
var headerFunc = function (selText, selectedRange, symbol) {
adornment = symbol.repeat(selText.length);
repText = selText + "\n" + adornment + "\n";
$.GollumEditor.replaceSelection(repText, false, false, selectedRange);
};
// No need to set all the replacements, only those different from the default language (Markdown).
var reStructuredText = {
'function-bold' : { 'function-bold' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "**$1**$2" replace: "**$1**$2"
}, },
'function-italic' : { 'function-italic' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "*$1*$2" replace: "*$1*$2"
}, },
'function-code' : { 'function-code' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "``$1``$2" replace: "``$1``$2"
}, },
@@ -40,30 +31,6 @@ var reStructuredText = {
append: "\n\n----\n\n" append: "\n\n----\n\n"
}, },
'function-ul' : {
exec: function(txt, selText, $field) {
var pfx = "* ";
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
lines[i] = pfx + lines[i];
}
var repText = lines.join("\n");
$.GollumEditor.replaceSelection(repText);
}
},
'function-ol' : {
exec: function( txt, selText, $field) {
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
pfx = (i + 1).toString() + ". ";
lines[i] = pfx + lines[i];
}
var repText = lines.join("\n");
$.GollumEditor.replaceSelection(repText);
}
},
'function-blockquote' : { 'function-blockquote' : {
exec: function( txt, selText, $field) { exec: function( txt, selText, $field) {
var pfx = " "; var pfx = " ";
@@ -77,122 +44,52 @@ var reStructuredText = {
}, },
'function-h1' : { 'function-h1' : {
exec: function( txt, selText, $field) { symbol: '=',
var lines = selText.split("\n"); exec: function( txt, selText, $field, selectedRange) {
title = lines.shift(); headerFunc(selText, selectedRange, this.symbol);
subtitle = lines.join(' ');
title_adornment = "=".repeat(title.length);
subtitle_adornment = "~".repeat(subtitle.length);
if (title != "" && subtitle != "") {
repText = title_adornment + "\n" + title + "\n" + title_adornment + "\n" +
subtitle_adornment + "\n" + subtitle + "\n" + subtitle_adornment;
} else if (title != ""){
repText = title_adornment + "\n" + title + "\n" + title_adornment;
}
$.GollumEditor.replaceSelection(repText);
} }
}, },
'function-h2' : { 'function-h2' : {
exec: function( txt, selText, $field) { symbol: '-',
var lines = selText.split("\n"); exec: function( txt, selText, $field, selectedRange) {
header = lines.shift(); headerFunc(selText, selectedRange, this.symbol);
tail = lines.join("\n");
adornment = "=".repeat(header.length);
repText = header + "\n" + adornment + "\n" + tail;
$.GollumEditor.replaceSelection(repText);
}
},
'function-critic-accept' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
} }
}, },
'function-critic-reject' : { 'function-h3' : {
exec: function( txt, selText, $field) { symbol: '~',
var toReplace = selText. exec: function( txt, selText, $field, selectedRange) {
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, ""). headerFunc(selText, selectedRange, this.symbol);
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
} }
}, },
'function-link' : { 'function-link' : {
exec: function( txt, selText, $field ) { replace: function( res ) {
var results = null;
$.GollumEditor.Dialog.init({
title: 'Insert Link',
fields: [
{
id: 'text',
name: 'Link Text',
type: 'text',
defaultValue: selText
},
{
id: 'href',
name: 'URL',
type: 'text'
}
],
OK: function( res ) {
var rep = ''; var rep = '';
if ( res['text'] && res['href'] ) { if ( res['text'] && res['href'] ) {
rep = '`' + res['text'] + ' ' + rep = '`' + res['text'] + ' ' + '<' + res['href'] + '>`_';
'<' + res['href'] + '>`_';
} }
$.GollumEditor.replaceSelection( rep ); return rep;
}
});
} }
}, },
'function-image' : { 'function-image' : {
exec: function( txt, selText, $field ) { replace: function( res ) {
var results = null; var rep = '';
$.GollumEditor.Dialog.init({
title: 'Insert Image',
fields: [
{
id: 'url',
name: 'Image URL',
type: 'text'
},
{
id: 'alt',
name: 'Alt Text',
type: 'text'
}
],
OK: function( res ) {
var rep = "";
if ( res['url'] && res['alt'] ) { if ( res['url'] && res['alt'] ) {
rep = ".. image:: " + res['url'] + "\n" + rep = '.. image:: ' + res['url'] + "\n" + ' :alt: ' + res['alt'];
' :alt: ' + res['alt'];
} }
$.GollumEditor.replaceSelection( rep ); return rep;
}
});
} }
} }
}; };
var reStructuredTextHelp = [ $.GollumEditor.defineLanguage('rst', $.constructLanguageDefinition(reStructuredText));
var reStructuredTextHelp = [
{ {
menuName: 'Block Elements', menuName: 'Block Elements',
@@ -258,10 +155,8 @@ var reStructuredTextHelp = [
} }
] ]
} }
]; ];
$.GollumEditor.defineHelp('rest', reStructuredTextHelp);
$.GollumEditor.defineLanguage('rest', reStructuredText);
$.GollumEditor.defineHelp('rest', reStructuredTextHelp);
})(jQuery); })(jQuery);
@@ -1,154 +1,69 @@
/** /**
* Textile Language Definition * Textile Language Definition
* See default.js for documentation
*
*/ */
(function($) { (function($) {
// No need to set all the replacements, only those different from the default language (Markdown).
var Textile = { var Textile = {
'function-bold' : { 'function-hr' : undefined,
search: /([^\n]+)([\n\s]*)/g,
replace: "*$1*$2"
},
'function-italic' : {
search: /([^\n]+)([\n\s]*)/g,
replace: "_$1_$2"
},
'function-hr' : {
append: "\n***\n"
},
'function-code' : { 'function-code' : {
search: /([^\n]+)([\n\s]*)/g, replace: "bc. $1$2",
replace: "<pre><code>$1</code></pre>$2" whole_line: true
},
'function-ul' : {
exec: function( txt, selText, $field ) {
var repText = '';
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += '* ' + lines[i] + "\n";
}
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
}, },
'function-ol' : { 'function-ol' : {
exec: function( txt, selText, $field ) { 'line': function ( index, line) {
var repText = ''; return '# ' + line + "\n";
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) {
repText += '# ' + lines[i] + "\n";
} }
repText = repText.substring(0, repText.length-1)
$.GollumEditor.replaceSelection( repText, true, true );
},
}, },
'function-blockquote' : { 'function-blockquote' : {
search: /(.+)([\n]?)/gi,
replace: "bq. $1$2", replace: "bq. $1$2",
break_line: true, },
'function-h1' : {
replace: "h1. $1$2"
},
'function-h2' : {
replace: "h2. $1$2"
},
'function-h3' : {
replace: "h3. $1$2"
}, },
'function-link' : { 'function-link' : {
exec: function( txt, selText, $field ) { replace: function( res ) {
var results = null; var rep = '';
$.GollumEditor.Dialog.init({
title: 'Insert Link',
fields: [
{
id: 'text',
name: 'Link Text',
type: 'text',
help: 'The text to display to the user.',
defaultValue: selText
},
{
id: 'href',
name: 'URL',
type: 'text',
help: 'The URL to link to.'
}
],
OK: function( res ) {
var h = '';
if ( res['text'] && res['href'] ) { if ( res['text'] && res['href'] ) {
h = '"' + res['text'] + '":' + rep = '"' + res['text'] + '":' + res['href'];
res['href'];
} }
$.GollumEditor.replaceSelection( h ); return rep;
}
});
} }
}, },
'function-image' : { 'function-image' : {
exec: function( txt, selText, $field ) { replace: function( res ) {
var results = null; var rep = '';
$.GollumEditor.Dialog.init({
title: 'Insert Image',
fields: [
{
id: 'url',
name: 'Image URL',
type: 'text'
},
{
id: 'alt',
name: 'Alt Text',
type: 'text'
}
],
OK: function( res ) {
if ( res['url'] ) { if ( res['url'] ) {
var h = '!' + res['url']; var rep = '!' + res['url'];
if ( res['alt'] != '' ) { if ( res['alt'] != '' ) {
h += '(' + res['alt'] + ')'; rep += '(' + res['alt'] + ')';
} }
h += '!'; rep += '!';
$.GollumEditor.replaceSelection( h ); return rep;
} }
} }
});
} }
},
'function-critic-accept' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$2").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
},
'function-critic-reject' : {
exec: function( txt, selText, $field) {
var toReplace = selText.
replace(/\{\+\+(.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "").
replace(/\{--(.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}/gm, "$1").
replace(/\{~~(.*?)~>(.*?)~~\}/gm, "$1").
replace(/\{\=\=(.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(.*?)<<\}/gm, "$1").
replace(/\{>>(.*?)<<\}/gm, "")
$.GollumEditor.replaceSelection( toReplace );
}
}
}; };
$.GollumEditor.defineLanguage('textile', Textile); $.GollumEditor.defineLanguage('textile', $.constructLanguageDefinition(Textile));
var TextileHelp = [ var TextileHelp = [