python-markdown-typst
A Python Markdown extension that compiles typst fenced code blocks into inline SVG images.
Features
- Detects fenced code blocks labeled as
typstwithtypst-previewin the first line. - Compiles the Typst code into SVG format using the
typstcompiler.
Installation
pip install markdown-typst
Usage
import markdown
from markdown_typst.typst_extension import TypstExtension
md = markdown.Markdown(extensions=[TypstExtension()])
input_text = '''
# This is a markdown title
```typst
// typst-preview
// This is a simple Typst document
= This is a typst title
```
'''
html = md.convert(input_text)
with open('output.html', 'w') as f:
f.write(html)
It is recommended to use the following Typst code to set the page size and margins:
#set page(width: auto, height: auto, margin: .5cm)
Integrate Typst Rendering with MkDocs
To enable Typst syntax rendering in MkDocs, add the following lines to your mkdocs.yml:
markdown_extensions:
- typst
Example Usage
# Hello, typst
!!! note
!!! warning
```typst
// typst-preview
// Code from https://raw.githubusercontent.com/typst/packages/main/packages/preview/cetz/0.3.2/gallery/waves.typ
#import "@preview/cetz:0.3.2": canvas, draw, vector, matrix
#set page(width: auto, height: auto, margin: .5cm)
#canvas({
import draw: *
ortho(y: -30deg, x: 30deg, {
on-xz({
grid((0,-2), (8,2), stroke: gray + .5pt)
})
// Draw a sine wave on the xy plane
let wave(amplitude: 1, fill: none, phases: 2, scale: 8, samples: 100) = {
line(..(for x in range(0, samples + 1) {
let x = x / samples
let p = (2 * phases * calc.pi) * x
((x * scale, calc.sin(p) * amplitude),)
}), fill: fill)
let subdivs = 8
for phase in range(0, phases) {
let x = phase / phases
for div in range(1, subdivs + 1) {
let p = 2 * calc.pi * (div / subdivs)
let y = calc.sin(p) * amplitude
let x = x * scale + div / subdivs * scale / phases
line((x, 0), (x, y), stroke: rgb(0, 0, 0, 150) + .5pt)
}
}
}
on-xy({
wave(amplitude: 1.6, fill: rgb(0, 0, 255, 50))
})
on-xz({
wave(amplitude: 1, fill: rgb(255, 0, 0, 50))
})
})
})
```
Requirements
markdowntypst
License
MIT License
Metadata
Release files for markdown-typst 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| markdown_typst-0.1.4.tar.gz | 4.7 kB | Without provenance | Details for markdown_typst-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| markdown_typst-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for markdown_typst-0.1.4-py3-none-any.whl |
Total release size: 10.0 kB
Release files / markdown_typst-0.1.4.tar.gz
| Download URL | markdown_typst-0.1.4.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cbf2eebd893aadc4afe8d817ed5e380c2701edee6fdb23ee55445ed258c5aec7
|
|
BLAKE2b-256 checksum How to use checksums |
a8d57b6b463940bc1ed33c782b42c37911d5a45ab707120f9e5bea4009c9c02b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / markdown_typst-0.1.4-py3-none-any.whl
| Download URL | markdown_typst-0.1.4-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2badd071ffe884cc3a3275e616429912528272a76157cf7d2b4eef2f8ffeed1
|
|
BLAKE2b-256 checksum How to use checksums |
3d021711b46c2d8484306572e5adb1c0f5552f101ae4c36b5af3da699c31f814
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for markdown-typst 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.