[wp-trac] [WordPress Trac] #10702: Support for complex nested shorttags
WordPress Trac
noreply at wordpress.org
Mon Nov 5 10:26:49 UTC 2012
#10702: Support for complex nested shorttags
-------------------------------------+-----------------------------
Reporter: pepijndevos | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Future Release
Component: Shortcodes | Version: 2.9
Severity: normal | Resolution:
Keywords: has-patch needs-testing |
-------------------------------------+-----------------------------
Changes (by kovshenin):
* keywords: needs-patch => has-patch needs-testing
Comment:
Hi there! My name is Konstantin and I love regular expressions (not!).
Everybody says we should not parse HTML using a regular expression, and
they're right. However, nobody said anything about using ''two'' (or more)
regular expressions to parse HTML, so let's just do a bunch of loops :)
[attachment:10702.diff] is an attempt to allow proper nested shortcodes in
WordPress. The regex pattern has changed to use a positive lookahead and
match the opening shortcode tag only if it's followed by its closing tag,
meaning the search will match the inner tags first, which is why a loop
has been introduced in `do_shortcode` and `strip_shortcodes` which will
loop from the inner tags to the outer tags. This means that
`preg_replace_callback` will run at least twice if a shortcode is present.
[attachment:10702.unit-tests.diff] adds some test coverage.
[attachment:10702.performance.csv] shows that there's a slight performance
hit when the content has a lot of shortcodes. The "no shortcodes" and
"some shortcodes" gains are probably due to the `strstr( $content, '[' )`
short circuit in `do_shortcode`. The plugin that ran these tests can be
found [https://gist.github.com/4016443 here].
This is a draft and has room for improvement. Whatever we end up doing in
`do_shortcode` should be equally done in `strip_shortcodes`. Also,
escaping shortcodes might look a little weird with that string
replacement, but since we're now replacing in a loop several times,
replacing `[[` with `[` will no longer work. If you can think of a smarter
way, I'm all ears!
Your feedback is highly appreciated :)
--
Ticket URL: <http://core.trac.wordpress.org/ticket/10702#comment:13>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list