[英]Replacing square brackets content to html
我嘗試更改代碼突出顯示標記以匹配Alex Gorbatchev的語法突出顯示標記。
這是我的源代碼的樣子:
[csharp]//awesome code[/csharp]
它應該是這樣的:
<pre brush: csharp>//awesome code</pre>
我想將允許的標簽放入數組。 因此,偽代碼將如下所示:
$.each(allowedValues,function(index,value){
MagicReplaceFunction(value);
}
因此,在可以從代碼突出顯示器調用方法之前,我需要一些更改標簽的方法
jQuery可用。
使用string.replace
函數。
> "[csharp]//awesome code[/csharp]".replace(/\[csharp\]([\s\S]*?)\[\/csharp\]/g, "<pre brush: csharp>$1</pre>")
'<pre brush: csharp>//awesome code</pre>'
[\\s\\S]*?
非貪婪地匹配任何空格或非空格字符。 所以,
\\[csharp\\]
與開始的[csharp]
標記匹配。 ([\\s\\S]*?)
捕獲任意數量的中間字符。 \\[\\/csharp\\]
與結束的[/csharp]
標記匹配。 <pre brush: csharp>
替換匹配的字符,再加上組索引1內的字符</pre>
將為您提供所需的輸出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.