Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Do not insert BR in empty inline elements when parent node contains text #258

Merged
merged 3 commits into from
Oct 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "scribe",
"dependencies": {
"lodash-amd": "2.4.1",
"scribe-common": "0.0.4"
"scribe-common": "0.0.11"
},
"devDependencies": {
"requirejs": "~2.1.9",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "src/scribe.js",
"dependencies": {
"lodash-amd": "~2.4.1",
"scribe-common": "~0.0.4"
"scribe-common": "~0.0.11"
},
"devDependencies": {
"chai": "~1.9.1",
Expand Down
24 changes: 21 additions & 3 deletions src/plugins/core/formatters/html/ensure-selectable-containers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,34 @@ define([
// http://www.w3.org/TR/html-markup/syntax.html#syntax-elements
var html5VoidElements = ['AREA', 'BASE', 'BR', 'COL', 'COMMAND', 'EMBED', 'HR', 'IMG', 'INPUT', 'KEYGEN', 'LINK', 'META', 'PARAM', 'SOURCE', 'TRACK', 'WBR'];

function parentHasNoTextContent(node) {
if (element.isCaretPositionNode(node)) {
return true;
} else {
return node.parentNode.textContent.trim() === '';
}
}


function traverse(parentNode) {
// Instead of TreeWalker, which gets confused when the BR is added to the dom,
// we recursively traverse the tree to look for an empty node that can have childNodes

var node = parentNode.firstElementChild;

function isEmpty(node) {
return node.children.length === 0
|| (node.children.length === 1
&& element.isSelectionMarkerNode(node.children[0]));

if ((node.children.length === 0 && element.isBlockElement(node))
|| (node.children.length === 1 && element.isSelectionMarkerNode(node.children[0]))) {
return true;
}

// Do not insert BR in empty non block elements with parent containing text
if (!element.isBlockElement(node) && node.children.length === 0) {
return parentHasNoTextContent(node);
}

return false;
}

while (node) {
Expand Down