Make WordPress Core

Opened 16 years ago

Closed 15 years ago

#6518 closed enhancement (fixed)

Shortcode escaping

Reported by: tellyworth's profile tellyworth Owned by: westi's profile westi
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.5
Component: General Keywords: has-patch
Focuses: 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 (1)

shortcode-escaping-r7583.patch (1.3 KB) - added by tellyworth 16 years ago.

Download all attachments as: .zip

Change History (11)

#1 @tellyworth
16 years ago

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

#2 @ryan
16 years ago

  • Owner changed from anonymous to ryan

#3 @Denis-de-Bernardy
16 years ago

the Markdown escape syntax is also worth looking into:

[gallery] -> not escaped

[gallery] -> escaped

[gallery] -> also escaped

D.

#4 @Denis-de-Bernardy
16 years ago

and wiki formatting needs better escaping as well ;-)

[gallery] -> not escaped

`[gallery]` -> escaped

`` [gallery] `` -> also escaped


#5 follow-up: @stringfold
16 years ago

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.

#6 in reply to: ↑ 5 @stringfold
16 years ago

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.

#7 @ryan
16 years ago

  • Milestone changed from 2.5.2 to 2.9

Milestone 2.5.2 deleted

#8 @westi
15 years ago

  • Milestone changed from 2.9 to 2.8
  • Owner changed from ryan to westi
  • Status changed from new to assigned

#9 @westi
15 years ago

Patch needs a refresh but I think this should go in.

#10 @westi
15 years ago

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

(In [10576]) Introduce a simple mechanism for escaping shortcodes by doubling the [[]]. Fixes #6518 props tellyworth.

Note: See TracTickets for help on using tickets.