I am writing a simple WYSIWYG HTML editor using Microsoft mshtml. One of the functions should be the choice of the type of heading (for example, h1, h2, h3) for the selected text. The first assignment does not cause problems with the following code:
IHTMLTxtRange range = (IHTMLTxtRange)doc.selection.createRange()
string rangeText = range.text;
IHTMLElement elem = doc.createElement(tag)
elem.innerHTML = rangeText;
range.pasteHTML(elem.outerHTML);
When I try to change the header, the old one is not replaced, although MSDN says pasteHTML:
Inserts HTML text into the given text range, replacing any previous text and HTML elements in the range.
That means if my HTML was
<H1>foo</H1>
after the first assignment, he gets
<H1>
<H2>asdasd</H2></H1>
after the second.
What am I doing wrong? Did I miss something?
source
share