Question

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 markdown editor? and how can i solve this problem?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top