Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
refs #114, refs #158 preserve macro and stop preventing CKEditor enco…
…ding
  • Loading branch information
a-ono committed Nov 3, 2015
1 parent 806464a commit 00d935c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
52 changes: 52 additions & 0 deletions assets/ckeditor-contrib/plugins/redmine/plugin.js
@@ -0,0 +1,52 @@
(function(){
function preservedPattern(i) {
return "____preserved_" + i + "____";
}

function wrapConversion(f) {
return function(data) {
var preserved = [];

// preserve Redmine macro
data = data.replace(/\{\{[^\}]+\}\}/g, function(match) {
preserved.push(match);
return preservedPattern(preserved.length);
});

// convert
arguments[0] = data;
data = f.apply(this, arguments);

// restore
for (var i = 0; i < preserved.length; i++) {
data = data.replace(preservedPattern(i + 1), preserved[i]);
}

return data;
};
}

var element = document.createElement('div');
function decodeEntities(html) {
element.innerHTML = html;
html = element.textContent;
element.textContent = '';
return html;
}

function onText(text, node) {
return (node.parent.name == "a") ?
text : text.replace(/(^|\s)https?:\/\/\S*/g, decodeEntities);
}

CKEDITOR.plugins.add('redmine', {
afterInit: function(editor) {
var processor = editor.dataProcessor;

processor.toHtml = wrapConversion(processor.toHtml);
processor.toDataFormat = wrapConversion(processor.toDataFormat);
processor.htmlFilter.addRules({text: onText}, 11);
processor.dataFilter.addRules({text: onText}, 11);
}
});
})();
2 changes: 0 additions & 2 deletions config/ckeditor.yml.example
@@ -1,6 +1,4 @@
allowedContent: true
bodyClass: "wiki"
basicEntities: false
entities: false
removePlugins: "div,flash,forms,iframe"
forcePasteAsPlainText: false
2 changes: 0 additions & 2 deletions lib/redmine_ckeditor.rb
Expand Up @@ -74,8 +74,6 @@ def ckeditor_config
:extraPlugins => plugins.join(","),
:allowedContent => true,
:bodyClass => "wiki",
:basicEntities => false,
:entities => false,
:removePlugins => 'div,flash,forms,iframe',
:forcePasteAsPlainText => false
}
Expand Down

1 comment on commit 00d935c

@rompic
Copy link

@rompic rompic commented on 00d935c Nov 7, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a date for the next release including these changes?

Please sign in to comment.