Insert formatted code block

Some units have a business need to format code (such as programming languages) so that it is readable in the frontend, such as documenting student use of research software or scientific languages (R, MATLAB, for example). This plugin does not enable the author to insert arbitrary HTML, Javascript or CSS into the page.

The display of the Formatted Code content type uses a white text on black background theme, displays the selected language, and includes a "Copy" button to aid the visitor in reuse of the code snippet. The appearance of the code block is not configurable by the author.

To insert formatted code,

  1. Insert a new content element in the desired location
  2. Select Special elements > Formatted Code
  3. Select the appropriate Language.
    Enabled languages include Bash, Java, JavaScript, JSON, LaTeX, MATLAB, PHP, R, SAS, SQL, and a generic "C-like" choice for other languages that use a C-like syntax
  4. Paste the code block into the Code field. Note there is NOT an editor--no syntax highlighting, linting, or other code checks are performed by CMS in the backend
  5. Save and publish as usual

Bash code example

#!/bin/bash

for i in {1..12}
do
    for j in {1..12}
    do
        printf '%dx%d=%-2d  ' "$i" "$j" "$(( i * j ))"
    done
    printf '\n'
done

MATLAB code example

t = 0:pi/10:2*pi;
[X,Y,Z] = cylinder(4*cos(t));
subplot(2,2,1); mesh(X); title('X');
subplot(2,2,2); mesh(Y); title('Y');
subplot(2,2,3); mesh(Z); title('Z');
subplot(2,2,4); mesh(X,Y,Z); title('X,Y,Z');
Top of page