Leanote BUG 修复 2014-12-25 (Ace代码编辑器, 历史记录)
? leanote bug ? ? bug ? ? leanote ?    2014-12-26 07:56:12    959    1    3
  1. ace editor 乱码问题还存在, 不允许tinymce修改ace [ok]
  2. ace下html标签刷新会消失 [ok]
  3. 历史记录问题 有10份之后, 就不允许再添加了 [ok], 紧急!!

1. ace editor 乱码

因为tinymce对html结构进行了validate, 认为在pre下有div是不合法的, 让它变成合法即可!

tinymce源码: Editor.js中setContent()会先将内容过滤

/**
 * Schema instance, enables you to validate elements and it's children.
 *
 * @property schema
 * @type tinymce.html.Schema
 */
self.schema = new Schema(settings);

/**
 * This class parses HTML code into a DOM like structure of nodes 
 * it will remove redundant whitespace and make
 * sure that the node tree is valid according to the specified schema.
 * @example
 * var parser = new tinymce.html.DomParser({validate: true}, schema);
 * var rootNode = parser.parse('content');
 */
self.parser = new DomParser(settings, self.schema);

self.serializer = new DomSerializer(settings, self);

// Editor.js
// Serializer == html/Serializer
setContent: function() {
    if (args.format !== 'raw') {
		content = new Serializer({}, self.schema).serialize(
			self.parser.parse(content, {isRootContent: true})
		);
	}
}

serlf.parser.parse()会把变成"<pre><div>xx</div></pre>"变成"<div>xx</div>"

解决: page.js, 使pre下可以存在div这种元素

http://www.tinymce.com/wiki.php/Configuration:valid_children

// 初始化编辑器
tinymce.init({
	inline: true,
	valid_children: "+pre[div|#text|p|span|textarea|i|b|strong]", // ace
	...
});

 2. ace下html标签刷新会消失

<pre>下的<div><span>...都存实体, 所以在getEditoContent(), aceToPre()< 转成 &lt;    

value.replace(/</g, '<').replace(/>/g, '>');

setEditorContent()时也要转成实体(因为历史的<pre>值都没转)

LeaAce:initAceFromContent() {
    ...
    value = value.replace(/ /g, " ").replace(/\<br *\/*\>/gi,"\n").replace(/</g, '<').replace(/>/g, '>');
    pre.html(value);
    var id = pre.attr('id');
    if(!id) {
    	id = me.getAceId();
    	pre.attr('id', id);
    }
    me.initAce(id);
    ...

3. 一个很低级的错误

func (this *NoteContentHistoryService) AddHistory(noteId, userId string, eachHistory info.EachHistory) {
    ...
        if l >= maxSize {
			// history.Histories = history.Histories[l-maxSize:] // BUG, 致使都是以前的
			history.Histories = history.Histories[:maxSize]
		}
	...
}

上一篇: Tinymce 集成 Ace 编辑器

下一篇: Leanote 新博客主题

959 人读过
立即登录, 发表评论.
没有帐号? 立即注册
3 条评论