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,231 +1,117 @@
/** /**
* 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-code' : { 'function-blockquote': {
search: /([^\n]+)([\n\s]*)/g, 'replace': "----\n$1$2\n----"
replace: "`$1`$2" },
},
'function-ul' : { 'function-h1': {
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-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-blockquote' : { 'function-h3': {
search: /(.+)([\n]?)/g, 'replace': "=== $1$2"
replace: "----\n$1$2\n----", },
break_line: true,
},
'function-h1' : { 'function-link': {
search: /(.+)([\n]?)/g, 'replace': function ( res ) {
replace: "= $1$2", var rep = '';
break_line: true, if ( res['text'] && res['href'] ) {
whole_line: true rep = res['href'] + '[' + res['text'] + ']';
},
'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.'
} }
], return rep;
OK: function( res ) {
var h = '';
if ( res['text'] && res['href'] ) {
h = res['href'] + '[' +
res['text'] + ']';
}
$.GollumEditor.replaceSelection( h );
} }
}); },
'function-image': {
} 'replace': function ( res ) {
}, var 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 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' : {
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('asciidoc', $.constructLanguageDefinition(AsciiDoc));
var AsciiDocHelp = [
{
menuName: 'Text Formatting',
content: [
{
menuName: 'Headers',
data: '<p>AsciiDoc headers can be written in two ways: with differing underlines or with different indentation using <code>=</code> (equals sign). AsciiDoc supports headings 1-4. The editor will automatically use the <code>=</code> notation. To create a level one header, prefix your line with one <code>=</code>. Level two headers are created with <code>==</code> and so on.</p>'
},
{
menuName: 'Bold / Italic',
data: '<p>To display text as <strong>bold</strong>, wrap the text in <code>*</code> (asterisks). To display text as <em>italic</em>, wrap the text in <code>_</code> (underscores). To create <code>monospace</code> text, wrap the text in <code>`</code> (backtick).'
},
{
menuName: 'Scripts',
data: '<p>Superscript and subscript is created the same way as other inline formats. To create superscript text, wrap your text in <code>^</code> (carats). To create subscript text, wrap your text in <code>~</code> (tildes).</p>'
},
{
menuName: 'Special Characters',
data: '<p>AsciiDoc will automatically convert textual representations of commonly-used special characters. For example, <code>(R)</code> becomes &reg;, <code>(C)</code> becomes &copy; and <code>(TM)</code> becomes &trade;.</p>'
}
]
},
{
menuName: 'Blocks',
content: [
{
menuName: 'Paragraphs',
data: '<p>AsciiDoc allows paragraphs to have optional titles or icons to denote special sections. To make a normal paragraph, simply add a line between blocks and a new paragraph will start. If you want to title your paragraphs, adda line prefixed by <code>.</code> (full stop). An example paragraph with optional title is displayed below:<br><br><code>.Optional Title<br><br>This is my paragraph. It is two sentences long.</code></p>'
},
{
menuName: 'Source Blocks',
data: '<p>To create source blocks (long blocks of code), follow the same syntax as above but with an extra line denoting the inline source and lines of four dashes (<code>----</code>) delimiting the source block.. An example of Python source is below:<br><br><code>.python.py<br>[source,python]<br>----<br># i just wrote a comment in python<br># and maybe one more<br>----</code></p>'
},
{
menuName: 'Comment Blocks',
data: '<p>Comment blocks are useful if you want to keep notes for yourself inline but do not want them displayed to the public. To create a comment block, simply wrap the paragraph in dividers with four slashes (<code>////</code>). An example comment block is below:<br><br><code>////<br>My comment block is here now<br><br>It can be multiple paragraphs. Really.<br>////</p>'
},
{
menuName: 'Quote Blocks',
data: '<p>Quote blocks work much like comment blocks &mdash; simply create dividers using four underscores (<code>____</code>) around your quote. An example quote block is displayed below:<br><code>____<br>This is my quote block. Quote something nice here, otherwise there is no point in quoting.<br>____</code></p>'
}
]
},
{
menuName: 'Macros',
content: [
{
menuName: 'Links',
data: '<p>To create links to external pages, you can simply write the URI if you want the URI to link to itself. (i.e., <code>http://github.com/</code> will automatically be parsed to <a href="javascript:void(0);">http://github.com/</a>. If you want different text to be displayed, simply append it to the end of the URI in between <code>[</code> (brackets.) For example, <code>http://github.com/[GitHub]</code> will be parsed as <a href="javascript:void(0);">GitHub</a>, with the URI pointing to <code>http://github.com</code>.</p>'
},
{
menuName: 'Images',
data: '<p>Images in AsciiDoc work much like hyperlinks, but image URLs are prefixed with <code>image:</code>. For example, to link to an image at <code>images/icons/home.png</code>, write <code>image:images/icons/home.png</code>. Alt text can be added by appending the text to the URI in <code>[</code> (brackets).</p>'
}
]
}
];
}; $.GollumEditor.defineHelp('asciidoc', AsciiDocHelp);
$.GollumEditor.defineLanguage('asciidoc', AsciiDoc);
var AsciiDocHelp = [
{
menuName: 'Text Formatting',
content: [
{
menuName: 'Headers',
data: '<p>AsciiDoc headers can be written in two ways: with differing underlines or with different indentation using <code>=</code> (equals sign). AsciiDoc supports headings 1-4. The editor will automatically use the <code>=</code> notation. To create a level one header, prefix your line with one <code>=</code>. Level two headers are created with <code>==</code> and so on.</p>'
},
{
menuName: 'Bold / Italic',
data: '<p>To display text as <strong>bold</strong>, wrap the text in <code>*</code> (asterisks). To display text as <em>italic</em>, wrap the text in <code>_</code> (underscores). To create <code>monospace</code> text, wrap the text in <code>`</code> (backtick).'
},
{
menuName: 'Scripts',
data: '<p>Superscript and subscript is created the same way as other inline formats. To create superscript text, wrap your text in <code>^</code> (carats). To create subscript text, wrap your text in <code>~</code> (tildes).</p>'
},
{
menuName: 'Special Characters',
data: '<p>AsciiDoc will automatically convert textual representations of commonly-used special characters. For example, <code>(R)</code> becomes &reg;, <code>(C)</code> becomes &copy; and <code>(TM)</code> becomes &trade;.</p>'
}
]
},
{
menuName: 'Blocks',
content: [
{
menuName: 'Paragraphs',
data: '<p>AsciiDoc allows paragraphs to have optional titles or icons to denote special sections. To make a normal paragraph, simply add a line between blocks and a new paragraph will start. If you want to title your paragraphs, adda line prefixed by <code>.</code> (full stop). An example paragraph with optional title is displayed below:<br><br><code>.Optional Title<br><br>This is my paragraph. It is two sentences long.</code></p>'
},
{
menuName: 'Source Blocks',
data: '<p>To create source blocks (long blocks of code), follow the same syntax as above but with an extra line denoting the inline source and lines of four dashes (<code>----</code>) delimiting the source block.. An example of Python source is below:<br><br><code>.python.py<br>[source,python]<br>----<br># i just wrote a comment in python<br># and maybe one more<br>----</code></p>'
},
{
menuName: 'Comment Blocks',
data: '<p>Comment blocks are useful if you want to keep notes for yourself inline but do not want them displayed to the public. To create a comment block, simply wrap the paragraph in dividers with four slashes (<code>////</code>). An example comment block is below:<br><br><code>////<br>My comment block is here now<br><br>It can be multiple paragraphs. Really.<br>////</p>'
},
{
menuName: 'Quote Blocks',
data: '<p>Quote blocks work much like comment blocks &mdash; simply create dividers using four underscores (<code>____</code>) around your quote. An example quote block is displayed below:<br><code>____<br>This is my quote block. Quote something nice here, otherwise there is no point in quoting.<br>____</code></p>'
}
]
},
{
menuName: 'Macros',
content: [
{
menuName: 'Links',
data: '<p>To create links to external pages, you can simply write the URI if you want the URI to link to itself. (i.e., <code>http://github.com/</code> will automatically be parsed to <a href="javascript:void(0);">http://github.com/</a>. If you want different text to be displayed, simply append it to the end of the URI in between <code>[</code> (brackets.) For example, <code>http://github.com/[GitHub]</code> will be parsed as <a href="javascript:void(0);">GitHub</a>, with the URI pointing to <code>http://github.com</code>.</p>'
},
{
menuName: 'Images',
data: '<p>Images in AsciiDoc work much like hyperlinks, but image URLs are prefixed with <code>image:</code>. For example, to link to an image at <code>images/icons/home.png</code>, write <code>image:images/icons/home.png</code>. Alt text can be added by appending the text to the URI in <code>[</code> (brackets).</p>'
}
]
}
];
$.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' : { '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 );
},
},
/* This looks silly but is completely valid Markdown */ 'function-h1': {
'function-ol' : { 'replace': "== $1$2"
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' : { 'function-h2': {
exec: function( txt, selText, $field ) { 'replace': "=== $1$2"
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-h3': {
'replace': "==== $1$2"
},
} 'function-link': {
}, 'replace': function ( res ) {
var rep = '';
if ( res['text'] && res['href'] ) {
rep = '[[' + res['href'] + '|' + res['text'] + ']]';
}
return rep;
}
},
'function-image' : { 'function-image': {
exec: function( txt, selText, $field ) { 'replace': function ( res ) {
var results = null; var rep = '';
$.GollumEditor.Dialog.init({ if ( res['url'] && res['alt'] ) {
title: 'Insert Image', rep = '{{' + res['url'];
fields: [ if ( res['alt'] != '' ) {
{ rep += '|' + res['alt'];
id: 'url', }
name: 'Image URL', rep = rep + '}}';
type: 'text' }
}, return rep;
{ }
id: 'alt',
name: 'Alt Text',
type: 'text'
}
],
OK: function( res ) {
var h = '';
if ( res['url'] && res['alt'] ) {
h = '{{' + res['url'];
if ( res['alt'] != '' ) {
h += '|' + res['alt'] + '}}';
} }
} };
$.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({ if ( res['text'] && res['href'] ) {
title: 'Insert Link', rep = '[' + res['href'] + ' | ' + res['text'] + ']';
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'] ) {
h = '[' + res['href'] + ' | ' +
res['text'] + ']';
}
$.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 );
}
},
'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 );
} }
return rep;
} }
}
}; };
$.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; var rep = '';
$.GollumEditor.Dialog.init({ if ( res['text'] && res['href'] ) {
title: 'Insert Link', rep = '[[' + res['href'] + '][' + res['text'] + ']]';
fields: [ }
{ else if ( res['href'] ) {
id: 'text', rep = '[[' + res['href'] + ']]';
name: 'Link Text', }
type: 'text', return rep;
defaultValue: selText
},
{
id: 'href',
name: 'URL',
type: 'text'
}
],
OK: function( res ) {
var rep = '';
if ( res['text'] && res['href'] ) {
rep = '[[' + res['href'] + '][' +
res['text'] + ']]';
}
else if ( res['href'] ) {
rep = '[[' + res['href'] + ']]';
}
$.GollumEditor.replaceSelection( rep );
}
});
} }
}, },
'function-image' : { 'function-image' : {
exec: function( txt, selText, $field ) { replace: function ( res ) {
var results = null; var rep = '';
$.GollumEditor.Dialog.init({ if ( res['url'] ) {
title: 'Insert Image', rep = '[[' + res['url'] + ']]';
fields: [
{
id: 'url',
name: 'Image URL',
type: 'text'
}
],
OK: function( res ) {
var rep = '';
if ( res['url'] ) {
rep = '[[' + 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 );
} }
return rep;
} }
}
}; };
$.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; var rep = '';
$.GollumEditor.Dialog.init({ if ( res['text'] && res['href'] ) {
title: 'Insert Link', rep = 'L<' + res['text'] + '|' + res['href'] + '>';
fields: [ }
{ return rep;
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 = 'L<' + res['text'] + '|' +
res['href'] + '>';
}
$.GollumEditor.replaceSelection( 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,267 +1,162 @@
/** /**
* 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 = {
'function-bold' : { var headerFunc = function (selText, selectedRange, symbol) {
search: /([^\n]+)([\n\s]*)/g, adornment = symbol.repeat(selText.length);
replace: "**$1**$2" repText = selText + "\n" + adornment + "\n";
}, $.GollumEditor.replaceSelection(repText, false, false, selectedRange);
};
'function-italic' : { // No need to set all the replacements, only those different from the default language (Markdown).
search: /([^\n]+)([\n\s]*)/g, var reStructuredText = {
replace: "*$1*$2"
},
'function-code' : { 'function-bold' : {
search: /([^\n]+)([\n\s]*)/g, replace: "**$1**$2"
replace: "``$1``$2" },
},
'function-hr' : { 'function-italic' : {
append: "\n\n----\n\n" replace: "*$1*$2"
}, },
'function-ul' : { 'function-code' : {
exec: function(txt, selText, $field) { replace: "``$1``$2"
var pfx = "* "; },
var lines = selText.split("\n");
'function-hr' : {
append: "\n\n----\n\n"
},
'function-blockquote' : {
exec: function( txt, selText, $field) {
var pfx = " ";
var lines = selText.split("\n");
for ( var i = 0; i < lines.length; i++ ) { for ( var i = 0; i < lines.length; i++ ) {
lines[i] = pfx + lines[i]; lines[i] = pfx + lines[i];
} }
var repText = lines.join("\n"); var repText = lines.join("\n");
$.GollumEditor.replaceSelection(repText); $.GollumEditor.replaceSelection(repText);
} }
}, },
'function-ol' : { 'function-h1' : {
exec: function( txt, selText, $field) { symbol: '=',
var lines = selText.split("\n"); exec: function( txt, selText, $field, selectedRange) {
for ( var i = 0; i < lines.length; i++ ) { headerFunc(selText, selectedRange, this.symbol);
pfx = (i + 1).toString() + ". ";
lines[i] = pfx + lines[i];
} }
var repText = lines.join("\n"); },
$.GollumEditor.replaceSelection(repText);
}
},
'function-blockquote' : { 'function-h2' : {
exec: function( txt, selText, $field) { symbol: '-',
var pfx = " "; exec: function( txt, selText, $field, selectedRange) {
var lines = selText.split("\n"); headerFunc(selText, selectedRange, this.symbol);
for ( var i = 0; i < lines.length; i++ ) {
lines[i] = pfx + lines[i];
}
var repText = lines.join("\n");
$.GollumEditor.replaceSelection(repText);
}
},
'function-h1' : {
exec: function( txt, selText, $field) {
var lines = selText.split("\n");
title = lines.shift();
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' : {
exec: function( txt, selText, $field) {
var lines = selText.split("\n");
header = lines.shift();
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' : {
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 );
} }
}, },
'function-h3' : {
symbol: '~',
exec: function( txt, selText, $field, selectedRange) {
headerFunc(selText, selectedRange, this.symbol);
}
},
'function-link' : { 'function-link' : {
exec: function( txt, selText, $field ) { replace: function( res ) {
var results = null; var rep = '';
$.GollumEditor.Dialog.init({ if ( res['text'] && res['href'] ) {
title: 'Insert Link', rep = '`' + res['text'] + ' ' + '<' + res['href'] + '>`_';
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 );
} }
}); return rep;
} }
}, },
'function-image' : { 'function-image' : {
exec: function( txt, selText, $field ) { replace: function( res ) {
var results = null; var rep = '';
$.GollumEditor.Dialog.init({ if ( res['url'] && res['alt'] ) {
title: 'Insert Image', rep = '.. image:: ' + res['url'] + "\n" + ' :alt: ' + res['alt'];
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 = ".. image:: " + res['url'] + "\n" +
' :alt: ' + res['alt'];
}
$.GollumEditor.replaceSelection( rep );
} }
}); return rep;
}
} }
}
}; };
var reStructuredTextHelp = [ $.GollumEditor.defineLanguage('rst', $.constructLanguageDefinition(reStructuredText));
{ var reStructuredTextHelp = [
menuName: 'Block Elements',
content: [
{
menuName: 'Paragraphs &amp; Breaks',
data: '<p>To create a paragraph, simply create a block of text that is not separated by one or more blank lines. Blocks of text separated by one or more blank lines will be parsed as paragraphs.</p>'
},
{
menuName: 'Headers',
data: '<p>Rest uses overline/underline adornments to indicate headers. To create a header, underline your header text with adornment characters such as the <code>=, ~, +, ^</code> characters. Make sure that the adornment is of the same length (or longer) as the header text. Use a different adornment character to specify a different heading depth.</p>'
},
{
menuName: 'Blockquotes',
data: '<p>Rest creates blockquotes using indentation. This looks best if you use four spaces per level of indentation.</p>'
},
{
menuName: 'Lists',
data: '<p>Rest supports both ordered and unordered lists. To create an ordered list, simply prefix each line with a number, or use <code>#</code> for auto enumeration. To create an unordered list, you can prefix each line with <code>*</code>, <code>+</code> or <code>-</code>.</p>'
},
{
menuName: 'Code Blocks',
data: '<p>Rest wraps code blocks in pre-formatted tags to preserve indentation in your code blocks. To create a code block, indent the entire block by at least 4 spaces or one tab. Rest will strip the extra indentation you&rsquo;ve added to the code block.</p>'
},
{
menuName: 'Horizontal Rules',
data: '<p>Horizontal rules are created by placing four or more hyphens, asterisks or underscores on a line by themselves.</p>'
}
]
},
{ {
menuName: 'Span Elements', menuName: 'Block Elements',
content: [ content: [
{ {
menuName: 'Links', menuName: 'Paragraphs &amp; Breaks',
data: '<p>To create an inline link, create a set of backticks, include the link title first, followed by the url in angled brackets (e.g., <code>`Python <http://www.python.org/>`_</code>).</p>' data: '<p>To create a paragraph, simply create a block of text that is not separated by one or more blank lines. Blocks of text separated by one or more blank lines will be parsed as paragraphs.</p>'
}, },
{
menuName: 'Headers',
data: '<p>Rest uses overline/underline adornments to indicate headers. To create a header, underline your header text with adornment characters such as the <code>=, ~, +, ^</code> characters. Make sure that the adornment is of the same length (or longer) as the header text. Use a different adornment character to specify a different heading depth.</p>'
},
{
menuName: 'Blockquotes',
data: '<p>Rest creates blockquotes using indentation. This looks best if you use four spaces per level of indentation.</p>'
},
{
menuName: 'Lists',
data: '<p>Rest supports both ordered and unordered lists. To create an ordered list, simply prefix each line with a number, or use <code>#</code> for auto enumeration. To create an unordered list, you can prefix each line with <code>*</code>, <code>+</code> or <code>-</code>.</p>'
},
{
menuName: 'Code Blocks',
data: '<p>Rest wraps code blocks in pre-formatted tags to preserve indentation in your code blocks. To create a code block, indent the entire block by at least 4 spaces or one tab. Rest will strip the extra indentation you&rsquo;ve added to the code block.</p>'
},
{
menuName: 'Horizontal Rules',
data: '<p>Horizontal rules are created by placing four or more hyphens, asterisks or underscores on a line by themselves.</p>'
}
]
},
{ {
menuName: 'Emphasis', menuName: 'Span Elements',
data: '<p>Asterisks (<code>*</code>) are treated as emphasis and are wrapped with an <code>&lt;em&gt;</code> tag, which usually displays as italics in most browsers. Double asterisks (<code>**</code>) are treated as bold using the <code>&lt;strong&gt;</code> tag. To create italic or bold text, simply wrap your words in single/double asterisks. For example, <code>**My double emphasis text**</code> becomes <strong>My double emphasis text</strong>, and <code>*My single emphasis text*</code> becomes <em>My single emphasis text</em>.</p>' content: [
}, {
menuName: 'Links',
data: '<p>To create an inline link, create a set of backticks, include the link title first, followed by the url in angled brackets (e.g., <code>`Python <http://www.python.org/>`_</code>).</p>'
},
{ {
menuName: 'Code', menuName: 'Emphasis',
data: '<p>To create inline spans of code, simply wrap the code in backticks (<code>`</code>). Rest will turn <code>`myFunction`</code> into <code>myFunction</code>.</p>' data: '<p>Asterisks (<code>*</code>) are treated as emphasis and are wrapped with an <code>&lt;em&gt;</code> tag, which usually displays as italics in most browsers. Double asterisks (<code>**</code>) are treated as bold using the <code>&lt;strong&gt;</code> tag. To create italic or bold text, simply wrap your words in single/double asterisks. For example, <code>**My double emphasis text**</code> becomes <strong>My double emphasis text</strong>, and <code>*My single emphasis text*</code> becomes <em>My single emphasis text</em>.</p>'
}, },
{ {
menuName: 'Images', menuName: 'Code',
data: '<p>Rest image syntax is two dots, followed by a space, the word "image", two colons, another space, and the url: <code>.. image:: http://image.com/image.png</code>.</p>' data: '<p>To create inline spans of code, simply wrap the code in backticks (<code>`</code>). Rest will turn <code>`myFunction`</code> into <code>myFunction</code>.</p>'
} },
]
},
{ {
menuName: 'Miscellaneous', menuName: 'Images',
content: [ data: '<p>Rest image syntax is two dots, followed by a space, the word "image", two colons, another space, and the url: <code>.. image:: http://image.com/image.png</code>.</p>'
{ }
menuName: 'Escaping', ]
data: '<p>If you want to use a special Rest character in your document (such as displaying literal asterisks), you can escape the character with the backslash (<code>\\</code>). Rest will ignore the character directly after a backslash.' },
}
]
}
];
{
menuName: 'Miscellaneous',
content: [
{
menuName: 'Escaping',
data: '<p>If you want to use a special Rest character in your document (such as displaying literal asterisks), you can escape the character with the backslash (<code>\\</code>). Rest will ignore the character directly after a backslash.'
}
]
}
];
$.GollumEditor.defineLanguage('rest', reStructuredText); $.GollumEditor.defineHelp('rest', reStructuredTextHelp);
$.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({ if ( res['text'] && res['href'] ) {
title: 'Insert Link', rep = '"' + res['text'] + '":' + res['href'];
fields: [ }
{ return rep;
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'] ) {
h = '"' + res['text'] + '":' +
res['href'];
}
$.GollumEditor.replaceSelection( h );
}
});
} }
}, },
'function-image' : { 'function-image' : {
exec: function( txt, selText, $field ) { replace: function( res ) {
var results = null; var rep = '';
$.GollumEditor.Dialog.init({ if ( res['url'] ) {
title: 'Insert Image', var rep = '!' + res['url'];
fields: [ if ( res['alt'] != '' ) {
{ rep += '(' + res['alt'] + ')';
id: 'url',
name: 'Image URL',
type: 'text'
},
{
id: 'alt',
name: 'Alt Text',
type: 'text'
}
],
OK: function( res ) {
if ( res['url'] ) {
var h = '!' + res['url'];
if ( res['alt'] != '' ) {
h += '(' + res['alt'] + ')';
}
h += '!';
$.GollumEditor.replaceSelection( h );
}
} }
}); 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('textile', Textile); $.GollumEditor.defineLanguage('textile', $.constructLanguageDefinition(Textile));
var TextileHelp = [ var TextileHelp = [