Greg Chapman

Displaying Code in WonderCMS

There's a Trick to It

You could say that WonderCMS will treat as code anything entered on a page that looks like code. As I wanted to show a number of code fragments in the WonderCMS section of the site, I needed to find a work around for that behaviour. Eventually, with the help of ChatGPT, I came up with the solution outlined below.

Perhaps I phrased the problem poorly as, initially, ChatGPT tried to come up with a JavaScript routine that would achieve my aim. After a few of its attempts, I mentioned something that made it realise that a large part of the solution was to place any code I wanted to display within "textarea" tags.

It suggested some CSS code, which I then tweaked a little to get to appear as I wanted, and added it to my copy of style.css. The code looks like this:

That code alone didn't work prettily for all cases so ChatGPT then suggested a JavaScript routine that calculated an appropriate height for the textarea element. This I added to the bottom of my theme.php file.

The result can be seen on this page, and everywhere else that code fragments appear on the site. All you do to get a code fragment to appear is to wrap it in the tags below: