Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter alanzucconi

    (@alanzucconi)

    For anyone who is interested, I finally took some time to make a quick WordPress plugin that converts Crayon Syntax Highlighter inline code to Enlighter. This way, I could deactivate Crayon for good!

    If you are unfamiliar with plugin development, just put the following code in a PHP file in wp-content/plugins/crayon-to-enlighter/crayon-to-enlighter.php. It should be automatically recognised as a plugin by WordPress which you can enabled.

    It does not alter your posts, so it can be safely disabled without any permanent change being made. It is far from perfect, but I have not have any issue (and I have hundreds of posts using both Crayon and Enlighter heavily).

    Let me know if you have any suggestion/improvement!

    <?php
       /*
       Plugin Name: Crayon to Enlighter
       Plugin URI: 
       Description: A plugin that converts inline code from Crayon Syntax Highlighter to Enlighter format.
       Version: 1.0
       Author: Alan Zucconi
       Author URI: https://www.alanzucconi.com/
       License: 
       */
    
       // Crayon inline code:
       // <span class="lang:c# decode:true crayon-inline">xxx</span>
       //
       // Enlighter inline equivalent code:
       //
       // <code data-enlighter-language="csharp" class="EnlighterJSRAW">float[] Xs</code>
       add_filter('the_content',
          function($content)
          {
             // crayon filter regex
             $regex = 
                // <span class="lang:c# decode:true crayon-inline">xxx</span>
                '/<span\s+class="lang:([a-z#+]+?)\s+decode:true\s+crayon-inline\s*"\s*>' .
    
                // content of the span tag
                // (+? captures as little as possible)
                '(.+?)' .
    
                // closing tag
                '<\/span>' .
             
                // case insensitive, multiline
                '/im';
    
             // <code data-enlighter-language="csharp" class="EnlighterJSRAW">xxx</code>
             $replacement = '<code data-enlighter-language="${1}" class="EnlighterJSRAW">${2}</code>';
    
             return preg_replace($regex, $replacement, $content);
          },
       1);
    
    ?>
    Thread Starter alanzucconi

    (@alanzucconi)

    Yes, I can confirm that the “inline” option is officially supported by Crayon.
    You can see in this screenshot here (from the plugin page) that there is an “Inline” checkbox at the very top right.

    It does not add any “pre” or “code” tag, but wraps the selected text into a span with class: ”lang:c# decode:true crayon-inline”.

    This is a page in which I have used the inline function extensively.

    Unfortunately I am not experienced enough with plugin development to point you towards the Crayon file where the inline functionality is actually implemented.

    It would be pretty handy if Enlighter could support this: it appears to be the last unsupported Crayon functionality, and I imagine there must be other people with a similar need.

    If you need any additional information, I would be happy to help!

    Thread Starter alanzucconi

    (@alanzucconi)

    Thank you Ani, that was such an incredibly fast reply!

    Would you be able to point me towards some resources for the conversion filter you mentioned? I have not done anything like that before, so any advice would be very appreciated!

    Thread Starter alanzucconi

    (@alanzucconi)

    Yes, it was indeed a ModSecurity issue.

    [Wed May 25 17:46:23 2016] [error] [client 82.69.229.6] ModSecurity: Access denied with redirection to https://www.alanzucconi.com/ using status 302 (phase 2). Matched phrase “/etc/ld.so.conf” at ARGS:content. [file “/usr/local/apache/conf/modsec_vendor_configs/OWASP/rules/REQUEST-30-APPLICATION-ATTACK-LFI.conf”] [line “29”] [id “950005”] [rev “4”] [msg “OS File Access Attempt”] [data “Matched Data: /etc/ld.so.conf found within ARGS:content: sudo nano /etc/ld.so.conf.d/caffe.conf”] [severity “CRITICAL”] [ver “OWASP_CRS/3.0.0”] [maturity “9”] [accuracy “9”] [tag “Host: https://www.alanzucconi.com”%5D [tag “application-multi”] [tag “language-multi”] [tag “platform-multi”] [tag “attack-local file inclusion”] [tag “OWASP_CRS/WEB_ATTACK/FILE_INJECTION”] [tag “WASCTC/WASC-33”] [tag “OWASP_TOP_10/A4”] [tag “PCI/6.5.4”] [hostname “www.alanzucconi.com”] [uri “/wp-admin/post.php”] [unique_id “V0XIzy78lWUADiUVSZsAAAAM”]

    Thank you very much for the support! <3

    Thread Starter alanzucconi

    (@alanzucconi)

    I’ve contacted Netsons, which is hosting the website.
    I’ll let you know their answer (and if it worked) very soon.

    Thread Starter alanzucconi

    (@alanzucconi)

    Yes, and unfortunately I am still experiencing this issue.
    I have tried to:
    * Purge cache and history from Chrome
    * Using Incognito Mode
    * Using Internet Explorer
    The issue still persists.

    Thread Starter alanzucconi

    (@alanzucconi)

    Hi sterndata, thank you so much for your fast reply.

    Unfortunately even wit all the plugins disabled AND the twentysixteen theme, the issue is still there. It has also affected old posts, leading me to believe it could be related to WordPress 4.5.1 or 4.5.2.

    This is a GIF of the issue I am experiencing. The first time I hit Preview, it works. The second time, it just opens a tab with the main page.

    I have enabled debug in wp-config.php, but got no relevant information.

Viewing 7 replies - 1 through 7 (of 7 total)