Got questions, comments, patches, etc.?
Contact Jason Woofenden
gitweb
/
peach-html5-editor.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
ea5445d
)
don't encode text inside tags that don't parse that way
author
Jason Woofenden
<jason@jasonwoof.com>
Wed, 17 May 2017 05:05:05 +0000
(
01:05
-0400)
committer
Jason Woofenden
<jason@jasonwoof.com>
Wed, 17 May 2017 05:05:05 +0000
(
01:05
-0400)
editor.js
patch
|
blob
|
history
diff --git
a/editor.js
b/editor.js
index
564befc
..
1a408ba
100644
(file)
--- a/
editor.js
+++ b/
editor.js
@@
-254,6
+254,7
@@
function enc_text (txt) {
})
}
})
}
+// no closing tag, cannot have children
void_elements = {
area: true,
base: true,
void_elements = {
area: true,
base: true,
@@
-272,6
+273,18
@@
void_elements = {
wbr: true
}
wbr: true
}
+// contents are not html encoded
+plaintext_elements = {
+ style: true,
+ script: true,
+ xmp: true,
+ iframe: true,
+ noembed: true,
+ noframes: true,
+ plaintext: true,
+ noscript: true
+}
+
// this does not pretty-print
function nodes_to_html (tree) {
var attr_keys, i, k, n, ret
// this does not pretty-print
function nodes_to_html (tree) {
var attr_keys, i, k, n, ret
@@
-297,7
+310,11
@@
function nodes_to_html (tree) {
}
break
case 'text':
}
break
case 'text':
- ret += enc_text(n.text)
+ if (n.parent != null ? plaintext_elements[n.parent.name] : false) {
+ ret += n.text
+ } else {
+ ret += enc_text(n.text)
+ }
break
case 'comment':
ret += "<!--" + n.text + "-->" // TODO encode?
break
case 'comment':
ret += "<!--" + n.text + "-->" // TODO encode?
@@
-771,6
+788,7
@@
function PeachHTML5Editor (in_el, options) {
// on_init: callback for when the editable content is in place
var css, opt_fragment, outer_bounds, outer_iframe_style, outer_wrap
this.options = options != null ? options : {}
// on_init: callback for when the editable content is in place
var css, opt_fragment, outer_bounds, outer_iframe_style, outer_wrap
this.options = options != null ? options : {}
+ this.pretty_print = options.pretty_print != null ? options.pretty_print : true
this.in_el = in_el
this.tree = null // array of Nodes, all editable content
this.tree_parent = null // this.tree is this.children. .el might === this.idoc.body
this.in_el = in_el
this.tree = null // array of Nodes, all editable content
this.tree_parent = null // this.tree is this.children. .el might === this.idoc.body
@@
-1676,8
+1694,11
@@
PeachHTML5Editor.prototype.load_html = function(html) {
}
PeachHTML5Editor.prototype.changed = function() {
this.in_el.onchange = null
}
PeachHTML5Editor.prototype.changed = function() {
this.in_el.onchange = null
- this.in_el.value = this.pretty_html(this.tree)
- // TODO make option for not pretty-printing: nodes_to_html(tree)
+ if (this.pretty_print) {
+ this.in_el.value = this.pretty_html(this.tree)
+ } else {
+ this.in_el.value = nodes_to_html(this.tree)
+ }
this.in_el.onchange = (function(_this) { return function() {
return _this.load_html(_this.in_el.value)
}})(this)
this.in_el.onchange = (function(_this) { return function() {
return _this.load_html(_this.in_el.value)
}})(this)
@@
-2468,7
+2489,11
@@
PeachHTML5Editor.prototype.pretty_html = function(tree, indent, parent_flags) {
}
break
case 'text':
}
break
case 'text':
- ret += enc_text(n.text)
+ if (n.parent != null ? plaintext_elements[n.parent.name] : false) {
+ ret += n.text
+ } else {
+ ret += enc_text(n.text)
+ }
break
case 'comment':
ret += "<!--" + n.text + "-->" // TODO encode?
break
case 'comment':
ret += "<!--" + n.text + "-->" // TODO encode?