<?xml version="1.0" encoding="iso-8859-1" ?>
<rss version="2.0">
  <channel>
    <title>HtmlEditor</title>
    <link>http://www.itwriting.com/phorum/list.php?3</link>
    <description><![CDATA[For discussion of the .Net HTMLEditor control]]></description>
    <language>EN</language>
    <pubDate>Mon, 22 Jun 2009 08:55:53 +0100</pubDate>
    <lastBuildDate>Mon, 22 Jun 2009 08:55:53 +0100</lastBuildDate>
    <category>HtmlEditor</category>
    <generator>Phorum 5.1.25</generator>
    <ttl>60</ttl>
    <item>
      <title>Re: Insert a span tag</title>
      <link>http://www.itwriting.com/phorum/read.php?3,3436,4242#msg-4242</link>
      <author>gdminal</author>
      <description><![CDATA[]]></description>
      <category>HtmlEditor</category>
      <guid isPermaLink="true">http://www.itwriting.com/phorum/read.php?3,3436,4242#msg-4242</guid>
      <pubDate>Mon, 22 Jun 2009 08:55:53 +0100</pubDate>
    </item>
    <item>
      <title>Re: Insert a span tag</title>
      <link>http://www.itwriting.com/phorum/read.php?3,3436,3450#msg-3450</link>
      <author>Tim Bushell</author>
      <description><![CDATA[Thanks for taking a look at this Tim.<br />
<br />
&quot;This is inherently quite tricky. &quot; That's good to hear! I'm not a complete idiot then... LOL.<br />
<br />
<br />
&quot;I think you could successfully remove the existing span in the case you cite&quot; 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 &quot;scoaObjectEditor&quot;<br />
<br />
<br />
<br />
  Public Property SelectedHTML() As String<br />
    Get<br />
      If CType(Me.scoaObjectEditor.HtmlDocument2, HTMLAPI.IHTMLDocument2).Selection Is Nothing Then<br />
        Return String.Empty<br />
      End If<br />
      Dim tr As HTMLAPI.IHTMLTxtRange = CType(CType(Me.scoaObjectEditor.HtmlDocument2, HTMLAPI.IHTMLDocument2).Selection.CreateRange(), HTMLAPI.IHTMLTxtRange)<br />
<br />
<br />
      Return tr.HTMLText<br />
    End Get<br />
    Set(ByVal value As String)<br />
<br />
      If CType(Me.scoaObjectEditor.HtmlDocument2, HTMLAPI.IHTMLDocument2).Selection Is Nothing Then<br />
        Return<br />
      End If<br />
      Dim tr As HTMLAPI.IHTMLTxtRange = CType(CType(Me.scoaObjectEditor.HtmlDocument2, HTMLAPI.IHTMLDocument2).Selection.CreateRange(), HTMLAPI.IHTMLTxtRange)<br />
<br />
      Dim theString As String = value<br />
<br />
      'If it's full html, strip out the body only.<br />
      Dim Pos As Integer = theString.ToUpper().IndexOf(&quot;&lt;BODY&quot;)<br />
      If Pos &gt; -1 Then<br />
        Pos = theString.ToUpper().IndexOf(&quot;&gt;&quot;, Pos)<br />
<br />
        If Pos &gt; -1 Then<br />
          theString = theString.Substring((Pos + 1))<br />
<br />
          Pos = theString.ToUpper().IndexOf(&quot;&lt;/BODY&quot;)<br />
<br />
          If Pos &gt; -1 Then<br />
            theString = theString.Substring(0, Pos)<br />
          End If<br />
        End If<br />
      End If<br />
<br />
      Dim markup As HTMLAPI.IMarkupServices = CType(Me.scoaObjectEditor.HtmlDocument2, HTMLAPI.IMarkupServices)<br />
      Dim pStart As HTMLAPI.IMarkupPointer = Nothing<br />
      Dim pEnd As HTMLAPI.IMarkupPointer = Nothing<br />
      markup.CreateMarkupPointer(pStart)<br />
      markup.CreateMarkupPointer(pEnd)<br />
      markup.MovePointersToRange(tr, pStart, pEnd)<br />
<br />
      'int BodyLength = ConvertEx.ToString(Body).Length;<br />
      tr.PasteHTML(value)<br />
<br />
<br />
      markup.MoveRangeToPointers(pStart, pEnd, tr)<br />
      tr.Select()<br />
    End Set<br />
  End Property<br />
<br />
<br />
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. <br />
<br />
Therefore  selectedHTML = Replace(selectedHTML , &quot;x&quot;, &quot;y&quot;) 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.<br />
<br />
##########<br />
<br />
&quot;there are more complex possibilities &quot;  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.<br />
<br />
One idea I did have was to extract the <br />
a) Store the selectedHTML as a string *<br />
b) Store the GetDocumentSource as a string<br />
c) Replace the selectedHTML in GetDocumentSource with the required span class *<br />
b) Reload the document from amended GetDocumentSource.<br />
<br />
Not pretty and *I'm going to have to find a way to &quot;unique-e-fy&quot; the selectedHTML first in case another string in the entire document shares the same pattern.<br />
<br />
Would there be another way to handle tackle this problem?]]></description>
      <category>HtmlEditor</category>
      <guid isPermaLink="true">http://www.itwriting.com/phorum/read.php?3,3436,3450#msg-3450</guid>
      <pubDate>Thu, 07 Dec 2006 15:19:58 +0000</pubDate>
    </item>
    <item>
      <title>Re: Insert a span tag</title>
      <link>http://www.itwriting.com/phorum/read.php?3,3436,3437#msg-3437</link>
      <author>Tim</author>
      <description><![CDATA[This is inherently quite tricky. Nested spans are legitimate HTML. I think you could successfully remove the existing span in the case you cite, but there are more complex possibilities - eg. the user selects only part of an existing span, or even worse starts the selection within one span and ends in another (if you then wrap a span round the selection it will NOT be valid).<br />
<br />
Tim]]></description>
      <category>HtmlEditor</category>
      <guid isPermaLink="true">http://www.itwriting.com/phorum/read.php?3,3436,3437#msg-3437</guid>
      <pubDate>Thu, 30 Nov 2006 09:12:04 +0000</pubDate>
    </item>
    <item>
      <title>Insert a span tag</title>
      <link>http://www.itwriting.com/phorum/read.php?3,3436,3436#msg-3436</link>
      <author>Tim Bushell</author>
      <description><![CDATA[Hello<br />
<br />
Firstly, thanks, it's a great control that has made my project so much easier.<br />
<br />
I have a question which I know has been asked before, but I've not been able to solve the problem from any of the hints provided.<br />
<br />
Anyway, what I want to accomplish is fairly simple. My project's resulting HTML - as edited by the control - is going to be rendered by a Flash engine and there is a requirement for span tags defining classes. So I simply want to take the SelectedText (which I have been able to get from other code on this site), and wrap it inside a &quot;&lt;span class=&quot;classname&quot;&gt;&quot; tag. <br />
<br />
Unfortunately this causes a problem because, whilst initially working with the selected piece of text (when it doesn't have HTML already), if I then select for a different class on that text then my HTMLEditor simply wraps the new span around the existing span. <br />
<br />
I thought perhaps I could capture the selectedText and fix it like this (forgive the VB, CS people)<br />
<br />
###########################<br />
Dim fix As String = MyEditor.SelectedHTML  <br />
'//fix = &lt;span class=&quot;ONE&quot;&gt;Hello&lt;/span&gt;<br />
<br />
fix = FunctionToRemoveExistingSpans(fix)<br />
'//fix = Hello<br />
<br />
MyEditor.SelectedHTML  = &quot;&lt;span class=&quot;TWO&quot;&gt; &amp; fix &amp; &quot;&lt;/span&gt;&quot;<br />
################################<br />
<br />
Code logically looks fine when you read it, but I'm left with the following HTML <br />
&lt;span class=&quot;TWO&quot;&gt;&lt;span class=&quot;ONE&quot;&gt;Hello&lt;/span&gt;&lt;span&gt;&quot;<br />
<br />
Now I'm not necessarily after a fix for this problem. if there is any other method I could use to add my span tag, then I'm not fussy!<br />
<br />
Hope someone can point me in the right direction (or carry me over the line - again I'm not fussy).<br />
<br />
Tim]]></description>
      <category>HtmlEditor</category>
      <guid isPermaLink="true">http://www.itwriting.com/phorum/read.php?3,3436,3436#msg-3436</guid>
      <pubDate>Tue, 28 Nov 2006 12:52:40 +0000</pubDate>
    </item>
  </channel>
</rss>
