WP-Code-Highlight.js icon indicating copy to clipboard operation
WP-Code-Highlight.js copied to clipboard

Why removed from Wordpress plugin site?

Open giggio opened this issue 6 years ago • 5 comments

I just noticed this plugin was removed from the wordpress plugin site. Why was that?

image

giggio avatar Jul 12 '19 21:07 giggio

There is a secure problem in this plugin. (see https://github.com/owt5008137/WP-Code-Highlight.js/pull/27 for the detail, thanks to jason0x90.) I have already merge the PR and republish it and send a email to wordpress team to reopen it. Please wait some times.

owent avatar Jul 13 '19 03:07 owent

Hi, it's been a month, do you know when they are adding it back?

giggio avatar Aug 12 '19 18:08 giggio

Sorry. The wordpress team tell me there are still some CSRF problems in this plugin when wordpress is setup for multiple sites. I don't use wordpress any more and I have no environment to test it after making a lot of changes to codes. So this plugin may be closed later.

owent avatar Aug 13 '19 01:08 owent

How about publishing the version that was updated after the fix from #27?

giggio avatar Oct 25 '19 16:10 giggio

Sorry, I have tried to publish it again but the wordpress team tell me I need to sanitize all data(Though I think I have sanitized all the input field.). I don't use wordpress myself any more and I have no environment to test this plugin. I seggust you to find another replacement or just import highlightjs's js and css into your website ,for example, add these codes below into the tail of <body></body>:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/highlight.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/languages/bash.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/languages/cpp.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/languages/go.min.js"></script>
<!--<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/languages/OTHER LANGUAGES.min.js"></script>-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.10/styles/vs.min.css" />

And then add these codes to enable it:

<script type="text/javascript">
jQuery(function(){
    hljs.configure({
        tabReplace: '    ',
        useBR: false,
        classPrefix: '',
        languages: []

    });

    jQuery('pre code').each(function(i, block) {
        hljs.highlightBlock(block);
    });

    // add this if you need syntaxhighlighter compatible mode
    jQuery('pre:not(:has(code))').each(function(i, block){
        var class_desc = jQuery(block).attr("class") || "";
        var reg_mat = class_desc.match(/brush\s*:\s*([\w\d]+)/i);
        if(!reg_mat || reg_mat.length < 2)
            return;
        var code_content = jQuery(block).removeClass("brush:").removeClass("ruler:").removeClass("first-line:").removeClass("highlight:")
            .removeClass("brush:" + reg_mat[1] + ";").removeClass(reg_mat[1] + ";").removeClass("true;").removeClass("false;").html();
        jQuery(block).empty().append(jQuery("<code class='hljs'></code>").html(code_content)).addClass(reg_mat[1]);
        hljs.highlightBlock(block);
    });

    // add this if you need prettify compatible mode
    jQuery('pre.prettyprint:not(.prettyprinted), code.prettyprint:not(.prettyprinted), xmp.prettyprint:not(.prettyprinted)').each(function(i, block){
        var jblock = jQuery(block).removeClass("prettyprint");
        if (jblock.prop("tagName").toLowerCase() == "code" && jblock.parent().prop("tagName").toLowerCase() == "pre") {
            hljs.highlightBlock(jblock.parent().get(0));
            return;
        }
        var class_desc = jQuery(block).attr("class") || "";
        var reg_mat = class_desc.match(/lang[^-]*-([\w\d]+)/i);
        var code_content = jQuery("<code class='hljs'></code>");
        if (reg_mat && reg_mat.length >= 2) {
            code_content.addClass(reg_mat[1]);
        }
        if (jblock.prop("tagName") === "PRE") {
            jblock.wrapInner(code_content);
            hljs.highlightBlock(jblock.children().get(0));
        } else {
            var code_content = jblock.html();
            jblock.replaceWith(jQuery("<pre></pre>").append(code_content.html(code_content)));
            hljs.highlightBlock(jblock.get(0));
        }
    });

    // add this if you need crayon compatible mode
    jQuery('pre:not(:has(code))').each(function(i, block){
        var class_desc = jQuery(block).attr("class") || "";
        var reg_mat = class_desc.match(/lang\s*:\s*([\w\d]+)/i);
        var code_content = jQuery("<code class='hljs'></code>").html(jQuery(block).removeAttr('class').html());
        if (reg_mat && reg_mat.length >= 2) {
            code_content.addClass(reg_mat[1]);
        }
        jQuery(block).empty().append(code_content);
        hljs.highlightBlock(block);
    });
});
</script>

If you use ES6 API instead of jQuery, you can also use window.addEventListener('DOMContentLoaded', () => { ... }); to replace jQuery(function(){ ... });, document.querySelectorAll("...") to replace jQuery selector, use forEach((block) => {...}) to replace jQuery.each(function(i, block) {...}) and etc.

owent avatar Oct 27 '19 08:10 owent