I just got an idea:
I want my users to be able to heavily "mark up" their text by inserting various [spans] with unique id's and classes. I've created a plugin that hooks into the STYLE system and applies uniqly id'ed spans to the selected text.
But I've found that CKEDITOR doesn't take care of all the nasty nesting issues that I wish it did: if I put a [span] inside another [span], they will be improperly nested -- here I put span2 inside of span1:
<span id=1>text text <span id=2>text text</span>(ambiguous closing) text text </span>(ambiguous closing)
It should look like this:
<span id=1>text text </span>(close span1) <span id=2>text text</span>(close span2) <span id=1>text text</span>(close span1)
I thought CKEDITOR would handle this, but it seems to get messed up by the fact that the span's are the same element, even though they have unique id's.
My thought is: why not create custom elements, so that each unique id becomes a unique element as well? Like this:
<span1>text text <span2>text text</span2> text text</span1>
There's no ambiguity in the closing tags since they are unique.
I know that I need some JS magic to make custom elements work in older IE. Is there any other reason not to do this? It seems like it'll solve a lot of problems...?
In HTML span element of
In HTML span element of course may contain another spans, so that's why CKEditor fixes your HTML this way. You would need to implement special parsing rules to differentiate spans based on their ids and that's rather undoable.
I read about many people using custom elements, but I know that there are problems with them. First of all, you need to extend CKEditor's DTD object. That will guarantee that CKEditor's parser understands them. Second thing is extending Advanced Content Filter configuration. Third this is enabling this custom elements in older browsers (see e.g. the code that starts here: https://github.com/ckeditor/ckeditor-dev/blob/major/core/dom/element.js#L423-L432). And then everything is in browsers' hands :).
Piotrek (Reinmar) Koszuliński
CKEditor JavaScript Developer
--
CKSource - http://cksource.com
--
Follow CKEditor on: Twitter | Facebook | Google+
Thanks so much for this! I
Thanks so much for this! I seriously appreciate it. I have a question:
You say "span element of course may contain another spans" but then how do we disambiguate the nested spans as they close? How do we know where the outer-span closes and where the inner-span closes? Is it "last-in, first-out?" So CKEDITOR handles the case ovf overlapping (not just nesting) spans?
AFAIK CKEditor closes element
AFAIK CKEditor closes element when it encounters a new element or parent closing tag, so the element is cannot be continued. So in the last possible place.
Piotrek (Reinmar) Koszuliński
CKEditor JavaScript Developer
--
CKSource - http://cksource.com
--
Follow CKEditor on: Twitter | Facebook | Google+