How to embed HTML content into a typst document?

In our web application, we have WYSIWYG text editor fields. The content of the text editor is stored as HTML, for example:

<div class="ql-editor read-mode">
	<p>Spezifikation: 8 Stunden Rechenzeit pro Monat; 4 GB Datenbank; 25 GB Speicherplatz für Anhänge.</p>
	<p><br></p>
	<p>Beinhaltet <strong>Hosting und Second-Level-Support</strong>.
		First-Level-Support, Bugfixes und Wartungsarbeiten werden separat nach Aufwand berechnet. Es
		gelten die Nutzungsbedingungen und die Datenschutzerklärung:</p>
	<p><a href="https://example.org/terms" rel="noopener noreferrer">https://example.org/terms</a> / <a
			href="https://example.org/privacy" rel="noopener noreferrer">https://example.org/privacy</a></p>
</div>

Now in typst, I would like this text to show up in a table cell, with the appropriate formatting (at least for basic elements like p, strong, br or a).

Is there any way to achieve this, apart from writing my own html-to-typst converter?

Hi @Raffael and welcome to the forum!

To clarify what you want to achieve, are you asking if there are HTML parsers written in typst, or if there is an easy way to convert HTML to typst code? If it’s the latter, I suggest using pandoc

Thanks for the quick reply.

To rephrase, I’m looking for a way to use our existing HTML content when creating PDFs with typst. E.g. I want to create invoice PDFs, but all my existing item descriptions are stored as HTML. What is the easiest way to still print them, without losing the markup?

Pandoc looks promising, I’ll give that a try!

Yeah so in that case probably use pandoc. You could make some sort of script to automate this task and #include the converted file into the main invoice file which would probably reduce errors. AFAIK there are no HTML parsers written in typst so external tools are the way to go

1 Like

Hello @Raffael, I’ve renamed your topic to “How to embed a HTML file into a typst document?”, don’t hesitate to read through How to post in the Questions category.

1 Like