Opened 17 years ago
Closed 16 years ago
#6518 closed enhancement (fixed)
Shortcode escaping
Reported by: | tellyworth | Owned by: | 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)
Change History (11)
#3
@
17 years ago
the Markdown escape syntax is also worth looking into:
[gallery] -> not escaped
[gallery]
-> escaped
[gallery]
-> also escaped
D.
#4
@
17 years ago
and wiki formatting needs better escaping as well ;-)
[gallery] -> not escaped `[gallery]` -> escaped `` [gallery] `` -> also escaped
#5
follow-up:
↓ 6
@
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
@
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.
nb, double-escaping works too:
[[[gallery]]]
outputs[[gallery]]
.