2015-08-30 133 views
1

我想用創建自定義標籤降價等showdown.js即:showdown.js擴展:匹配多字擴展

==highlighted text== 

呈現:

<mark>highlighted text</mark> 

使用twitter擴展爲基線,我已經一直在嘗試:

// #highlighted# syntax 
    { 
    type: 'lang', 
    regex: '\\B(\\\\)?==([\\S]+)\\b', 
    replace: function (match, leadingSlash, highlighted) { 
     // Check if we matched the leading \ and return nothing changed if so 
     if (leadingSlash === '\\') { 
     return match; 
     } else { 
     return '<mark>' + highlighted + '</mark>'; 
     } 
    } 
    }, 

但是,這隻能讓我highlig單個單詞,例如

  • == ==蘋果梨
  • 蘋果梨

我想使用==類似**

我認爲問題是正則表達式,但似乎不能釘它。有人可以建議嗎?

回答

1

如果我理解正確的問題,你可以使用這個簡單的正則表達式:

regex: "==\\s*(.+?)\\s*=="; 

,並使用匹配的組1#。

RegEx Demo