Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
645 views
in Plugins by

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
by
selected by
 
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";

by
Thank you! @pupi1985 I think something is still missing. The image upload box is there. I can choose the file, but when I upload the file, it keeps "sending" and it does not get the file at all. The administrator settings seems also to be working well and the "enable image uploads" seems to be working, but it is not working at all.

I didnt understand very well "Note that you won't be able to disable the image upload filter from the Q2A settings. You'll have to rollback this change too."
by
It seems the developer made changes to the minified files and not to the source files. So it is pending to make the same changes to the source files. I've updated the answer with those changes.
by
@pupi1985 Thank you again! (1) Where should I include the input text box and the cancel button? (2) Is there a missing "var" before "input = doc.createElement("input"); "?
by
1) All of them in Markdown.Editor.js. Perform text searches to find the places
2) No
by
Thank you! Now I understands! It works!!! (:-)
...