Make WordPress Core

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#7056 closed defect (bug) (fixed)

wptexturize should leave contents of pre tags verbatim

Reported by: nbachiyski Owned by:
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.8
Component: Formatting Keywords: has-patch wptexturize tested
Focuses: Cc:


Current behaviour:

  • wptexturize('<pre><code></code>--</pre>') gives <pre><code></code>&#8211;</pre>

Expected behavious:

  • wptexturize shouldn't convert the two hyphens to a m-dash and should return <pre><code></code>--</pre>

The problem is that wptexturize doesn't keep it's state if tags are nested.

Also, a test was added. The patched version passes it.

Attachments (3)

texturize-deep-pre.diff (1.4 KB) - added by nbachiyski 13 years ago.
texturize-deep-code.diff (1.6 KB) - added by nbachiyski 12 years ago.
texturize-stack.diff (2.8 KB) - added by nbachiyski 12 years ago.

Download all attachments as: .zip

Change History (14)

#1 @Viper007Bond
13 years ago

  • Version set to 2.6

Oh thank you thank you thank you. This'll be a huge help for my code posting plugins.

#2 @ryan
13 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [8298]) Hands off pre tags. Props nbachiyski. fixes #7056

#3 @nbachiyski
12 years ago

  • Milestone changed from 2.6 to 2.8
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from 2.6 to 2.8

We should do the same with code tags, too. They often contain other tags, as links and in that case wptexturize() breaks the quotes and dashes.

The test from the ticket description was updated to reflect the changes. The patch passes the tests.

#4 @DD32
12 years ago

See also: #6969 (<code>/shortcodes)

#5 @nbachiyski
12 years ago

Regex parsing of tags sucks. Setting $next to false doesn't work if you have any tags inside a pre/code/whatever. The current patch doesn't work with two nested pres. So, here are the stacks.

The stacks approach works for any number/kind of nested elements. It also keeps a dynamic list of the not texturizable tags and shortcodes, so that a plugin can modify them. This way you can opt-out your shortcode from wptexturize() (this fixes #6969).

Please, have a look at the unit tests, I would be happy if anybody adds more. They are really useful in this case.

#6 @Denis-de-Bernardy
12 years ago

  • Component changed from General to Formatting

#7 @nbachiyski
12 years ago

  • Keywords tested added

#8 @ryan
12 years ago

See #8321. tt support would need to be merged into this if we go with it.

BTW, this has been running on wp.com for the past 3 weeks.

#9 @ryan
12 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [11345]) Handle nested tag in wptexturize(). Props nbachiyski. fixes #7056 see #6969

#10 @miken32
12 years ago

Definitely looking forward to this one, it will be in 2.9 I assume?

I wanted to add that <samp> should be added to the list of HTML elements to leave alone. This element "represents (sample) output from a program or computing system."

#11 @miken32
12 years ago

  • Cc miken32 added
Note: See TracTickets for help on using tickets.