Ticket #6518 (new enhancement)

Opened 8 months ago

Last modified 4 months ago

Shortcode escaping

Reported by: tellyworth Assigned to: ryan
Priority: normal Milestone: 2.9
Component: General Version: 2.5
Severity: normal Keywords: has-patch
Cc:

Description

In 2.5.0 there's no official syntax for escaping a shortcode. This makes it difficult to write a post that gives examples of shortcode usage:

Here's how to use the [gallery] tag...

It's possible to work around it by using HTML entities to represent the square brackets but that's ugly.

The enclosed patch improves the shortcode parser to support an escaping syntax:

Here's how to use the [[gallery]] tag...

The output looks like this, with the extra brackets removed:

Here's how to use the [gallery] tag...

It only affects valid shortcode tags, so [[not-a-tag]] displays the input unmodified.

I have unit tested it for common cases including invalid escaping syntax with unbalanced brackets (test_tag_escaped() and test_tag_not_escaped()):

http://svn.automattic.com/wordpress-tests/wp-testcase/test_shortcode.php

Attachments

shortcode-escaping-r7583.patch (1.3 kB) - added by tellyworth on 04/01/08 00:28:18.

Change History

04/01/08 00:28:18 changed by tellyworth

  • attachment shortcode-escaping-r7583.patch added.

04/01/08 00:40:16 changed by tellyworth

nb, double-escaping works too: [[[gallery]]] outputs [[gallery]].

04/15/08 06:33:47 changed by ryan

  • owner changed from anonymous to ryan.

04/16/08 23:29:48 changed by Denis-de-Bernardy

the Markdown escape syntax is also worth looking into:

[gallery] -> not escaped

[gallery] -> escaped

[gallery] -> also escaped

D.

04/16/08 23:31:13 changed by Denis-de-Bernardy

and wiki formatting needs better escaping as well ;-)

[gallery] -> not escaped

`[gallery]` -> escaped

`` [gallery] `` -> also escaped

(follow-up: ↓ 6 ) 07/07/08 08:28:17 changed by stringfold

I agree that this is a problem that needs fixing. (Was a real pain for me until I found a workaround). I would favor the

Error: Failed to load processor shortcode
No macro or processor named 'shortcode' found

format and not those tick marks (unless WP starts using them elsewhere).

I wrote a workaround for my plugin (AZIndex). I simply added another parameter to my shortcode escape="true" for when I wanted to display the shortcode unmodified (in plugin documentation, for example).

But it would be nice to see this fixed in the next release.

(in reply to: ↑ 5 ) 07/07/08 08:30:27 changed by stringfold

Replying to stringfold:

I agree that this is a problem that needs fixing. (Was a real pain for me until I found a workaround). I would favor the [[ shortcode ]] format and not those tick marks (unless WP starts using them elsewhere). I wrote a workaround for my plugin (AZIndex). I simply added another parameter to my shortcode escape="true" for when I wanted to display the shortcode unmodified (in plugin documentation, for example). But it would be nice to see this fixed in the next release.

Oops -- [[ ]] is the escape format I favor.

07/15/08 16:24:07 changed by ryan

  • milestone changed from 2.5.2 to 2.9.

Milestone 2.5.2 deleted