Re: Insert a span tag
Posted by:
Tim Bushell (---.range86-145.btcentralplus.com)
Date: Thursday, 07-Dec-2006, 15:19:58
Thanks for taking a look at this Tim.
"This is inherently quite tricky. " That's good to hear! I'm not a complete idiot then... LOL.
"I think you could successfully remove the existing span in the case you cite" Really? How? This is my SelectedHTML property which I adapted from the HTMLeditor adaption by Darwin. I haven't gone so far as add it to the original HTML control source, but have simply pointed it to my HTMLEditor control called "scoaObjectEditor"
Public Property SelectedHTML() As String
Get
If CType(Me.scoaObjectEditor.HtmlDocument2, HTMLAPI.IHTMLDocument2).Selection Is Nothing Then
Return String.Empty
End If
Dim tr As HTMLAPI.IHTMLTxtRange = CType(CType(Me.scoaObjectEditor.HtmlDocument2, HTMLAPI.IHTMLDocument2).Selection.CreateRange(), HTMLAPI.IHTMLTxtRange)
Return tr.HTMLText
End Get
Set(ByVal value As String)
If CType(Me.scoaObjectEditor.HtmlDocument2, HTMLAPI.IHTMLDocument2).Selection Is Nothing Then
Return
End If
Dim tr As HTMLAPI.IHTMLTxtRange = CType(CType(Me.scoaObjectEditor.HtmlDocument2, HTMLAPI.IHTMLDocument2).Selection.CreateRange(), HTMLAPI.IHTMLTxtRange)
Dim theString As String = value
'If it's full html, strip out the body only.
Dim Pos As Integer = theString.ToUpper().IndexOf("<BODY")
If Pos > -1 Then
Pos = theString.ToUpper().IndexOf(">", Pos)
If Pos > -1 Then
theString = theString.Substring((Pos + 1))
Pos = theString.ToUpper().IndexOf("</BODY")
If Pos > -1 Then
theString = theString.Substring(0, Pos)
End If
End If
End If
Dim markup As HTMLAPI.IMarkupServices = CType(Me.scoaObjectEditor.HtmlDocument2, HTMLAPI.IMarkupServices)
Dim pStart As HTMLAPI.IMarkupPointer = Nothing
Dim pEnd As HTMLAPI.IMarkupPointer = Nothing
markup.CreateMarkupPointer(pStart)
markup.CreateMarkupPointer(pEnd)
markup.MovePointersToRange(tr, pStart, pEnd)
'int BodyLength = ConvertEx.ToString(Body).Length;
tr.PasteHTML(value)
markup.MoveRangeToPointers(pStart, pEnd, tr)
tr.Select()
End Set
End Property
What's perhaps going wrong here is that the Get and Set parts of this property are not interdependant - not, at least in the same way the private member of an Integer property would be.
Therefore selectedHTML = Replace(selectedHTML , "x", "y") does weird things because the SET part does not relate directly to the GET part in the Replace function. But I'm clueless as to what the particular issue is.
##########
"there are more complex possibilities " I agree. However those I can handle. All the HTML is heavily processed in order to meet the HTML requirements of the engine (the Flash developers have specified a small subset of HTML). Therefore I can clean any poor HTML during that process. In fact I could clean the double SPAN problem at this point too. My problem is that unless I can override the existing SPAN tag during the editing stage I will lose WYSIWYG, so the user won't see the colour changes, etc because the inner SPAN i wanted to replace the outer SPAN with overrides the formatting.
One idea I did have was to extract the
a) Store the selectedHTML as a string *
b) Store the GetDocumentSource as a string
c) Replace the selectedHTML in GetDocumentSource with the required span class *
b) Reload the document from amended GetDocumentSource.
Not pretty and *I'm going to have to find a way to "unique-e-fy" the selectedHTML first in case another string in the entire document shares the same pattern.
Would there be another way to handle tackle this problem?