Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Prevent nested links #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

peyerluk
Copy link
Member

@peyerluk peyerluk commented Mar 12, 2015

  • Editable should not set links if the host or a parent if the host is a link tag
  • Consider adding general rules for allowed elements

@peyerluk peyerluk self-assigned this Mar 12, 2015
@peyerluk peyerluk changed the title Prevent illegal markup Prevent nested links Mar 12, 2015
* should not be possible.
*/
canLinkBeSet: function() {
var linkParents = content.getParentsAndSelf(this.host, 'a');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peyerluk This iterates throught all parents of the dom up to the html tag.
I guess we shouldn't go further than the element in which editable.js is initialized.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcbachmann This is on purpose since nesting links should not be allowed in general. Especially in case of teasers the link tag can be outside of the editable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. It's still forbidden in HTML5 :)
It's not allowed to place interactive elements inside an <a> element:
http://www.w3.org/html/wg/drafts/html/master/single-page.html#the-a-element
http://www.w3.org/html/wg/drafts/html/master/single-page.html#interactive-content-2

@masone masone added the ready label May 23, 2016
Comment on lines +189 to +200
getParentsAndSelf: function(node, tagName) {
var parents = [];
while (node) {
if (node.nodeType === nodeType.elementNode) {
if (!tagName || node.nodeName === tagName.toUpperCase()) {
parents.push(node);
}
}
node = node.parentNode;
}
return parents;
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peyerluk, would it be possible to merge only this function if you don’t want to merge the patch below? I ask because it comes in handy in other contexts as well, e.g. avoiding <em> inside of a <strong> or others.

To address @marcbachmann’s concern perhaps a flag that stops traversal at a given node would be an agreeable compromise?

Lastly, I’d probably rename the function to getAncestorsAndSelf() to be more in line with the XPath axis ancestor-or-self.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is a bit of an odd duck currently as this is the only method that is meant to collect info outside of the host element.

It would need some polishing before we can merge it.

Would this method here help your use case? Or are you more interested in knowing which tags affect a cursor or selection within the host? For that we have the method getTags() in this file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this method here help your use case?

@peyerluk, I think I used getTagNames() from PR #198 in its stead.

@peyerluk peyerluk changed the title Prevent nested links WIP: Prevent nested links Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants