0

This is an example shortcode:

[boutique_banner title="Loyalty Program:" link="More" linkhref="/"]Earn 1 point for every $5 spent[/boutique_banner] 

I have created a custom mce view to display this shortcode nicely in the backend editor. Now I'm working on the "edit" button when this shortcode is clicked.

I am trying to get all the attributes and the shortcode content, so I can display them when doing editor.windowManager.open

This is the working regex I have for getting the attributes:

var re = /([\w\-.:]+)\s*=\s*"([^"]*)"/g, values = {}, match;
while(match = re.exec(shortcode_string)){
   values[match[1]] = match[2]
}

But I'm a little stuck on getting the actual shortcode content, [x]this stuff[/x]

Is there an existing javascript shortcode parser in wordpress? I had a look through the gallery mce view to try and see how they handle shortcode attribute parsing but nothing stood out.

Any ideas?

Thanks!

1 Answer 1

1

found it.

var str = '[boutique_icon icon="phone"]1300 555 555<br />(07) 555 555[/boutique_icon]';

console.debug( wp.shortcode.next( 'boutique_icon', str ) );
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.