I am trying to parse shortcode using jquery regex. But there is a problem with regex. Here is my code for using shortcode.
function shortCode(b, c) {
var e = /\[\S (?:\s [^="] ="[^"\]\s] ") \]/g;
for (var i = 0; i < e.length; i ) {
var f = e[i].split('=');
if (f[0].trim() == b) {
c = f[1];
if (c.match(e) != null) {
return String(c.match(e)).trim()
}
else {
return false
}
}
}
return false
}
My shortcode should be like this.
<strike>[stack="hello" over="hi" flow="5"]</strike>
Output code:
$(".test strike").each(function () {
var e = $(this),
t = e.html(),
a = t.toLowerCase(),
o = shortCode(t, "stack"),
s = shortCode(t, "over"),
r = shortCode(t, "flow");
if (a.match("getcode")) {
e.replaceWith('<div>' o s r '</div>');
}
});
CodePudding user response:
you can use shortcode.js by nicinabox. This will help you to create wordpress like shortcode.