Skip to content

Commit 096d19d

Browse files
committed
Additional fixes for HTML.
1 parent 8824690 commit 096d19d

File tree

6 files changed

+62
-26
lines changed

6 files changed

+62
-26
lines changed

build/content-tools.js

Lines changed: 27 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/content-tools.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/content-tools.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ContentTools",
33
"description": "A JS library for building WYSIWYG editors for HTML content",
4-
"version": "1.6.3",
4+
"version": "1.6.4",
55
"keywords": [
66
"wysiwyg",
77
"inline",

src/scripts/editor.coffee

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,24 @@ class _EditorApp extends ContentTools.ComponentUI
358358
wrapper = sandbox.createElement('div')
359359
wrapper.innerHTML = ContentTools.getHTMLCleaner().clean(content.trim())
360360

361-
# Remove any undefined nodes
362-
childNodes = (n for n in wrapper.childNodes when n)
361+
# Remove any undefined nodes or empty #text nodes
362+
childNodes = []
363+
for childNode in wrapper.childNodes
364+
unless childNode
365+
continue
366+
367+
if childNode.nodeName.toLowerCase() == '#text'
368+
if childNode.textContent.trim() == ''
369+
continue
370+
371+
childNodes.push(childNode)
372+
363373
unless childNodes.length
364374
return
365375

366376
# Paste the HTML
367-
inlineTags = ContentTools.INLINE_TAGS
377+
inlineTags = ContentTools.INLINE_TAGS.slice()
378+
inlineTags.push('#text')
368379
firstNode = childNodes[0].nodeName.toLowerCase()
369380
lastNode = childNodes[childNodes.length - 1].nodeName.toLowerCase()
370381

@@ -391,7 +402,10 @@ class _EditorApp extends ContentTools.ComponentUI
391402
content = new HTMLString.String(wrapper.innerHTML)
392403

393404
else
394-
content = new HTMLString.String(wrapper.textContent)
405+
console.log wrapper.textContent
406+
content = new HTMLString.String(
407+
HTMLString.String.encode(wrapper.textContent)
408+
)
395409

396410
# Check we can paste in to the selected element
397411
if element.content
@@ -445,6 +459,17 @@ class _EditorApp extends ContentTools.ComponentUI
445459

446460
region = element.parent()
447461

462+
# If the content starts and ends with an inline tag then we need to
463+
# wrap it within a paragraph tag before inserting.
464+
465+
if (inlineTags.indexOf(firstNode) > -1 and
466+
inlineTags.indexOf(lastNode) > -1)
467+
468+
innerP = wrapper.createElement('p')
469+
while wrapper.childNodes.length > 0
470+
innerP.appendChild(wrapper.childNodes[0])
471+
wrapper.appendChild(innerP)
472+
448473
i = 0
449474
newElement = originalElement
450475
for node in wrapper.childNodes

src/scripts/styles.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ContentTools.StylePalette
1616
# If no element is specified return a copy of the stlyes list
1717
if element is undefined
1818
return @_styles.slice()
19-
19+
2020
# Return the styles (optional only those applicable for the specified
2121
# tag name).
2222
tagName = element.tagName()

0 commit comments

Comments
 (0)