Giter Club home page Giter Club logo

Comments (5)

owent avatar owent commented on August 19, 2024

There is a secure problem in this plugin. (see #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.

from wp-code-highlight.js.

giggio avatar giggio commented on August 19, 2024

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

from wp-code-highlight.js.

owent avatar owent commented on August 19, 2024

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.

from wp-code-highlight.js.

giggio avatar giggio commented on August 19, 2024

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

from wp-code-highlight.js.

owent avatar owent commented on August 19, 2024

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.

from wp-code-highlight.js.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.