Moodular -- author learning materials for Moodle using Typst (also: relevant tooling coming soon!)

Moodular (Github) is my new package for writing assignments and other learning resources for Moodle courses. To do so, it basically fulfills three requirements:

  • It transforms some Typst elements into the HTML form expected by Moodle. For example, it would replace #image("example.png") by (roughly) <img src="@@PLUGINFILE@@/example.png">, which is the form in which Moodle refers to attachments uploaded in its rich text editor plugins.

  • It styles the Typst document so that it looks similar to how the Moodle resource would look in the browser, so that you can use the web app or Tinymist for preview. For example, blockquotes (#quote(block: true)[...]) look similar to those here on the forum, with a grey left border:

    …

    The ability to fairly accurately preview the Moodle appearance means that you can also use Moodular for targeting both Moodle and PDF with your materials.

  • It implements the Components for Learning (C4L) library, which gives you a toolkit for presenting your material. When targeting HTML, they result in equivalent markup to the official C4L Moodle plugins; when targeting PDF, they still look almost exactly the same.

If you’re interested, the README (on Universe or Github) and the manual contain more information.

Example

As a teaser, this is how Moodular’s preview of a C4L “key concept” as well as a code block look:

thumbnail

And here is a screenshot of the same document, pasted into and rendered by Moodle:

Moodular rendered by Moodle

These examples were both created from this code:

#import "@preview/moodular:0.1.0" as moodular: c4l

#show: moodular.preview()

#c4l.key-concept[#lorem(20)]

```py
print("Hello, world!")  # this is an example
```

Tooling

This is not open sourced yet, but stay tuned for some related tooling! Copy-pasting HTML into Moodle’s web interface isn’t fun although arguably better than actually writing in it. I have therefore created two more puzzle pieces that I hope to release soon:

  • a Moodle plugin that provides web API endpoints for editing common activity types. (It’s already fairly outdated again, but here’s a blog post on my first steps with this.) This plugin needs to be installed server side, so it unfortunately needs buy-in from you Moodle server admin.

  • a Python CLI tool that reads activity metadata from a yaml file, or queries it directly from your Typst file, and then does the rest for you: upload images, compile your Typst document as HTML, and update your Moodle activities via the web API.

Both of these are practically ready, I just need to make sure they are fit for public consumption.


I’m looking forward to spending less time in the Moodle web UI when creating learning materials and exercises, and I hope some of you can relate or are interested as well. Thanks for reading :slight_smile:

6 Likes