如果缺少,请添加所需的内部简码 [英] Add needed inner shortcode if missing

查看:69
本文介绍了如果缺少,请添加所需的内部简码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

<textarea class="content">
    [row]
        [col-md-12]
            text
        [/col-md-12]
    [/row]
    [row]
        text
    [/row]
</textarea>

现在,我想在[row]内(紧随其后)添加[col-md-12],并使用jquery在[/row]之前将其关闭.结果应该是:

Now I want to add the [col-md-12] inside (directly after) the [row] and close it before the [/row] with jquery. This should be the result:

<textarea class="content">
    [row]
        [col-md-12]
            text
        [/col-md-12]
    [/row]
    [row]
        [col-md-12]
            text
        [/col-md-12]
    [/row]
</textarea>

(注意:上面的代码不是bootstrap!我只是进行了bootstrap,因为它更清楚地表明需要"col-md-12"!)

(Note: The code above is not bootstrap! I just took bootstrap, because its more clear, that the "col-md-12" is needed!)

这是当前代码的jsfiddle示例: http://jsfiddle.net/Zoker/6mzrj1e7/

Here is a jsfiddle example of the current code: http://jsfiddle.net/Zoker/6mzrj1e7/

现在,在转换"之后,第一个"[vc_row]"中缺少一个"[vc_column width ="1/1"]",而在关闭"[/vc_row]"之前没有一个[[/vc_column]". 这就是我需要添加的简码.我不知道如何证明,如果缺少它,然后添加它...

Now after "converting" there is a '[vc_column width="1/1"]' missing inside the first '[vc_row]' and a '[/vc_column]' before the closing '[/vc_row]'. And thats the shortcode I need to add. I dont know how to proof, if its missing and add it then...

我还必须在按钮上单击3次以使内容完全更新. 1次点击后如何使它工作? (使用 https://stackoverflow.com/a/1145525/2977288 解决的问题)

Also I have to click 3 times on the button to get the content completely updated. How can I make it work after 1 click? (edit: that one fixed with https://stackoverflow.com/a/1145525/2977288)

推荐答案

实时:

这很难实现:(希望有帮助)

It was very hard to achieve: (Hope it helps)

// auto_descritive
function wrap_string( str, open_param, close_param ){
    var text = $(".content").text();

    // all indexes of str
    var re = new RegExp(str,'gi'), results = [];
    while (re.exec(text)){
        results.push(re.lastIndex);
    }

    // check each parent param of each str
    for (var i=0; results[i]; i++) {
        var y_param = text.substring(0, results[i]).lastIndexOf(']')+1;
        var x_param = y_param - open_param.length;
        var lastParam = text.substring(x_param, y_param);
        var half1 = text.substring(0, y_param);
        var half2 = text.substring(results[i]+str.length, text.length);
        if (lastParam != open_param) {
            text = half1 + open_param + str + close_param + half2;
            $(".content").text( text );
            // return true if one was wrapped
            return true;
        }
    }

    // return false in case nothing was wrapped
    return false;

}


// wrap all "text" with "[col-md-12] /"
while( wrap_string( "text", "[col-md-12]", "[/col-md-12]" ) );

这篇关于如果缺少,请添加所需的内部简码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆