diff --git a/docs/en/reference/shortcodes.md b/docs/en/reference/shortcodes.md
index 09788a0e6..9140d0552 100644
--- a/docs/en/reference/shortcodes.md
+++ b/docs/en/reference/shortcodes.md
@@ -1,32 +1,143 @@
-# Shortcodes
+# Shortcodes: Flexible Content Embedding
-The Shortcode API is a way to replace simple bbcode-like tags within HTML. It is inspired by and very similar to
-the [Wordpress implementation](http://codex.wordpress.org/Shortcode_API) of shortcodes.
+## Overview
-A guide to syntax
+The `[api:ShortcodeParser]` API is simple parser that allows you to map specifically
+formatted content to a callback to transform them into something else.
+You might know this concept from forum software which don't allow you to insert
+direct HTML, instead resorting to a custom syntax.
- Unclosed - [shortcode]
- Explicitly closed - [shortcode/]
- With parameters, mixed quoting - [shortcode parameter=value parameter2='value2' parameter3="value3"]
- Old style parameter separation - [shortcode,parameter=value,parameter2='value2',parameter3="value3"]
- With contained content & closing tag - [shortcode]Enclosed Content[/shortcode]
- Escaped (will output [just] [text] in response) - [[just] [[text]]
+In the CMS, authors often want to insert content elements which go beyond
+standard formatting, at an arbitrary position in their WYSIWYG editor.
+Shortcodes are a semi-technical solution for this. A good example would
+be embedding a 3D file viewer or a Google Map at a certain location.
-Shortcode parsing is already hooked into HTMLText and HTMLVarchar fields when rendered into a template
+Here's some syntax variations:
+
+ [my_shortcode]
+ [my_shortcode /]
+ [my_shortcode,myparameter="value"]
+ [my_shortcode,myparameter="value"]Enclosed Content[/my_shortcode]
-## Attribute and element scope
+## Usage
+
+In its most basic form, you can invoke the `[api:ShortcodeParser]` directly:
+
+ :::php
+ ShortcodeParser::get_active()->parse($myvalue);
+
+In addition, shortcodes are automatically parsed on any database field which is declared
+as `[api:HTMLValue]` or `[api:HTMLText]`, when rendered into a template.
+This means you can use shortcodes on common fields like `SiteTree.Content`,
+and any other `[api:DataObject::$db]` definitions of these types.
+
+In order to allow shortcodes in your own template placeholders,
+ensure they're casted correctly:
+
+ :::php
+ class MyObject extends DataObject {
+ static $db = array('Content' => 'HTMLText');
+ static $casting = array('ContentHighlighted' => 'HTMLText');
+ public function ContentHighlighted($term) {
+ return str_replace($term, "$term", $this->Content);
+ }
+ }
+
+There is currently no way to allow shortcodes directly in template markup
+(as opposed to return values of template placeholders).
+
+## Defining Custom Shortcodes
+
+All you need to do to define a shortcode is to register a callback with the parser that will be called whenever a
+shortcode is encountered. This callback will return a string to replace the shortcode with.
+If the shortcode is used for template placeholders of type `HTMLText` or `HTMLVarchar`,
+the returned value should be valid HTML
+
+To register a shortcode you call:
+
+ ShortcodeParser::get('default')->register('my_shortcode',
Head [figure src="assets/a.jpg" caption="caption"] Tail
+Head [figure,src="assets/a.jpg",caption="caption"] Tail
When converted naively would become @@ -83,43 +191,11 @@ When the location attribute is "leftAlone" or "center" then the DOM is split aro -## Defining Custom Shortcodes - -All you need to do to define a shortcode is to register a callback with the parser that will be called whenever a -shortcode is encountered. This callback will return a string to replace the shortcode with. - - :::php - public static function my_shortcode_handler($attributes, $enclosedContent, $parser, $tagName) { - // This simple callback simply converts the shortcode to a span. - return "$enclosedContent"; - } - -The parameters passed to the callback are, in order: - -* Any parameters attached to the shortcode as an associative array (keys are lower-case). -* Any content enclosed within the shortcode (if it is an enclosing shortcode). Note that any content within this will -not have been parsed, and can optionally be fed back into the parser. -* The ShortcodeParser instance used to parse the content. -* The shortcode tag name that was matched within the parsed content. - -For the shortcode to work, you need to register it with the `ShortcodeParser`. Assuming you've placed the -callback function in the `Page` class, you would need to make the following call from `_config.php`: - - :::php - ShortcodeParser::get('default')->register( - 'shortcode_tag_name', - array('Page', 'my_shortcode_handler') - ); - -An example result of installing such a shortcode would be that the string `[shortcode_tag_name]Testing -testing[/shortcode_tag_name]` in the page *Content* would be replaced with the `Testing -testing`. - ### Parameter values Here is a summary of the callback parameter values based on some example shortcodes. -#### Short +Short [my_shortcodes] @@ -128,7 +204,7 @@ Here is a summary of the callback parameter values based on some example shortco $parser => ShortcodeParser instance $tagName => 'my_shortcode' -#### Short with attributes +Short with attributes [my_shortcode,attribute="foo",other="bar"] @@ -137,7 +213,7 @@ Here is a summary of the callback parameter values based on some example shortco $parser => ShortcodeParser instance $tagName => 'my_shortcode' -#### Long with attributes +Long with attributes [my_shortcode,attribute="foo"]content[/my_shortcode] @@ -146,11 +222,6 @@ Here is a summary of the callback parameter values based on some example shortco $parser => ShortcodeParser instance $tagName => 'my_shortcode' -## Inbuilt Shortcodes - -All internal links inserted via the CMS into a content field are in the form ``. At -runtime this is replaced by a plain link to the page with the ID in question. - ## Limitations Since the shortcode parser is based on a simple regular expression it cannot properly handle nested shortcodes. For @@ -161,3 +232,7 @@ example the below code will not work as expected: [/shortcode] The parser will raise an error if it can not find a matching opening tag for any particular closing tag + +## Related + + * [Wordpress implementation](http://codex.wordpress.org/Shortcode_API) \ No newline at end of file diff --git a/docs/en/topics/shortcodes.md b/docs/en/topics/shortcodes.md deleted file mode 100644 index d11b07091..000000000 --- a/docs/en/topics/shortcodes.md +++ /dev/null @@ -1,143 +0,0 @@ -# Shortcodes: Flexible Content Embedding - -## Overview - -The `[api:ShortcodeParser]` API is simple parser that allows you to map specifically -formatted content to a callback to transform them into something else. -You might know this concept from forum software which don't allow you to insert -direct HTML, instead resorting to a custom syntax. - -In the CMS, authors often want to insert content elements which go beyond -standard formatting, at an arbitrary position in their WYSIWYG editor. -Shortcodes are a semi-technical solution for this. A good example would -be embedding a 3D file viewer or a Google Map at a certain location. - -Here's some syntax variations: - - [myshortcode] - [myshortcode /] - [myshortcode,myparameter="value"] - [myshortcode,myparameter="value"]Enclosed Content[/myshortcode] - -## Usage - -In its most basic form, you can invoke the `[api:ShortcodeParser]` directly: - - :::php - ShortcodeParser::get_active()->parse($myvalue); - -In addition, shortcodes are automatically parsed on any database field which is declared -as `[api:HTMLValue]` or `[api:HTMLText]`, when rendered into a template. -This means you can use shortcodes on common fields like `SiteTree.Content`, -and any other `[api:DataObject::$db]` definitions of these types. - -In order to allow shortcodes in your own template placeholders, -ensure they're casted correctly: - - :::php - class MyObject extends DataObject { - static $db = array('Content' => 'HTMLText'); - static $casting = array('ContentHighlighted' => 'HTMLText'); - public function ContentHighlighted($term) { - return str_replace($term, "$term", $this->Content); - } - } - -There is currently no way to allow shortcodes directly in template markup -(as opposed to return values of template placeholders). - -## Defining Custom Shortcodes - -All you need to do to define a shortcode is to register a callback with the parser that will be called whenever a -shortcode is encountered. This callback will return a string to replace the shortcode with. -If the shortcode is used for template placeholders of type `HTMLText` or `HTMLVarchar`, -the returned value should be valid HTML - -To register a shortcode you call: - - ShortcodeParser::get('default')->register('myshortcode',