WordPress Trac: Ticket #14857: Shortcode causes preceding HTML tag to disappearhttps://core.trac.wordpress.org/ticket/14857
<p>
On my Wordpress 3.0.1 installation (Atahualpa theme 3.4.4, PHP 5.2.12 + Zend 2.2.0 running on SunOS 5.10) I've succesfully added a shortcode which allows me to 'write' an image into the text of a contribution; all the hard work of figuring out where it should be displayed, how wide the container should be, and what the caption looks like is handled by the shortcode callback function. It works very well, but for one weird issue.
</p>
<p>
If I use a HTML construct like
</p>
<pre class="wiki">&lt;p&gt;[photo location="..." link="..."]Lorem ipsum dolor sit amet...
</pre><p>
where [photo...] expands into a complex &lt;span&gt;, then on random occasions the shortcode processing will swallow the preceding &lt;p&gt; tag. If I didn't have specific CSS applied to distinguish between the appearance of various &lt;a&gt; tags in &lt;p&gt; text (which rely on very specific child selectors, amongst which the presence of an opening &lt;p&gt; tag) I would never have seen the problem. If I modify the HTML to
</p>
<pre class="wiki">&lt;p&gt;&lt;!----&gt;[photo location="..." link="..."]Lorem ipsum dolor sit amet...
</pre><p>
which introduces a non-visible break between the &lt;p&gt; tag and the shortcode, then the &lt;p&gt; tag is left alone. Oddly enough, the comment is not removed either.
</p>
<p>
Unfortunately there seems to be no pattern to this 'gobbling up' of preceding tags; I only know it is there, and how to work around it. On a previous occasion (dealing with ticket <a class="closed ticket" href="https://core.trac.wordpress.org/ticket/14468" title="defect (bug): Shortcode usage causes blog texts to not be output (closed: duplicate)">#14468</a>) I had been instructed to up the PCRE backtrack limit, but setting this at an in my opinion ridiculous value of 5000000 did not cause the problem to disappear. I can provide a visual demonstration of the problem if required.
</p>
en-usWordPress Trachttps://core.trac.wordpress.org/chrome/site/your_project_logo.pnghttps://core.trac.wordpress.org/ticket/14857
Trac 1.0.1nacinSun, 12 Sep 2010 22:29:48 GMThttps://core.trac.wordpress.org/ticket/14857#comment:1
https://core.trac.wordpress.org/ticket/14857#comment:1
<p>
This is a separate issue from backtracking limits. Duplicate of <a class="closed ticket" href="https://core.trac.wordpress.org/ticket/10082" title="defect (bug): Shortcodes need a character separating them to work (closed: fixed)">#10082</a>.
</p>
TicketnacinSun, 12 Sep 2010 22:30:09 GMTstatus changed; resolution set; milestone deletedhttps://core.trac.wordpress.org/ticket/14857#comment:2
https://core.trac.wordpress.org/ticket/14857#comment:2
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>duplicate</em>
</li>
<li><strong>milestone</strong>
<em>Awaiting Review</em> deleted
</li>
</ul>
TicketnacinSun, 12 Sep 2010 22:36:48 GMThttps://core.trac.wordpress.org/ticket/14857#comment:3
https://core.trac.wordpress.org/ticket/14857#comment:3
<p>
Replying to <a class="closed ticket" href="https://core.trac.wordpress.org/ticket/14857" title="defect (bug): Shortcode causes preceding HTML tag to disappear (closed: duplicate)">cymric</a>:
</p>
<blockquote class="citation">
<p>
On a previous occasion (dealing with ticket <a class="closed ticket" href="https://core.trac.wordpress.org/ticket/14468" title="defect (bug): Shortcode usage causes blog texts to not be output (closed: duplicate)">#14468</a>) I had been instructed to up the PCRE backtrack limit, but setting this at an in my opinion ridiculous value of 5000000 did not cause the problem to disappear.
</p>
</blockquote>
<p>
Keep in mind it's just a number.
</p>
<p>
PHP 5.2 introduced a default of 100,000, but internally, PCRE's default limit is actually 10 million. (<a class="ext-link" href="http://bugs.php.net/40846"><span class="icon">​</span>http://bugs.php.net/40846</a>) It's really not much when you start dealing with complex expressions, a lot of content, or both.
</p>
TicketcymricMon, 13 Sep 2010 12:57:01 GMThttps://core.trac.wordpress.org/ticket/14857#comment:4
https://core.trac.wordpress.org/ticket/14857#comment:4
<p>
I know it's just a number; I was merely trying to show initiative in trying to find a simple solution.
</p>
<p>
Anyway, apologies for not finding the <a class="closed ticket" href="https://core.trac.wordpress.org/ticket/10082" title="defect (bug): Shortcodes need a character separating them to work (closed: fixed)">#10082</a>-ticket and opening a duplicate one by mistake: regrettably the title of <a class="closed ticket" href="https://core.trac.wordpress.org/ticket/10082" title="defect (bug): Shortcodes need a character separating them to work (closed: fixed)">#10082</a> isn't particularly detailed so I glanced over it :(.
</p>
TicketnacinMon, 13 Sep 2010 13:41:43 GMThttps://core.trac.wordpress.org/ticket/14857#comment:5
https://core.trac.wordpress.org/ticket/14857#comment:5
<p>
Not a problem at all... We're approaching 15,000 tickets, it's impossible sometimes to find what you're looking for, even if you know what you're looking for :-)
</p>
Ticket