feat: initial commit

This commit is contained in:
johannes committed 2026-07-26 11:45:12 +02:00
commit 4b3cd1d2b1
453 files changed
+52428

No files matched your search

@@ -0,0 +1,42 @@
# Elem
# html.elem
An HTML element that can contain Typst content.
Typst's HTML export automatically generates the appropriate tags for most elements. However, sometimes, it is desirable to retain more control. For example, when using Typst to generate your blog, you could use this function to wrap each article in an `<article>` tag.
Typst is aware of what is valid HTML. A tag and its attributes must form syntactically valid HTML. Some tags, like `meta` do not accept content. Hence, you must not provide a body for them. We may add more checks in the future, so be sure that you are generating valid HTML when using this function.
Normally, Typst will generate `html`, `head`, and `body` tags for you. If you instead create them with this function, Typst will omit its own tags.
```typst
#html.elem("div", attrs: (style: "background: aqua"))[
A div with _Typst content_ inside!
]
```
```typst
#html.elem(
tag,
attrs: dictionary,
body
) -> content
```
## Parameters
- tag:
- description: The element\'s tag.
- type: str
- default: None
- attrs:
- description: The element\'s HTML attributes.
- type: dictionary
- default: (:)
- body:
- description: The contents of the HTML element. The body can be arbitrary Typst content.
- type: none | content
- default: none
@@ -0,0 +1,24 @@
# Frame
# html.frame
An element that lays out its content as an inline SVG.
Sometimes, converting Typst content to HTML is not desirable. This can be the case for plots and other content that relies on positioning and styling to convey its message.
This function allows you to use the Typst layout engine that would also be used for PDF, SVG, and PNG export to render a part of your document exactly how it would appear when exported in one of these formats. It embeds the content as an inline SVG.
```typst
#html.frame(
body
) -> content
```
## Parameters
- body:
- description: The content that shall be laid out.
- type: content
- default: None
@@ -0,0 +1,42 @@
# HTML
> Typst's HTML export is currently under active development. The feature is still very incomplete and only available for experimentation behind a feature flag. Do not use this feature for production use cases. In the CLI, you can experiment with HTML export by passing `--features html` or setting the `TYPST_FEATURES` environment variables to `html`. In the web app, HTML export is not available at this time. Visit the [tracking issue](https://github.com/typst/typst/issues/5512) to follow progress on HTML export and learn more about planned features.
HTML files describe a document structurally. The aim of Typst's HTML export is to capture the structure of an input document and produce semantically rich HTML that retains this structure. The resulting HTML should be accessible, human-readable, and editable by hand and downstream tools.
PDF, PNG, and SVG export, in contrast, all produce _visual_ representations of a fully-laid out document. This divergence in the formats' intents means that Typst cannot simply produce perfect HTML for your existing Typst documents. It cannot always know what the best semantic HTML representation of your content is.
Instead, it gives _you_ full control: You can check the current export format through the [`target`](/docs/reference/foundations/target/) function and when it is set to HTML, generate [raw HTML elements](/docs/reference/html/elem/). The primary intended use of these elements is in templates and show rules. This way, the document's contents can be fully agnostic to the export target and content can be shared between PDF and HTML export.
Currently, Typst will always output a single HTML file. Support for outputting directories with multiple HTML documents and assets, as well as support for outputting fragments that can be integrated into other HTML documents is planned.
Typst currently does not output CSS style sheets, instead focussing on emitting semantic markup. You can of course write your own CSS styles and still benefit from sharing your _content_ between PDF and HTML. For the future, we plan to give you the option of automatically emitting CSS, taking more of your existing set rules into account.
## Exporting as HTML
### Command Line
Pass `--format html` to the `compile` or `watch` subcommand or provide an output file name that ends with `.html`. Note that you must also pass `--features html` or set `TYPST_FEATURES=html` to enable this experimental export target.
When using `typst watch`, Typst will spin up a live-reloading HTTP server. You can configure it as follows:
- Pass `--port` to change the port. (Defaults to the first free port in the range 3000-3005.)
- Pass `--no-reload` to disable injection of a live reload script. (The HTML that is written to disk isn't affected either way.)
- Pass `--no-serve` to disable the server altogether.
### Web App
Not currently available.
## HTML-specific functionality
Typst exposes HTML-specific functionality in the global `html` module. See below for the definitions it contains.
## Definitions
| Name | Description |
| --- | --- |
| [`elem`](/reference/html/elem/) | An HTML element that can contain Typst content. |
| [`frame`](/reference/html/frame/) | An element that lays out its content as an inline SVG. |
| [`typed`](/reference/html/typed/) | A typed layer over raw HTML elements. |
File diff suppressed because it is too large. Load diff