Here's a quick way to add syntax highlighting to code blocks in the monastery:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/hi +ghlight.js/11.7.0/styles/base16/one-light.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7. +0/highlight.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7. +0/languages/perl.min.js"></script> <script> window.addEventListener( "DOMContentLoaded", ( event ) => { hljs.configure( { cssSelector: '.codeblock .codetext font', languages: new Array( 'perl', 'html', 'css', 'xml', 'json', 'yam +l', 'diff' ), } ); hljs.highlightAll(); /* If you use the free nodelet for only Javascript/CSS, * and not as a display area, then you can uncomment * the next line of Javascript. */ // document.getElementById( 'Free_Nodelet' ).display.style = 'none'; } ); </script> <style> .codeblock .codetext font { white-space: pre; display: block; padding: 0.5rem; margin: 0.5rem 1rem 0.5rem 0; border: 1px solid #ccc; border-radius: 0.125rem; } </style>

You may want to double-check the CSS selector used because I think this may differ based on other settings you've chosen.

Also, you may wish to choose a different colour scheme. highlight.js (the syntax highlighter used) comes with a huge variety of colour schemes. Scroll down to the bottom of this page to find URLs for other options. (And previews are here.)


In reply to Free Nodelet hack for syntax highlighting by tobyink

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.