mastosan

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2024 License: CC0-1.0 Imports: 9 Imported by: 0

README

mastosan

Package mastosan takes Mastodon flavored HTML and emits Slack-flavored markdown.

It works by using an embedded Rust program compiled to WebAssembly. At the time of writing this adds an extra 0.2 seconds to compile and run the WebAssembly module, but this can probably be fixed with aggressive sync.Once caching should this prove a problem in the real world.

Building this Rust program outside of Nix flakes is UNSUPPORTED.

To build the Rust module from inside the Nix flake:

cargo install wasm-snip
cargo build --release
wasm-opt -Oz -o ./testdata/mastosan-pre-snip.wasm
wasm-snip --skip-producers-section --snip-rust-panicking-code --snip-rust-fmt-code -i ./testdata/mastosan-pre-snip.wasm ./testdata/mastosan.wasm
rm ./testdata/mastosan-pre-snip.wasm

This adds about two megabytes to the resulting binary, including the AOT WebAssembly runtime wazero: https://wazero.io/

Documentation

Overview

Package mastosan takes Mastodon flavored HTML and emits Slack-flavored markdown.

It works by using an embedded Rust program compiled to WebAssembly. At the time of writing this adds an extra 0.2 seconds to compile and run the WebAssembly module, but this can probably be fixed with aggressive sync.Once caching should this prove a problem in the real world.

Building this Rust program outside of Nix flakes is UNSUPPORTED.

To build the Rust module from inside the Nix flake:

cargo install wasm-snip
cargo build --release
wasm-opt -Oz -o ./testdata/mastosan-pre-snip.wasm
wasm-snip --skip-producers-section --snip-rust-panicking-code --snip-rust-fmt-code -i ./testdata/mastosan-pre-snip.wasm ./testdata/mastosan.wasm
rm ./testdata/mastosan-pre-snip.wasm

This adds about two megabytes to the resulting binary, including the AOT WebAssembly runtime wazero: https://wazero.io/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Markdown

func Markdown(ctx context.Context, text string) (string, error)

Markdown converts a string with HTML content into an approximation of plain text.

Internally this works by taking that HTML and piping it to a small Rust program using lol_html to parse the HTML and rejigger it into generic markdown.

func Slackdown

func Slackdown(ctx context.Context, text string) (string, error)

Slackdown converts a string full of HTML text to slack-flavored markdown.

Internally this works by taking that HTML and piping it to a small Rust program using lol_html to parse the HTML and rejigger it into slack-flavored markdown.

func Text

func Text(ctx context.Context, text string) (string, error)

Text converts a string with HTML content into an approximation of plain text.

Internally this works by taking that HTML and piping it to a small Rust program using lol_html to parse the HTML and rejigger it into plain text.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL