[wp-trac] Re: [WordPress Trac] #5073: Editor behaves strange when trying to type a html comment.

WordPress Trac wp-trac at lists.automattic.com
Tue Sep 25 13:13:33 GMT 2007


#5073: Editor behaves strange when trying to type a html comment.
---------------------+------------------------------------------------------
 Reporter:  znuff    |        Owner:  anonymous
     Type:  defect   |       Status:  new      
 Priority:  normal   |    Milestone:  2.3.1    
Component:  General  |      Version:  2.3      
 Severity:  normal   |   Resolution:           
 Keywords:           |  
---------------------+------------------------------------------------------
Changes (by DD32):

  * component:  TinyMCE => General

Comment:

 That'll be coming from wptexturize()

 The actual HTML output of the above code is:

 {{{
 <code>&lt;!-- <em>Some Text</em> &#8211;&gt;</code>
 }}}

 wptexturize seems to be slightly flawed in the terms of HTML within code
 blocks:

 in:
 {{{
 <code>&lt;!-- <em>Some Text</em> --&gt;</code><br />
 <code>&lt;!-- TEST --&gt;</code>
 }}}

 out:
 {{{
 <code>&lt;!-- <em>Some Text</em> &#8211;&gt;</code><br />
 <code>&lt;!-- TEST --&gt;</code>
 }}}

 I would've expected that within the code block, that the HTML would be
 escaped so as to apear to the end user rather than being presented, But
 thats what causes this issue:

 {{{
 $textarr:
 array
   0 => string '' (length=0)
   1 => string '<code>' (length=6)
   2 => string '&lt;!-- ' (length=8)
   3 => string '<em>' (length=4)
   4 => string 'Some Text' (length=9)
   5 => string '</em>' (length=5)
   6 => string ' --&gt;' (length=7)
   7 => string '</code>' (length=7)
   8 => string '
 &' (length=2)
   9 => string '<code>' (length=6)
   10 => string '&lt;!-- TEST --&gt;' (length=19)
   11 => string '</code>' (length=7)
   12 => string '' (length=0)
 }}}

 Since <code is in #1 then the "static_characters" dont get replaced,
 however, that flag is reset for the next array item, which causes the
 following lines to be texturized.

 In the 2nd example i put in, due to the spliting method, and there being
 no unconverted HTML in the code block, it passes through A-OK as all the
 content of the codeblock apear in the same array item (Ie. its skipped
 because the preceeding item is the start of a code block)


 Had the OP been using the Visual editor, then i doubt there would be a
 issue as TinyMCE would be encoding the HTML for him.

 Just thinking about it, Perhaps all HTML within a Code block can safely be
 assumed that it is encoded, and as such, its a null issue?[[BR]]
 The OP has encoded some of the content (The <!-- pieces, just not the
 <em>).

 If the input was changed to: (as TinyMCE would do)
 {{{
 <code>&lt;!-- &lt;em&gt;Some Text&lt;/em&gt; --&gt;</code>
 }}}
 Then it works fine.

 However, Running code such as this through wptexturize would cause havvoc:
 {{{
 <script>
 alert('This is a <em>Test</em>');
 </script>
 }}}
 produces:
 {{{
 <script>
 alert(\'This is a <em>Test</em>&#8216;);
 </script>
 }}}

 I'm thinking outloud here, and hopefully will bring some thoughts to mind.

 znuff, Maybe your best bet is to just use a plugin thats designed to post
 Sourcecode into your blog? Eg.
 http://wordpress.org/extend/plugins/syntaxhighlighter/

 (Removing TinyMCE as it has nothing to do with it)

-- 
Ticket URL: <http://trac.wordpress.org/ticket/5073#comment:3>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list