The page is written in TapirMD (source is available here).
TapirMD official maintains libraries for Zig, WebAssembly (WASM), JavaScript, and Go.
The Zig library is fully featured, while the others currently support only HTML generation (from TapirMD documents) and TapirMD document formatting.
To use the library, the TapirMD dependency entry should be put in the build.zig.zon file of your Zig project. It is recommended to choose a tagged version as the dependency. The following example uses the v0.0.5 version tag.
...
.tmd = .{
.url = "https://github.com/tapirmd/tmd/archive/refs/tags/v0.0.5.zip",
},
...
The library provides a tmd module which can be imported into the modules of your Zig project.
...
const tmdModule = b.dependency("tmd", .{
.target = target,
.optimize = optimize,
}).module("tmd");
...
myModule.addImport("tmd", tmdModule);
...
The steps to build the TapirMD WASM library:
-
Install
Zig, if haven't. The latest version tip (master) version is recommended.
-
-
Open your terminal or command prompt, and change directory to the TapirMD project folder, then run
zig build -Doptimize=ReleaseSmall wasm
If the build is successful, the output tmd.wasm binary file will be located in the lib folder under the project local zig-out folder.
The output
tmd.wasm binary file can be used in various languages. The official TapirMD
JavaScript and
Go libraries are both built upon WASM.
The WASM binary file exports several APIs:
-
lib_version returns the memory offset of the version string of the library. The version string is C-style string which ends with 0.
-
buffer_offset returns the memory offset of the buffer for communicating between WASM and host apps. The input TapirMD document content with a length header should be placed at the beginning of the buffer.
-
tmd_parse parses the input TapirMD document and returns the memory offset of unused buffer (for communicating between WASM and host apps). The following APIs should put their options data at the returned memory offset.
-
tmd_title generates the title (without any formatting elements) of the input TapirMD document and returns the memory offset of the title with a length header. If the title length is 0xFFFFFFFF, it means the input TapirMD document doesn't define a title.
-
tmd_to_html generates HTML content from the input TapirMD document content and returns the memory offset of the output HTML content with a length header.
-
tmd_format formats the input TapirMD document and returns the memory offset of the output formatted result with a length header. If the result length is 0xFFFFFFFF, it means the formatted result is identical to the input TapirMD document.
Every memory offset return result is a int32 value. A negative offset means an error and the memory offset of the error string (a C-style string) is the absolute value of the negative offset minus one.
Host apps should provide an env module which contains a print function. The print function takes 4 uint32 and one int32 parameters.
-
the 1st uint32 parameter means the memory offset of the first string.
-
the 2nd uint32 parameter means the length (in bytes) of the first string.
-
the 3rd uint32 parameter means the memory offset of the second string.
-
the 4th uint32 parameter means the length (in bytes) of the second string.
-
the final int32 parameter is just a plain integer value.
For implementation details, please reference the official TapirMD JavaScript and Go libraries (see below).
Currently, the official TapirMD JavaScript library can be only used in browser environments.
The steps to build the TapirMD JavaScript library:
-
Install
Zig, if haven't. The latest version tip (master) version is recommended.
-
-
Open your terminal or command prompt, and change directory to the TapirMD project folder, then run
zig build -Doptimize=ReleaseSmall js
If the build is successful, the output tmd-with-wasm.js file will be located in the lib folder under the project local zig-out folder.
Please read the source code of the
online play page to get how to use the JavaScript library.
The library repository includes an example demonstrating its usage.