CS Moodle

 
 
Picture of Tony Allevato
Change in <pre> tag handling on assignment write-ups and other pages
by Tony Allevato - Thursday, May 24, 2012, 1:34 PM
 

We've changed the way that <pre> tags are handled on Moodle web pages to make them a lot more useful.

Since most instructors use those tags to put code snippets in assignment write-ups, we're now using a little JavaScript/CSS magic to replace those blocks with a read-only syntax-highlighting editor, thanks to CodeMirror. Now you no longer have to use your own CSS to color those code snippets.

This should work on legacy assignment write-ups without any changes -- any of the inline span-tags that you were using to color the code before will be stripped out automatically.

By default, the injector assumes that the contents of any pre-tag are Java code. If you want to use a different language, add a data-lang="..." attribute to your pre-tag, where the value of the attribute is the MIME type of the content (or "text/plain" for no highlighting). For example:

<pre data-lang="text/x-haskell">
type Bag a = [(a, Int)]
</pre>

The appropriate MIME types for your favorite language can be found by clicking on that language from CodeMirror's main site.

E-mail me or Steve if you notice any problems with this new feature.

 
Picture of Stephen Edwards
Re: Change in <pre> tag handling on assignment write-ups and other pages
by Stephen Edwards - Thursday, May 24, 2012, 2:35 PM
 
How do you turn off line numbers? (They are usually good in code, but sometimes unnecessary.)
Picture of Tony Allevato
Re: Change in <pre> tag handling on assignment write-ups and other pages
by Tony Allevato - Thursday, May 24, 2012, 3:21 PM
 
Do we want line numbers to be on by default or not?

Either way, let's identify a CSS class that we want to use for this, and then we can pass something to the effect of lineNumbers: $(codeNode).hasClass("foo") or the inverse of that into the hash that creates the editor.
Picture of Stephen Edwards
Re: Change in <pre> tag handling on assignment write-ups and other pages
by Stephen Edwards - Friday, May 25, 2012, 9:05 AM
 
Yes, I think line numbers should be on by default.

Maybe two classes: lineNumbers to request them, and noLineNumbers to turn them off, with the default being on.

... [edit] Now implemented.