We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22840
    • 1,572 Posts
    Hi All,

    Currently writing some tutorials and I really need to be able to display code within my pages output and display calls to the likes of wayfinder etc.

    Is there anything like this for Revolution or something that could be plugged in to achieve it ??

    Thanks
      • 25663 MODX Staff
      • 12,272 Posts
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 14883 ☆ A M B ☆
        • 450 Posts
        Nice.

        I wish I’d known about this before I wasted a day wrestling with regex to achieve the same thing.
          • 22840
          • 1,572 Posts
          Thanks Ryan,

          I’ve created the plugin and added the 3 events ( although site says 2 ) and the page is outputting the code however there is no formatting to it ( I also added the class of php to the code tag ). Looking at the source code on Garry’s site each element has a class, is that something that has to be added manually ??
            • 22840
            • 1,572 Posts
            Right I managed to sort it by wrapping it in a pre,

            Think i’ll do a background image for it now so it adds line numbers grin
              • 10487 MODX Staff
              • 1,535 Posts
              Glad you got it working smiley Let me know if you have any problems with it - I’ve tested the plugin quite a lot on the modx360 blog so hopefully it should work with pretty much any code samples you throw at it.

              BTW, thanks for noting the event typo on the post - I’ve now corrected that. And, now I’ve fixed the spam problem with my comments, I think I’m close to an official blog launch smiley
                Garry Nutting
                Senior Developer
                MODX, LLC

                Email: [email protected]
                Twitter: @garryn
                Web: modx.com
                • 22840
                • 1,572 Posts
                No Problems Garry,

                One thing I can’t get working is the colours, If I add the spans in the code it is rendering them as the code and displaying them. How did you get the colours to work and it not render the spans ??
                  • 10487 MODX Staff
                  • 1,535 Posts
                  I used highlight.js on my site. Pretty simple to install and has several themes to choose from.

                  It’s fairly simple to get going, but I did find that I have to explicitly specify the class for the <code> tags. So, for example, in my <head> section of my template, I included the files as follows (once I’d copied them to my install):
                  <link href="assets/js/highlight/styles/zenburn.css" rel="stylesheet" type="text/css" />
                  <script type="text/javascript" src="assets/js/highlight/highlight.pack.js"></script>
                  <script type="text/javascript">
                  	hljs.initHighlightingOnLoad('php,html,css,sql');
                  </script>

                  Basically, that initializes highlight.js and sets what code formats hightlight.js will recognize and which CSS theme to use.

                  Then, when adding code tags, I add a CSS class that highlight.js can hook on to:
                  <pre>
                  <code class="php">
                  ... code here ...
                  </code>
                  </pre>
                  

                  Strictly speaking, the CSS class shouldn’t be required but I found that highlight.js didn’t always highlight correctly unless I added it explicitly.

                  Hope that helps (and makes sense)!
                    Garry Nutting
                    Senior Developer
                    MODX, LLC

                    Email: [email protected]
                    Twitter: @garryn
                    Web: modx.com
                    • 22840
                    • 1,572 Posts
                    Thanks Garry,

                    I’ll give it a try after work grin
                      • 22840
                      • 1,572 Posts
                      Works great Garry, Thank you