The Editor's Indent/Outdent feature is a crime against HTML, as has been discussed before
in this forum.
I'm trying to fix this myself and would like some help coming up with a solution that anyone using RadEditor can implement.
The Indent button simply wraps the selected elements in a <blockquote> tag. In most web browsers, this looks like you're indenting the text. However, those of us that respect HTML know well that the blockquote element is intended for quoting other people's text, not indenting.
To a screen reader for the blind, a search engine or any other semantic parser of HTML, using a blockquote tag has a much different meaning than indenting.
Personally, I approach indenting a section of content by wrapping it in a <div> with a margin-left style applied to it. I create a CSS class called "indent" for that purpose.
Others might add a margin-left to each element to be indented, rather than wrapping the section.
Achieving the Solution in RadEditor:
Here's where I'm stuck.
My preferred approach is to obtain an array of the DOM elements selected in the Editor. That way, I can simply add a <div> before the first element and make the selected elements children of the indention <div>.
The problem: I don't know how to retrieve an array of the selected elements. editor.getSelectedElement() gives me the last of the selected elements but there's no editor.getAllSelectedElements(). If more than one line of text is selected, editor.getSelectedElement() will not work.
Another approach is editing the HTML as a string. editor.getSelection().getHtml() gives me all the HTML that is selected in the Editor. editor.pasteHTML() puts the modified HTML back. Like approach #1, wrapping the HTML in <div> tags could achieve the desired result.
The problem: If the opening or closing <p> tag is not part of the selection (i.e. partial line selected), the resulting <div>-wrapped HTML is malformed.
This might work if I had a way to read ahead to the closing tag and read behind to the opening tag. But I haven't found an obvious way to do this.
Does anyone have any ideas on solving approach #1 or #2? How about a different approach that I haven't considered?
I appreciate your input.