Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Could this markdown editor be used in the non-minimal version of the markdown editor?

+3 votes
624 views
asked Mar 14, 2015 in Plugins by gunrose

I am talking about the peatarian version of the markdown editor: http://peatarian.com/blob/q2a-markdown-editor-master.zip

Could you help me?

There is this replacement in the qa-markdown-editor that depends on
the markdown.min.js:

            $js = str_replace("<!--REPLACEMENT_UPLOAD!>", '<div><form enctype="multipart/form-data" id="qa_imageupload_form" name="qa_imageupload_form" action="upload.php" method="POST"><input type="file" name="qa_imageupload_file" id="qa_imageupload_file"><input type="button" value="Upload" onclick="javascript:qa_imageupload();" name="qa_imageupload_submitbutton" id="qa_imageupload_submitbutton"></form><div id="progress"></div></div>', $js);
            
       

1 Answer

+2 votes
answered Mar 14, 2015 by pupi1985
selected Mar 14, 2015 by gunrose
 
Best answer

I'm not sure if this will work but you could try adding:

<div><form enctype="multipa...id="progress"></div></div>

To the Markdown.Editor.js file exactly where the X is placed (replacing it, of course).

var imageDialogText = '<h3 style="margin-top:0">Enter the image URL.</h3>X';

Note that you won't be able to disable the image upload filter from the Q2A settings. You'll have to use the minified version of the plugin in order to do so. There are a few changes you could make to fix this but it means making even more changes that are not considered good practices.

Edit: And there are more changes in that minified file that are NOT in the source files!

// The input text box
input = doc.createElement("input");
input.type = "text";
input.name = "wmd-promptinputtext";//zzz
input.id = "wmd-promptinputtext";//zzz
input.value = defaultInputText;

And also:

// The cancel button
var cancelButton = doc.createElement("input");
cancelButton.type = "button";
cancelButton.name = "wmd-cancelbutton";//zzz
cancelButton.onclick = function () { return close(true); };

Add the lines with the //zzz comment. Note this is the quick and dirty solution in order to avoid writing the plugin from scratch.

Finally, make sure your qa-markdown-editor.php file looks like this:

$html .= '<script src="'.$this->pluginurl.'pagedown/Markdown.Converter.js"></script>' . "\n";
$html .= '<script src="'.$this->pluginurl.'pagedown/Markdown.Sanitizer.js"></script>' . "\n";
$html .= '<script src="'.$this->pluginurl.'pagedown/Markdown.Editor.js"></script>' . "\n";
//
// comment this script and uncomment the 3 above to use the non-minified code
//$js = file_get_contents($this->pluginurl.'pagedown/markdown.min.js');
//if (qa_opt('md_enable_image_upload')) {
//    $js = str_replace("<!--REPLACEMENT_UPLOAD!>", '<div><form enctype="multipart/form-data" id="qa_imageupload_form" name="qa_imageupload_form" action="upload.php" method="POST"><input type="file" name="qa_imageupload_file" id="qa_imageupload_file"><input type="button" value="Upload" onclick="javascript:qa_imageupload();" name="qa_imageupload_submitbutton" id="qa_imageupload_submitbutton"></form><div id="progress"></div></div>', $js);
//
//}
//$html .= '<script type="text/javascript">'.$js.'</script>' . "\n";

commented Mar 14, 2015 by pupi1985
1) All of them in Markdown.Editor.js. Perform text searches to find the places
2) No
commented Mar 14, 2015 by gunrose
Thank you! Now I understands! It works!!! (:-)
...