Compare commits

...

4 Commits

Author SHA1 Message Date
Vitaliy Filippov 96d95a8160 Explain what are *GT* 2015-08-12 01:33:08 +03:00
Vitaliy Filippov e8aecceb3d Add README 2015-08-12 01:26:03 +03:00
parhelionix 58c71157b1 Get rid of eval() @ line 676
Now, nicEdit is ready to use in chrome extensions and apps platform :)
2015-08-12 01:26:03 +03:00
Vitaliy Filippov 8200365acc Add plugin to sanitize pasted HTML 2015-08-12 01:26:03 +03:00
7 changed files with 167 additions and 4 deletions

9
License.md Normal file
View File

@ -0,0 +1,9 @@
NicEdit License
Copyright (c) 2007-2008 Brian Kirchoff [(http://nicedit.com)](http://nicedit.com), (c) 2012+ Vitaliy Filippov (vitalif@mail.ru)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

12
README.md Normal file
View File

@ -0,0 +1,12 @@
nicEdit is a lightweight, Cross Platform WYSIWYG editor
This is my (Vitaliy Filippov's) fork of nicEdit which I use in my projects since 2012.
It has several improvements:
* Table plugin
* Example plugins for "wiki-like CMS integrated" image uploads and link insertions
* Russian localisation
* Reworked nicFloatingPanel
* Sanitize pasted HTML plugin (removes all the crap that MSWord inserts)
Not sure if it's easy to merge all this to upstream, but I'll try... maybe :)

View File

@ -2,7 +2,7 @@
* NicEdit - Micro Inline WYSIWYG
* Copyright 2007-2008 Brian Kirchoff, http://nicedit.com/
* Copyright 2012-2015 Vitaliy Filippov, http://yourcmc.ru/wiki/nicEdit
* Version: 2015-07-13
* Version: 2015-08-12
*
* NicEdit is distributed under the terms of the MIT license
* Do not remove this copyright message
@ -734,7 +734,14 @@ var nicEditorPanel = bkClass.extend({
addButton : function(buttonName,options,noOrder) {
var button = options.buttons[buttonName];
var type = (button['type']) ? eval('(typeof('+button['type']+') == "undefined") ? null : '+button['type']+';') : nicEditorButton;
var type = null;
if (button['type']) {
type = typeof(window[button['type']]) == undefined ? null : window[button['type']];
}
else {
type = nicEditorButton;
}
var hasButton = bkLib.inArray(this.buttonList,buttonName);
if(type && (hasButton || this.ne.options.fullPanel)) {
this.panelButtons.push(new type(this.panelElm,buttonName,options,this.ne));

View File

@ -1,4 +1,4 @@
/** nicImageUploadGT (Image + Upload + Lightbox support) */
/** nicImageUploadGT (Image + Upload + Lightbox support) -- example image uploads integrated with wiki-like site CMS */
/* START CONFIG */
var nicImageUploadGTOptions = {

View File

@ -1,4 +1,4 @@
/** nicLink */
/** nicLinkGT -- example link insertion integrated with wiki-like site CMS */
/* START CONFIG */
var nicLinkGTOptions = {

30
nicSanitize.js Normal file
View File

@ -0,0 +1,30 @@
/** nicSanitize */
// Sanitize pasted HTML
var nicSanitize = bkClass.extend({
construct: function(nicEditor)
{
this.ne = nicEditor;
this.ne.addEvent('add', this.add.closure(this));
},
add: function(instance)
{
instance.elm.addEvent('paste', this.paste.closureListener(this));
},
paste: function(ev, target)
{
var d = ev.clipboardData || window.clipboardData;
var h = d.getData('text/html') || d.getData('Text');
if (h)
{
this.sanitizeCfg = this.sanitizeCfg || getSanitizeCfg();
h = sanitizeHtml(h, this.sanitizeCfg);
if (h)
this.ne.nicCommand('insertHTML', h);
bkLib.cancelEvent(ev);
}
}
});
nicEditors.registerPlugin(nicSanitize);

105
sanitize-html.js Normal file
View File

@ -0,0 +1,105 @@
/**
* DOM based HTML sanitizer
* License: Mozilla Public License 2.0 or later version
* (c) Vitaliy Filippov 2015+
* Version 2015-08-11
*/
(function() {
window.getSanitizeCfg = function(nest, attr)
{
// Default configuration is for sanitizing pasted html
if (!nest)
{
var inline = 'a b i strong em strike code tt sub sup br table span font';
nest = {
'hr br': '/',
'p': '#text '+inline,
'ul': 'li',
'ol': 'li',
'dl': 'dt dd',
'table': 'tr thead tbody',
'thead tbody': 'tr',
'tr': 'td th',
'* h1 h2 h3 h4 h5 h6 blockquote li dt dd pre td th': 'h1 h2 h3 h4 h5 h6 blockquote p ul ol dl pre hr #text '+inline,
'td th': '/'
};
nest[inline] = '#text '+inline;
}
if (!attr)
{
attr = {
'p': 'align',
'a': 'href name target',
'td': 'colspan rowspan',
'th': 'colspan rowspan'
};
}
var r = { nest: {}, attr: {} };
for (var k in nest)
{
var v = nest[k];
k = k.toUpperCase().split(' ');
v = v.toUpperCase().split(' ');
for (var i = 0; i < k.length; i++)
{
for (var j = 0; j < v.length; j++)
{
r.nest[k[i]] = r.nest[k[i]] || {};
r.nest[k[i]][v[j]] = true;
}
}
}
for (var k in attr)
{
var v = attr[k].split(' ');
k = k.toUpperCase();
r.attr[k] = {};
for (var i = 0; i < v.length; i++)
r.attr[k][v[i]] = true;
}
return r;
};
window.sanitizeHtml = function(html, cfg)
{
var r = document.createElement('div');
r.innerHTML = html;
sanitize(r, true, cfg);
return r.innerHTML.replace(/[ \t]*(\n[ \t]*)+/g, '\n').replace(/[ \t]{2,}/g, ' ').replace(/^\s*/, '');
};
function sanitize(el, is_root, cfg)
{
var n = is_root ? '*' : el.nodeName;
for (var i = 0; i < el.childNodes.length; i++)
{
var c = el.childNodes[i];
if (c.nodeType != 1 && c.nodeType != 3 ||
!cfg.nest[n][c.nodeType == 1 ? c.nodeName : '#TEXT'] ||
c.nodeType == 1 && !sanitize(c, false, cfg))
{
// Keep contents of generally allowed tags which are just not in place
if (c.nodeType == 1 && cfg.nest[c.nodeName])
while (c.childNodes.length)
el.insertBefore(c.childNodes[0], c);
el.removeChild(c);
i--;
}
}
if (!is_root)
{
for (var i = el.attributes.length-1; i >= 0; i--)
if (!cfg.attr[n] || !cfg.attr[n][el.attributes[i].nodeName])
el.removeAttribute(el.attributes[i].nodeName);
if (el.nodeName == 'A' && !(el.getAttribute('href') || '').match(/^https?:\/\/|^mailto:/i))
el.removeAttribute('href');
if ((el.nodeName == 'A' || el.nodeName == 'SPAN' || el.nodeName == 'FONT') && !el.attributes.length ||
el.innerHTML.match(/^\s*$/) && !cfg.nest[n]['/'])
return false;
}
return true;
}
})();