[webkit-help] How to use DOMRange to select a paragraph's outer HTML?

Alexander Shulgin alexander.shulgin at yessoftware.com
Tue May 18 06:23:34 PDT 2010


On 17.05.2010 20:00, Alexander Shulgin wrote:
> Hi,
>
> I'm new to the list, so hope this is the right place for my question.
> Feel free to redirect me to more appropriate one if it's not.
>
> In the content editing mode is there a way to programmatically select
> _outer_ representation of a HTML tag, e.g.<p>, so that when we call one
> of the replaceSelectionWith*() methods, the selected tag is replaced as
> a whole?
>
> I'm trying to use setSelectedDOMRange() like this:
>
> DOMRange* range = ...;
> range->setStartBefore(paragraphToReplace);
> range->setEndAfter(paragraphToReplace);
>
> webView->replaceSelectionWithNode(replacementParagraph);
>
> But this has unpleasant side effects: any adjacent tags are merged into
> the newly inserted paragraph.  And this can be quite annoying as it
> would happily convert any adjacent<h1>  into<span>, while preserving
> the look, but not semantics of HTML.

Just noted I didn't say why I need this to work.  I'm trying to replace 
HTML like this:

<p>Text text text.</p>

with this:

<p style="padding-left: 20px">Text text text.</p>

_and_ I need undo to work, so the only way seems to be using 
replaceSelectionWith*() methods.

Hope this clarifies my problem a bit.

--
Regards,
Alex


More information about the webkit-help mailing list