p

percencode

@preview

Work with percent-encoding used by web browsers to encode URLs.

v0.1.0
MIT

Package Information

Last Updated
Authors
Sven Vogel
Categories
scriptingutility

1. Get the package

Download the package using the TPIX CLI:

tpix get @preview/percencode:0.1.0

2. Import in your Typst file

Add this to your .typ file:

#import "@preview/percencode:0.1.0": *

Version History

0.1.0
bd8c7ca8cf84...

Percent Encoding

GitHub License
GitHub Release
GitHub

This Typst library offers function for encoding and decoding percent escape sequences.
These are typically used to encode unsafe or non-ASCII characters in URLs.
Supported by this library is only Typst's native character encoding and defacto web standard: UTF-8.

Read the manual for further information.

Usage

You can directly import the package from Typst universe:

#import "@preview/percencode:0.1.0": *

Example

Sanitize URLs

The method url-encode can be used to escape unsafe characters (as in RFC 2396) in URL strings.

Example:

https://example.com/how much is 23€ wörth?

Results in:

https://example.com/how%20much%20is%2023%E2%82%AC%20w%C3%B6rth?

Encoding

Encode an entire string:

#percent-encode("Hello, World!")

Results in:

%48%65%6C%6C%6F%2C%20%57%6F%72%6C%64%21

Decoding

Decode an entire string:

#percent-decode("%48%65%6C%6C%6F%2C%20%57%6F%72%6C%64%21")

Results in:

Hello, World!

(c) 2025 Sven Vogel. Some right reserved.