Adding creole & asciidoc
This commit is contained in:
@@ -84,9 +84,7 @@
|
|||||||
* Used in exec() to display dialogs with dynamic fields.
|
* Used in exec() to display dialogs with dynamic fields.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$.GollumEditor.Dialog = function( argObject ) {
|
$.GollumEditor.Dialog = Dialog;
|
||||||
Dialog.init( argObject );
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -329,7 +327,6 @@
|
|||||||
reselect = false;
|
reselect = false;
|
||||||
}
|
}
|
||||||
repText += definitionObject.append;
|
repText += definitionObject.append;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (repText)
|
if (repText)
|
||||||
@@ -394,6 +391,11 @@
|
|||||||
var selectNew = false;
|
var selectNew = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var scrollTop = null;
|
||||||
|
if ( $field[0].scrollTop ) {
|
||||||
|
scrollTop = $field[0].scrollTop;
|
||||||
|
}
|
||||||
|
|
||||||
$field.val( fullStr.substring(0, selPos.start) + replaceText +
|
$field.val( fullStr.substring(0, selPos.start) + replaceText +
|
||||||
fullStr.substring(selPos.end));
|
fullStr.substring(selPos.end));
|
||||||
$field[0].focus();
|
$field[0].focus();
|
||||||
@@ -402,6 +404,11 @@
|
|||||||
$field[0].setSelectionRange( selPos.start,
|
$field[0].setSelectionRange( selPos.start,
|
||||||
selPos.start + replaceText.length );
|
selPos.start + replaceText.length );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( scrollTop ) {
|
||||||
|
// this jumps sometimes in FF
|
||||||
|
$field[0].scrollTop = scrollTop;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -417,7 +424,13 @@
|
|||||||
|
|
||||||
markupCreated = false,
|
markupCreated = false,
|
||||||
|
|
||||||
|
attachEvents: function( evtOK ) {
|
||||||
|
$('#gollum-editor-action-ok').click( Dialog.eventOK( evtOK ) );
|
||||||
|
$('#gollum-editor-action-cancel').click( Dialog.eventCancel );
|
||||||
|
},
|
||||||
|
|
||||||
createMarkup: function( title, body ) {
|
createMarkup: function( title, body ) {
|
||||||
|
Dialog.markupCreated = true;
|
||||||
return '<div id="gollum-editor-dialog">' +
|
return '<div id="gollum-editor-dialog">' +
|
||||||
'<div id="gollum-editor-title"><h4>' + title + '</h4></div>' +
|
'<div id="gollum-editor-title"><h4>' + title + '</h4></div>' +
|
||||||
'<div id="gollum-editor-body">' + body + '</div>'
|
'<div id="gollum-editor-body">' + body + '</div>'
|
||||||
@@ -428,32 +441,63 @@
|
|||||||
'</div>';
|
'</div>';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
eventCancel: function() {
|
||||||
|
Dialog.hide();
|
||||||
|
},
|
||||||
|
|
||||||
|
eventOK: function( evtOK ) {
|
||||||
|
var results = {};
|
||||||
|
|
||||||
|
// pass them to evtOK if it exists (which it should)
|
||||||
|
if ( evtOK &&
|
||||||
|
typeof evtOK == 'function' ) {
|
||||||
|
evtOK( results );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
hide: function() {
|
hide: function() {
|
||||||
$('#gollum-editor-dialog')
|
$('#gollum-editor-dialog').animate({ opacity: 0 }, {
|
||||||
|
duration: 700
|
||||||
|
complete: function() {
|
||||||
|
$('#gollum-editor-dialog').removeClass('active');
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
init: function( argObject ) {
|
init: function( argObject ) {
|
||||||
|
var title = '';
|
||||||
|
var body = '';
|
||||||
|
|
||||||
|
// bail out if necessary
|
||||||
|
if ( !argObject ||
|
||||||
|
typeof argObject != 'object' ) {
|
||||||
|
debug('Editor Dialog: Cannot init; invalid init object');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( Dialog.markupCreated ) {
|
||||||
|
$('#gollum-editor-dialog').remove();
|
||||||
|
}
|
||||||
|
var $dialog = $( Dialog.createMarkup( title, body ) );
|
||||||
|
$('body').append( $dialog );
|
||||||
|
Dialog.attachEvents( evtOK );
|
||||||
},
|
},
|
||||||
|
|
||||||
show: function( title, body ) {
|
show: function() {
|
||||||
if ( Dialog.markupCreated ) {
|
if ( !Dialog.markupCreated ) {
|
||||||
$('#gollum-editor-dialog').remove();
|
debug('Dialog: No markup to show. Please use init first.')
|
||||||
}
|
} else {
|
||||||
var $dialog = $( Dialog.createMarkup( title, body ) );
|
Dialog.position(); // position this thing
|
||||||
$('body').append( $dialog );
|
$('#gollum-editor-dialog').animate({ opacity: 0 }, {
|
||||||
Dialog.position(); // position this thing
|
duration: 1,
|
||||||
Dialog.attachEvents();
|
complete: function() {
|
||||||
$('#gollum-editor-dialog').animate({ opacity: 0 }, {
|
$('#gollum-editor-dialog').addClass('active');
|
||||||
duration: 1,
|
$('#gollum-editor-dialog').animate({ opacity: 100 }, {
|
||||||
complete: function() {
|
duration: 700
|
||||||
$('#gollum-editor-dialog').addClass('active');
|
});
|
||||||
$('#gollum-editor-dialog').animate({ opacity: 100 }, {
|
}
|
||||||
duration: 700
|
});
|
||||||
});
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
position: function() {
|
position: function() {
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
/**
|
||||||
|
* ASCIIDoc Language Definition
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
var ASCIIDoc = {
|
||||||
|
|
||||||
|
'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-ul' : {
|
||||||
|
search: /(.+)([\n]?)/gi,
|
||||||
|
replace: "* $1$2"
|
||||||
|
},
|
||||||
|
|
||||||
|
/* This looks silly but is completely valid Markdown */
|
||||||
|
'function-ol' : {
|
||||||
|
search: /(.+)([\n]?)/gi,
|
||||||
|
replace: ". $1$2"
|
||||||
|
},
|
||||||
|
|
||||||
|
'function-blockquote' : {
|
||||||
|
search: /(.+)([\n]?)/gi,
|
||||||
|
replace: "----\n$1$2\n----\n"
|
||||||
|
},
|
||||||
|
|
||||||
|
'function-link' : {
|
||||||
|
exec: function( txt, selText, $field ) {
|
||||||
|
var results = null;
|
||||||
|
$.GollumEditor.Dialog({
|
||||||
|
title: 'Insert Link',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
id: 'text',
|
||||||
|
name: 'Link Text',
|
||||||
|
type: 'text',
|
||||||
|
help: 'The text to display to the user.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'href',
|
||||||
|
name: 'URL',
|
||||||
|
type: 'text',
|
||||||
|
help: 'The URL to link to.'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
OK: function( res ) {
|
||||||
|
if ( res['text'] && res['href'] ) {
|
||||||
|
return res['href'] + '[' +
|
||||||
|
res['text'] + ']';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'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 ) {
|
||||||
|
if ( res['url'] && res['alt'] ) {
|
||||||
|
return 'image::' + res['url'] +
|
||||||
|
'[' + res['alt'] + ']';
|
||||||
|
} else
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// this is necessary for GollumEditor to pick this up
|
||||||
|
jQuery.GollumEditor.defineLanguage('markdown', ASCIIDoc);
|
||||||
|
|
||||||
|
})();
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/**
|
||||||
|
* Creole Language Definition
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
var Creole = {
|
||||||
|
|
||||||
|
'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----\n\n";
|
||||||
|
},
|
||||||
|
|
||||||
|
'function-ul' : {
|
||||||
|
search: /(.+)([\n]?)/gi,
|
||||||
|
replace: "* $1$2"
|
||||||
|
},
|
||||||
|
|
||||||
|
/* This looks silly but is completely valid Markdown */
|
||||||
|
'function-ol' : {
|
||||||
|
search: /(.+)([\n]?)/gi,
|
||||||
|
replace: "# $1$2"
|
||||||
|
},
|
||||||
|
|
||||||
|
'function-link' : {
|
||||||
|
exec: function( txt, selText, $field ) {
|
||||||
|
var results = null;
|
||||||
|
$.GollumEditor.Dialog({
|
||||||
|
title: 'Insert Link',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
id: 'text',
|
||||||
|
name: 'Link Text',
|
||||||
|
type: 'text',
|
||||||
|
help: 'The text to display to the user.'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'href',
|
||||||
|
name: 'URL',
|
||||||
|
type: 'text',
|
||||||
|
help: 'The URL to link to.'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
OK: function( res ) {
|
||||||
|
if ( res['text'] && res['href'] ) {
|
||||||
|
return '[[' + res['href'] + '|' +
|
||||||
|
res['text'] + ']]';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
'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 ) {
|
||||||
|
if ( res['url'] && res['alt'] ) {
|
||||||
|
var h = '{{' + res['url'];
|
||||||
|
if ( res['alt'] != '' ) {
|
||||||
|
h += '|' + res['alt'] + '}}';
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
} else
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
jQuery.GollumEditor.defineLanguage('creole', Creole);
|
||||||
|
|
||||||
|
})();
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
|
(function() {
|
||||||
|
|
||||||
var MarkDown = {
|
var MarkDown = {
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ var MarkDown = {
|
|||||||
exec: function( txt, selText, $field ) {
|
exec: function( txt, selText, $field ) {
|
||||||
var results = null;
|
var results = null;
|
||||||
$.GollumEditor.Dialog({
|
$.GollumEditor.Dialog({
|
||||||
title: '',
|
title: 'Insert Link',
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
id: 'text',
|
id: 'text',
|
||||||
@@ -89,11 +90,37 @@ var MarkDown = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
'function-image' : {
|
'function-image' : {
|
||||||
/* Stub */
|
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 ) {
|
||||||
|
if ( res['url'] && res['alt'] ) {
|
||||||
|
return '![' + res['alt'] + ']' +
|
||||||
|
'(' + res['url'] + ')';
|
||||||
|
} else
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// this is necessary for GollumEditor to pick this up
|
// this is necessary for GollumEditor to pick this up
|
||||||
jQuery.GollumEditor.defineLanguage('markdown', MarkDown);
|
jQuery.GollumEditor.defineLanguage('markdown', MarkDown);
|
||||||
|
|
||||||
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user