我正在使用summenote,最近我在summernote中应用了代码,将<b>
和<i>
之类的标签更改为<strong>
和<em>
,该代码运行得很好,但是我开始遇到一个问题,现在每当我按下bold
和italics
的热键时,键入光标就会再次回到第一行。
下面是我用来转换标签的代码:
function clean_html(editor, type, value)
{
if (value.indexOf("<"+type+">") >= 0)
{
if(type == "b")
{
marca = /<b(?:.*?)>(?:.*?)<\/b>/g;
replaceIniTag = "<strong>";
replaceEndTag = "</strong>";
}
else
{
marca = /<i(?:.*?)>(?:.*?)<\/i>/g;
replaceIniTag = "<em>";
replaceEndTag = "</em>";
}
var matches = value.match(marca),
len = matches.length,
i;
for (i = 0; i < len; i++)
{
str = $(matches[i]).text();
str = replaceIniTag+str+replaceEndTag;
value = value.replace(matches[i], str);
}
$('#post_content').summernote('code', value); //Replace the editor content
}
}
下面是我在初始化summernote时使用的代码。
$('#post_content').summernote(
{
height: 200,
focus: false,
disableDragAndDrop: true,
popover: {
image: [],
link: [],
air: []
},
// disableResizeEditor: true,
placeholder: "Type Your Post Content...",
toolbar: [
['cleaner',['cleaner']], // The Button
['style', ['style']],
// ['style', ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript', 'clear']],
['style', ['bold', 'italic', 'underline', 'strikethrough', 'superscript', 'subscript']],
// ['fontname', ['fontname']],
['fontsize', ['fontsize']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']],
['table', ['table']],
['insert', ['link', 'hr']],
// ['insert', ['link', 'picture', 'video', 'hr', 'readmore']],
['view', ['fullscreen', 'codeview']]
// ['help', ['help']]
],
cleaner:{
action: 'both', // both|button|paste 'button' only cleans via toolbar button, 'paste' only clean when pasting content, both does both options.
newline: '<br>', // Summernote's default is to use '<p><br></p>'
notStyle: 'position:absolute;top:0;left:0;right:0', // Position of Notification
icon: '<i class="note-icon-row-remove"></i>',
keepHtml: false, // Remove all Html formats
keepOnlyTags: ['<p>', '<br>', '<ul>', '<li>', '<b>', '<strong>','<i>', '<a>'], // If keepHtml is true, remove all tags except these
keepClasses: false, // Remove Classes
badTags: ['style', 'script', 'applet', 'embed', 'noframes', 'noscript', 'html'], // Remove full tags with contents
badAttributes: ['style', 'start'], // Remove attributes from remaining tags
limitChars: false, // 0/false|# 0/false disables option
limitDisplay: 'both', // text|html|both
limitStop: false // true/false
},
callbacks:
{
onPaste: function (e)
{
var thisNote = $(this);
var updatePastedText = function(someNote)
{
var original = someNote.code();
var cleaned = CleanPastedHTML(original); //this is where to call whatever clean function you want. I have mine in a different file, called CleanPastedHTML.
someNote.code('').html(cleaned); //this sets the displayed content editor to the cleaned pasted code.
};
setTimeout(function ()
{
//this kinda sucks, but if you don't do a setTimeout,
//the function is called before the text is really pasted.
updatePastedText(thisNote);
}, 10);
},
onChange: function(contents, $editable)
{
clean_html(this, "b", contents);
clean_html(this, "i", contents);
}
}
});
任何人都可以让我知道这是什么触发条件吗?