print("Hello World!")
print(3 + 2)
Hello World!
5
February 20, 2024
.qmd
files are files special to quarto. The short version of it is that quarto renders these files, which are essentially markdown files, to jupyter notebooks, where it then executes and renders any python code.
Quarto is designed for data science, and this means having executable code blocks that do something. For example, Quarto can use matplotlib in python to plot things.
Where things get interesting is the combination of three factors:
#| output: asis
at the beginning of the code block.#| echo: false
at the beginning of the code block itselfWhat this means, is that python can essentially act as a formatting engine, for generating dynamic content. Even things like using.
#| output: asis
#| echo: false
def make_bullets(list):
bulletlist = f''''''
for i in list:
bulletlist = bulletlist + "* "
bulletlist = bulletlist + i
bulletlist = bulletlist + "\n"
print(bulletlist)
sample_list = [
"Item 1",
"Item 2",
"Item 3"
]
make_bullets(sample_list)
Which renders to:
It should be noted that I am actually using two code blocks here, one which does not execute, and does not hide itself, and another which executes and hides itself.
You can get even more dynamic content, if you use something like python requests to pull it as you render the site. Again, it is a bit hacky since backticks would render into a code block, so here I multiply one backticks times 3 to get a string containing 3 backticks, but it does work.
#| output: asis
#| echo: false
import requests
backticks = "`" * 3
print(f'''
{backticks}{{.nix .code-overflow-wrap filename=home.nix}}
{requests.get('https://raw.githubusercontent.com/ErikMcClure/bad-licenses/3c26bef3028fa8470308c493af7d7eae152a19ba/overwatch').text}
{backticks}
''')
home.nix
Overwatch License Revision 2
(c) Author, year
Permission is hereby granted, free of charge, for anyone to use, distribute, or
sell the compiled binaries, source code, and documentation (the "Software")
without attribution.
Permission to modify the Software is only granted to those that have a higher
competitive matchmaking rank than the copyright holder in Overwatch 2
(Blizzard, 2022).
The Software is provided in the hope that some will find it useful, but the
Software comes under NO WARRANTY, EXPRESS OR IMPLIED, and the authors of the
Software are NOT LIABLE IN THE EVENT OF LOSSES, DAMAGES OR MISUSE relating to
the Software.