svivian / q2a-markdown-editor

Markdown editor plugin for Question2Answer
55 stars 24 forks source link

Plugin introduces HTML code which is not valid #5

Closed alixandru closed 11 years ago

alixandru commented 11 years ago

The HTML introduced by the plugin is not valid. Here is a patch to make it valid.

--- a/qa-plugin/markdown-editor/qa-markdown-editor.php
+++ b/qa-plugin/markdown-editor/qa-markdown-editor.php
@@ -24,7 +24,7 @@ class qa_markdown_editor
    function get_field(&$qa_content, $content, $format, $fieldname, $rows, $autofocus)
    {
        $html = '<div id="wmd-button-bar-'.$fieldname.'" class="wmd-button-bar"></div>' . "\n";
-        $html .= '<textarea name="'.$fieldname.'" id="wmd-input-'.$fieldname.'" class="wmd-input">'.$content.'</textarea>' . "\n";
+        $html .= '<textarea name="'.$fieldname.'" id="wmd-input-'.$fieldname.'" class="wmd-input" cols="80" rows="15">'.$content.'</textarea>' . "\n";
        $html .= '<h3>Preview</h3>' . "\n";
        $html .= '<div id="wmd-preview-'.$fieldname.'" class="wmd-preview"></div>' . "\n";

@@ -33,7 +33,7 @@ class qa_markdown_editor
         // $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
-        $html .= '<script src="'.$this->pluginurl.'pagedown/markdown.min.js"></script>' . "\n";
+        $html .= '<script src="'.$this->pluginurl.'pagedown/markdown.min.js" type="text/javascript"></script>' . "\n";

        return array( 'type'=>'custom', 'html'=>$html );
    }

And

--- a/qa-plugin/markdown-editor/qa-md-layer.php
+++ b/qa-plugin/markdown-editor/qa-md-layer.php
@@ -48,7 +48,7 @@ class qa_html_theme_layer extends qa_html_theme_base
        if ( $usehljs )
        {
            $this->output_raw(
-                "<script src=\"" . QA_HTML_THEME_LAYER_URLTOROOT . "pagedown/highlight.min.js\"></script>\n" .
+                "<script src=\"" . QA_HTML_THEME_LAYER_URLTOROOT . "pagedown/highlight.min.js\" type=\"text/javascript\"></script>\n" .

                "<script type=\"text/javascript\">\n" .
                "$(function(){\n" .
svivian commented 11 years ago

Hi, thanks for taking the time to contribute!

However, the code the plugin outputs is not invalid per the HTML5 spec. Scripts don't require the type attribute (Javascript is the default), and textareas don't require the rows/cols attributes.

I suggest updating your code to use the HTML 5 doctype - <!DOCTYPE html> - and revalidating. (You can change the doctype in Q2A by overriding the doctype() function in an advanced theme.)