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:
4499a63
)
code cleanup (just renames)
author
Jason Woofenden
<jason@jasonwoof.com>
Wed, 9 Mar 2016 07:29:18 +0000
(
02:29
-0500)
committer
Jason Woofenden
<jason@jasonwoof.com>
Wed, 9 Mar 2016 07:29:18 +0000
(
02:29
-0500)
editor.coffee
patch
|
blob
|
history
diff --git
a/editor.coffee
b/editor.coffee
index
494108e
..
d885b7d
100644
(file)
--- a/
editor.coffee
+++ b/
editor.coffee
@@
-163,61
+163,61
@@
no_text_elements = { # these elements never contain text
tbody: true
}
# FIXME terminology: s/dom/tree/; s/el/n/
tbody: true
}
# FIXME terminology: s/dom/tree/; s/el/n/
-dom_to_html = (dom, indent = '', parent_is_block = false) ->
+tree_to_html = (tree, indent = '', parent_is_block = false) ->
ret = ''
ret = ''
- for el, i in dom
- switch el.type
+ for n, i in tree
+ switch n.type
when TYPE_TAG
when TYPE_TAG
- is_block = is_display_block el.el
+ is_block = is_display_block n.el
if is_block
is_tiny_block = false
if is_block
is_tiny_block = false
- if is_whitespace_significant el
+ if is_whitespace_significant n
is_tiny_block = true
else
is_tiny_block = true
else
- if el.children.length is 1
- if el.children[0].type is TYPE_TEXT
- if el.children[0].text.length < 35
+ if n.children.length is 1
+ if n.children[0].type is TYPE_TEXT
+ if n.children[0].text.length < 35
is_tiny_block = true
if is_block or (parent_is_block and i is 0)
ret += indent
is_tiny_block = true
if is_block or (parent_is_block and i is 0)
ret += indent
- ret += '<' + el.name
+ ret += '<' + n.name
attr_keys = []
attr_keys = []
- for k of el.attrs
+ for k of n.attrs
attr_keys.unshift k
#attr_keys.sort()
for k in attr_keys
ret += " #{k}"
attr_keys.unshift k
#attr_keys.sort()
for k in attr_keys
ret += " #{k}"
- if el.attrs[k].length > 0
- ret += "=\"#{enc_attr el.attrs[k]}\""
+ if n.attrs[k].length > 0
+ ret += "=\"#{enc_attr n.attrs[k]}\""
ret += '>'
ret += '>'
- unless void_elements[el.name]?
+ unless void_elements[n.name]?
if is_block
next_indent = indent + ' '
else
next_indent = indent
if is_block
next_indent = indent + ' '
else
next_indent = indent
- if el.children.length
+ if n.children.length
if is_block and not is_tiny_block
ret += "\n"
if is_block and not is_tiny_block
ret += "\n"
- ret += dom_to_html el.children, next_indent, is_block and not is_tiny_block
+ ret += tree_to_html n.children, next_indent, is_block and not is_tiny_block
if is_block and not is_tiny_block
ret += indent
if is_block and not is_tiny_block
ret += indent
- ret += "</#{el.name}>"
- if is_block or (parent_is_block and i is dom.length - 1)
+ ret += "</#{n.name}>"
+ if is_block or (parent_is_block and i is tree.length - 1)
ret += "\n"
when TYPE_TEXT
if parent_is_block and i is 0
ret += indent
ret += "\n"
when TYPE_TEXT
if parent_is_block and i is 0
ret += indent
- ret += enc_text el.text
- if parent_is_block and i is dom.length - 1
+ ret += enc_text n.text
+ if parent_is_block and i is tree.length - 1
ret += "\n"
when TYPE_COMMENT
ret += "\n"
when TYPE_COMMENT
- ret += "<!--#{el.text}-->"
+ ret += "<!--#{n.text}-->"
when TYPE_DOCTYPE
when TYPE_DOCTYPE
- ret += "<!DOCTYPE #{el.name}"
- if el.public_identifier? and el.public_identifier.length > 0
- ret += " \"#{el.public_identifier}\""
- if el.system_identifier? and el.system_identifier.length > 0
- ret += " \"#{el.system_identifier}\""
+ ret += "<!DOCTYPE #{n.name}"
+ if n.public_identifier? and n.public_identifier.length > 0
+ ret += " \"#{n.public_identifier}\""
+ if n.system_identifier? and n.system_identifier.length > 0
+ ret += " \"#{n.system_identifier}\""
ret += ">\n"
return ret
ret += ">\n"
return ret
@@
-812,7
+812,7
@@
class PeachHTML5Editor
@changed()
changed: ->
@in_el.onchange = null
@changed()
changed: ->
@in_el.onchange = null
- @in_el.value = dom_to_html @tree
+ @in_el.value = tree_to_html @tree
@in_el.onchange = =>
@load_html @in_el.value
@iframe.style.height = "0"
@in_el.onchange = =>
@load_html @in_el.value
@iframe.style.height = "0"