Getting a Flex RTE to group LI items properly in XML (wrapped in UL tag)
I'm trying to use XML to convert the code that a Flex RTE creates to valid HTML. N开发者_运维百科o problems on other HTML elements, but difficulty with unordered lists. I created a solution for moving consecutive LIs into a UL node. After trial and error, I came up with the following solution. Is there a better way to do this?
for each (listXML:XML in xml..li) {
if (listXML.children().length() == 0) {
// list item is empty - make it an empty paragraph instead
listXML.parent().replace( listXML.childIndex(), <p /> );
} else if (listXML.parent().children()[listXML.childIndex() - 1].name() != 'ul') {
// first LI - wrap in UL
listXML.parent().replace(listXML.childIndex(), '<ul>' + listXML.toXMLString() + '</ul>');
} else if (listXML.parent().children()[listXML.childIndex() - 1].name() == 'ul') {
// move LI into previous UL node
var lastUL:int = listXML.parent().children()[listXML.childIndex() -1].childIndex();
var parentXML:XML = listXML.parent();
delete listXML.parent().children()[listXML.childIndex()];
parentXML.children()[lastUL].appendChild(listXML);
}
}
Thanks a lot! That was exactly what I need... Worked perfectly except for:
listXML.parent().replace(listXML.childIndex(), '(ul)' + listXML.toXMLString() + '(/ul)');
Instead I used:
listXML.parent().replace(listXML.childIndex(), (ul){listXML}(/ul));
Is there a better way to do it? I first try with string regexp but didn't worked out... But yes, probably there's a better way to do it...
Anyway! it works..
精彩评论