ENHANCEMENT Shortcodes now support commas as delimiter for attributes (thanks aoneil for help with the regex!) (trac #6868)

BUGFIX HtmlEditorField not inserting shortcodes correctly (trac #6868)
This commit is contained in:
Sean Harvey 2012-03-09 14:25:42 +13:00
parent c59c717d78
commit 49267dbbc4
3 changed files with 7 additions and 8 deletions

View File

@ -370,7 +370,7 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
// All other attributes // All other attributes
switch(this.find(':input[name=LinkType]:checked').val()) { switch(this.find(':input[name=LinkType]:checked').val()) {
case 'internal': case 'internal':
href = '[sitetree_link id=' + this.find(':input[name=internal]').val() + ']'; href = '[sitetree_link,id=' + this.find(':input[name=internal]').val() + ']';
if(anchor) href += '#' + anchor; if(anchor) href += '#' + anchor;
break; break;
@ -379,7 +379,7 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
break; break;
case 'file': case 'file':
href = '[file_link id=' + this.find(':input[name=file]').val() + ']'; href = '[file_link,id=' + this.find(':input[name=file]').val() + ']';
target = '_blank'; target = '_blank';
break; break;

View File

@ -170,10 +170,9 @@ class ShortcodeParser {
if($prefix == '[' && $suffix == ']') { if($prefix == '[' && $suffix == ']') {
return substr($matches[0], 1, -1); return substr($matches[0], 1, -1);
} }
$attributes = array(); // Parse attributes into into this array. $attributes = array(); // Parse attributes into into this array.
if(preg_match_all('/(\w+) *= *(?:([\'"])(.*?)\\2|([^ "\'>]+))/', $matches[3], $match, PREG_SET_ORDER)) { if(preg_match_all('/(\w+) *= *(?:([\'"])(.*?)\\2|([^ ,"\'>]+))/', $matches[3], $match, PREG_SET_ORDER)) {
foreach($match as $attribute) { foreach($match as $attribute) {
if(!empty($attribute[4])) { if(!empty($attribute[4])) {
$attributes[strtolower($attribute[1])] = $attribute[4]; $attributes[strtolower($attribute[1])] = $attribute[4];

View File

@ -82,14 +82,14 @@ class ShortcodeParserTest extends SapphireTest {
} }
public function testUnquotedArguments() { public function testUnquotedArguments() {
$this->assertEquals('', $this->parser->parse('[test_shortcode foo=bar baz = buz]')); $this->assertEquals('', $this->parser->parse('[test_shortcode,foo=bar,baz = buz]'));
$this->assertEquals(array('foo' => 'bar', 'baz' => 'buz'), $this->arguments); $this->assertEquals(array('foo' => 'bar', 'baz' => 'buz'), $this->arguments);
} }
public function testSelfClosingTag() { public function testSelfClosingTag() {
$this->assertEquals ( $this->assertEquals (
'morecontent', 'morecontent',
$this->parser->parse('[test_shortcode id="1"/]more[test_shortcode id="2"]content[/test_shortcode]'), $this->parser->parse('[test_shortcode,id="1"/]more[test_shortcode,id="2"]content[/test_shortcode]'),
'Assert that self-closing tags are respected during parsing.' 'Assert that self-closing tags are respected during parsing.'
); );