2009-12-03 54 views
1

即时消息使用wmd markdown编辑器在我的项目中,我有一个代码标签问题: 如果我输入代码片段,markdown不会正确转换为html,它将在“<p>”标签中转换,但如果我输入一些其他文本第一,然后在“<code>”标签正确转换的代码片段 这是一个wmd markdown编辑器的错误?我该如何解决这个问题?wmd markdown code problem

回答

1

我实际上正在为我的固定版本的WMD编辑工作。使用正则表达式可以迅速砍掉了前端和后端<p>标签这是最引人注目的是很多问题的causers:

html = html.replace(/^<p>/g, '').replace(/<\/p>$/g, ''); 

为了在大规模杀伤性武器执行这个..

(我asuming你”重新使用大规模杀伤性武器的编辑器的SO叉)找到这部分代码,并将其更改如下:

var convertToHtml = function(){ 

    if (wmd.showdown) { 
     var markdownConverter = new wmd.showdown.converter(); 
    } 
    var text = inputBox.value; 

    var callback = function(){ 
     inputBox.value = text; 
    }; 

    if (!/markdown/.test(wmd.wmd_env.output.toLowerCase())) { 
     if (markdownConverter) { 
      inputBox.value = markdownConverter.makeHtml(text); 

      // Add this line here: 
      inputBox.value= inputBox.value.replace(/^<p>/g, '').replace(/<\/p>$/g, ''); 

      top.setTimeout(callback, 0); 
      } 
     } 
    return true; 
}; 

未经检验的,但你应该明白我的意思。

+0

你能帮我解答吗 – Moon

0

与T.斯通先生回答。我已经在我使用大规模杀伤性武器完成,除去

<p> ..article.. </p> 

是..article ..

而这里WMD.js代码:(线:910)

if (converter) { 
    text = converter.makeHtml(text); 
    //new code here 
    text= text.replace(/^<p>/g, '').replace(/<\/p>$/g, ''); 
} 

我在回答中写了这个,因为我很高兴它在一周内解决了我的问题。谢谢。