简体   繁体   English

不解析代码标签之间的BBCode

[英]Not Parse BBCode Between Code Tags

I have read other posts on this topic, but none of them seem to help. 我已经阅读了有关该主题的其他文章,但似乎都没有帮助。

Ok, so I am coding my own BBCode parser. 好的,所以我正在编码自己的BBCode解析器。 Now my question is how can I NOT parse the BBCode between the [code] tags? 现在我的问题是我怎么不解析[code]标签之间的BBCode? I am really not sure how I would go about this. 我真的不确定如何去做。 This is my current code: 这是我当前的代码:

$('#posttextareadisplay').text($('#textareainput').val());
    var replacebbcode = $('#posttextareadisplay').html().replace(/(\[((\/?)(b|i|u|s|sup|sub|code|quote))\])/gi, '<$2>')
                                                        .replace(/(\[(rule)\])/gi, '<hr>')
                                                        .replace(/(\[((align=)(left|center|right|justify))\])/gi, '<div align="$4">')
                                                        .replace(/(\[((\/)(align))\])/gi, '</div>')
                                                        .replace(/(\[((color=#)([0-9a-fA-F]{0,}))\])/gi, '<span style="color:#$4">')
                                                        .replace(/(\[((\/)(color))\])/gi, '</span>')
                                                        .replace(/(\[((size=)(1|2|3|4|5|6))\])/gi, '<font size="$4">')
                                                        .replace(/(\[((\/)(size))\])/gi, '</font>')
                                                        .replace(/(\[((link=)([a-zA-Z0-9._:\/\\+-]{0,}))\])/gi, '<a href="$4">')
                                                        .replace(/(\[((\/)(link))\])/gi, '</a>')
                                                        .replace(/((((http|https):\/\/)(([a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal))(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&amp;]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@\/?]*)?)(\s+|$))/gi, '<a href="$1">$1</a>');
    $('#posttextareadisplay').html(replacebbcode);

So what do I do to NOT parse the code inbetween the [code] tags? 那么,我该怎么做才能不解析[code]标签之间的代码? Thank You!!! 谢谢!!! :) :)

PS I am using JS/Jquery PS我正在使用JS / Jquery

One solution would be to replace the BBCode special characters [ and ] with the corresponding HTML entities &#91; 一种解决方案是用相应的HTML实体&#91;替换BBCode特殊字符[] &#91; and &#93; &#93; so that they are not parsed later: 以便以后不解析它们:

input.replace(/\[code](.*?)\[\/code]/g,function(m,a){return '<code>'+a.replace(/[[\]]/g, function(t){return '&#9'+(t=='['?'1':'3')+';';})+'</code>';})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM