仅CONTENTEDITABLE DIV示例字符串
int main(){
if((x<3 && x!=5) || x>10)
//execute statement;
while((y<10) && (y>1))
//execute statement;
}
DIV 的现有 HTML
<div id="board_code">
<div>int main<span class="openParen bm1">(</span><span class="closeParen bm1">)</span></div>
<div></div>
<div>if<span class="openParen bm2">(</span><span class="openParen bm3">(</span>x<3 && x!=5<span class="closeParen bm3">)</span> || x>10<span class="closeParen bm2">)</span></div>
<div>//execute statement;</div>
<div>while<span class="openParen bm4">(</span><span class="openParen bm5">(</span>y<10<span class="closeParen bm5">)</span> && <span class="openParen bm6">(</span>y>1<span class="closeParen bm6">)</span><span class="closeParen bm4">)</span></div>
<div>//execute statement;</div>
<div>}</div>
</div>
目标 HTML
<div id="board_code">
<div>int main<span class="parenWrap"><span class="openParen bm1">(</span><span class="closeParen bm1">)</span></span></div>
<div></div>
<div>if<span class="parenWrap"><span class="openParen bm2">(</span><span class="parenWrap"><span class="openParen bm3">(</span>x<3 && x!=5<span class="closeParen bm3">)</span></span> || x>10<span class="closeParen bm2">)</span></span></div>
<div>//execute statement;</div>
<div>while<span class="parenWrap"><span class="openParen bm4">(</span><span class="parenWrap"><span class="openParen bm5">(</span>y<10<span class="closeParen bm5">)</span></span> && <span class="parenWrap"><span class="openParen bm6">(</span>y>1<span class="closeParen bm6">)</span></span><span class="closeParen bm4">)</span></span></div>
<div>//execute statement;</div>
<div>}</div>
</div>
我已经()
通过一对bm1, bm2
等来匹配了。现在,我需要将 to包裹openParen bm(n)
起来。看,我已经确定了paren对,现在我需要将它们作为一个整体包装起来,以便我以后可以评估它们,它接近HIGHLIGHTING,但我不会真正突出它,我将评估对之间的文本。closeParen bm(n)
span class = parenWrap
我怎样才能做到这一点?
我试过这个,但它不工作
$('.openParen, .bm0').first().nextUntil('.closeParen, .bm0').last().wrapAll('<span class="parenWrap"></span>');
//this must loop to all the bm's by the way