Mojo Code Blocks in Quarto
Quarto
Mojo code blocks with syntax highlighting in Quarto.
Abstract
How to use Mojo within Quarto to display syntax highlighted code.
Keywords
Quarto, Mojo, Syntax Highlighting, Code Block
Mojo Code Blocks in Quarto
To get mojo executing inside of a quarto QMD file.
- Install Modular’s Mojo/Max which includes the mojo-max-jupyter-kernel 1
Note
Verification: A good way to verify your intstallation within your VS Code Quarto project is to create a Jupyter notebook (mynotebook.ipynb) and verify that you can select the Mojo(Max) kernel.
- Inside your Quarto .qmd file’s front matter add:
jupyter: mojo-max-jupyter-kernel
- Declare a code block
Code
fn greet(name: String) -> String:
return "Hello " + name + "🔥"
print(greet("Mojo"))
Mojo syntax highlighting
Quarto doesn’t come with mojo syntax highlighting by default. You need to add it.
- Add the mojo.xml syntax definition file to your project.
- Add the following syntax-definition reference to the front matter of your qmd file or globally in your _quarto.yml
html:
code-fold: true
theme: slate
syntax-definitions:
- mojo.xml
Your mojo code should now be syntax highlighted like mine is.
Footnotes
https://docs.modular.com↩︎