Fix backreferencing/replacement issues
Add in a way to short-circuit missing language definitions
This commit is contained in:
@@ -13,7 +13,8 @@
|
||||
EditorMode: 'code',
|
||||
NewFile: false,
|
||||
HasFunctionBar: true,
|
||||
Debug: false
|
||||
Debug: false,
|
||||
NoDefinitionsFor: []
|
||||
};
|
||||
var ActiveOptions = {};
|
||||
|
||||
@@ -61,13 +62,14 @@
|
||||
// get form fields
|
||||
var oldAction = $('#gollum-editor form').attr('action');
|
||||
var $form = $($('#gollum-editor form').get(0));
|
||||
$form.attr('action', '/preview');
|
||||
$form.attr('action', this.href);
|
||||
$form.attr('target', '_blank');
|
||||
$form.submit();
|
||||
|
||||
|
||||
$form.attr('action', oldAction);
|
||||
$form.removeAttr('target');
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -217,8 +219,21 @@
|
||||
* @return void
|
||||
*/
|
||||
loadFor: function( markup_name, on_complete ) {
|
||||
// Keep us from hitting 404s on our site, check the definition blacklist
|
||||
if ( ActiveOptions.NoDefinitionsFor.length ) {
|
||||
for ( var i=0; i < ActiveOptions.NoDefinitionsFor.length; i++ ) {
|
||||
if ( markup_name == ActiveOptions.NoDefinitionsFor[i] ) {
|
||||
// we don't have this. get out.
|
||||
if ( typeof on_complete == 'function' ) {
|
||||
on_complete( null, 'error' );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// attempt to load the definition for this language
|
||||
var script_uri = '/javascript/gollum-editor/langs/' + markup_name + '.js';
|
||||
var script_uri = '/javascripts/editor/langs/' + markup_name + '.js';
|
||||
$.ajax({
|
||||
url: script_uri,
|
||||
dataType: 'script',
|
||||
@@ -475,27 +490,21 @@
|
||||
if ( definitionObject.search &&
|
||||
typeof definitionObject.search == 'object' ) {
|
||||
debug('Replacing search Regex');
|
||||
searchExp = definitionObject.search;
|
||||
searchExp = null;
|
||||
searchExp = new RegExp ( definitionObject.search );
|
||||
debug( searchExp );
|
||||
}
|
||||
debug(repText);
|
||||
debug('repText is ' + '"' + repText + '"');
|
||||
// replace text
|
||||
if ( definitionObject.replace &&
|
||||
typeof definitionObject.replace == 'string' ) {
|
||||
debug('Running replacement - using ' + definitionObject.replace);
|
||||
var rt = definitionObject.replace;
|
||||
var matches = searchExp.exec( repText );
|
||||
if ( matches && matches.length > 1 ) {
|
||||
debug(matches);
|
||||
for ( var i = 1; i < matches.length; i++ ) {
|
||||
var searchStr = '$' + i;
|
||||
debug('searching for ' + searchStr + ' to replace with ' + matches[i]);
|
||||
rt = rt.replace( searchStr, matches[i] );
|
||||
}
|
||||
// remove any excess backreferences from the replace string
|
||||
rt = rt.replace( /\$[\d]/g, '' );
|
||||
repText = rt;
|
||||
} else if ( repText === '' ) {
|
||||
repText = repText.replace( searchExp, rt );
|
||||
// remove backreferences
|
||||
repText = repText.replace( /\$[\d]/g, '' );
|
||||
|
||||
if ( repText === '' ) {
|
||||
debug('Search string is empty');
|
||||
|
||||
// find position of $1 - this is where we will place the cursor
|
||||
@@ -620,6 +629,7 @@
|
||||
|
||||
refresh: function() {
|
||||
if ( EditorHas.functionBar() ) {
|
||||
debug('Refreshing function bar');
|
||||
if ( LanguageDefinition.isValid() ) {
|
||||
$('#gollum-editor-function-bar a.function-button').unbind('click');
|
||||
FunctionBar.activate();
|
||||
@@ -982,6 +992,9 @@
|
||||
if ( $('#function-help').length ) {
|
||||
$('#function-help').addClass('disabled');
|
||||
}
|
||||
if ( Help.isShown() ) {
|
||||
Help.hide();
|
||||
}
|
||||
} else {
|
||||
Help._ACTIVE_HELP_LANG = name;
|
||||
if ( $("#function-help").length ) {
|
||||
|
||||
Reference in New Issue
Block a user