wmd markdown code problem
i m using wmd markdown editor in my project and i have a problem with code tags:
if i enter a code snippet , markdown does not convert to html correctly it converts in "<p>
" tags but if i enter some text else first and then code snippet it converts correctly in "<code>
" tags
is this a bug of wmd m开发者_如何学运维arkdown editor? and how can i solve this problem?
I was actually working on this for my fixed version of WMD edit. Using regex you can quickly lop off the leading and trailing <p>
tags which are most notably the causers of a lot of problems:
html = html.replace(/^<p>/g, '').replace(/<\/p>$/g, '');
To enforce this in wmd..
(I'm asuming you're using the SO fork of wmd editor) Find this part of the code and change it as follows:
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;
};
Untested, but you should get the idea.
With Mr. T. Stone answer. I have done in WMD that i used, to remove
<p> ..article.. </p>
to be ..article..
And here the WMD.js code :(line : 910 )
if (converter) {
text = converter.makeHtml(text);
//new code here
text= text.replace(/^<p>/g, '').replace(/<\/p>$/g, '');
}
i wrote this in answer because i am very glad it solve my problem in a week. thankyou.
精彩评论