Skip to content

Commit 6d0d6e5

Browse files
committed
- Fixes #463, now possible to paste HTML into fixtures.
- Additional improvements to HTML C&P support with improved cleansing of deeper structures.
1 parent a356be7 commit 6d0d6e5

File tree

6 files changed

+70
-21
lines changed

6 files changed

+70
-21
lines changed

build/content-tools.js

Lines changed: 29 additions & 13 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.1",
4+
"version": "1.6.2",
55
"keywords": [
66
"wysiwyg",
77
"inline",

src/scripts/clean-html.coffee

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,19 @@ class ContentTools.HTMLCleaner
6969
nodeName = node.nodeName.toLowerCase()
7070

7171
# Remove any non-whitelisted tags
72+
console.log '----'
7273
if @tagWhitelist.indexOf(nodeName) < 0
74+
75+
# Add the children of the tag to the stack to be processed
76+
for childNode in node.childNodes
77+
unless childNode
78+
continue
79+
80+
childNode = childNode.cloneNode(true)
81+
node.parentNode.insertBefore(childNode, node)
82+
stack.push(childNode)
83+
84+
console.log nodeName, node.innerHTML
7385
node.remove()
7486
continue
7587

src/scripts/editor.coffee

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,31 @@ class _EditorApp extends ContentTools.ComponentUI
367367
inlineTags = ContentTools.INLINE_TAGS
368368
firstNode = childNodes[0].nodeName.toLowerCase()
369369
lastNode = childNodes[childNodes.length - 1].nodeName.toLowerCase()
370-
if inlineTags.indexOf(firstNode) > -1 and
371-
inlineTags.indexOf(lastNode) > -1
372370

373-
content = new HTMLString.String(wrapper.innerHTML)
371+
# Cater for a single line of HTML being pasted, or pasting into a
372+
# fixture.
373+
if element.isFixed() or (inlineTags.indexOf(firstNode) > -1 and
374+
inlineTags.indexOf(lastNode) > -1)
375+
376+
# If we merging multiple block level elements into one we strip
377+
# HTML before doing so.
378+
#
379+
# HACK: This isn't the long term plan, where we're resolving here
380+
# is an issue where pasting multiple paragraphs into a fixture
381+
# causes issues because fixtures typically don't cater for block
382+
# level elements as children. Long term this needs to be improved
383+
# to cater for merging the text elements within to produce a
384+
# single text element (retaining the HTML tags) that can be pasted
385+
# into the fixture.
386+
#
387+
# ~ Anthony Blackshaw <[email protected]>, 7 Jan 2018
388+
#
389+
if (inlineTags.indexOf(firstNode) > -1 and
390+
inlineTags.indexOf(lastNode) > -1)
391+
content = new HTMLString.String(wrapper.innerHTML)
392+
393+
else
394+
content = new HTMLString.String(wrapper.textContent)
374395

375396
# Check we can paste in to the selected element
376397
if element.content

0 commit comments

Comments
 (0)