markdown

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 14 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

📝 markdown — Markdown to HTML for Starlark

Go Reference codecov binary footprint

Convert Markdown to HTML from Starlark, built on goldmark. CommonMark-compliant with opt-in extensions (tables, task lists, strikethrough, autolinks, footnotes, definition lists, typographer, emoji) and configurable rendering (hard wraps, auto heading IDs).

Overview

This is a starpkg module: starpkg provides support for necessary local operations plus simple abstractions over common online services, for ease of use. Markdown rendering is a purely local capability — it runs entirely in-process (no network, no filesystem), so a script can turn untrusted Markdown into HTML without reaching out to anything.

  • Two builtins — convert renders in one call; create_converter builds a reusable converter with rendering options frozen in.
  • Secure by default — raw HTML in the source is filtered out unless you opt in with unsafe=True, and renderer panics are recovered into errors.
  • Bounded work — a max_input_bytes cap rejects oversized input before it reaches the renderer, and a max_convert_time cap bounds a single conversion's wall-clock time (goldmark's nested parsing is ~O(n²), so an input under the byte cap can still spin). Both are host-only.

For the complete per-builtin reference — signatures, parameters, returns, errors, examples — and the configuration accessors, see docs/API.md.

Installation

go get github.com/starpkg/markdown

Go floor: this module requires Go 1.22+. It tracks the latest goldmark (no downgrade) for upstream security and correctness fixes; the recent goldmark releases raise their own Go floor, so this module relaxes its floor to match (per ENG-09 SEP — a module may raise its floor when a dependency requires it, like the email module).

Quickstart

Wire the module into a Starlet interpreter, then load("markdown", …) from a script:

package main

import (
    "fmt"

    "github.com/1set/starlet"
    "github.com/starpkg/markdown"
)

func main() {
    mod := markdown.NewModule()
    interpreter := starlet.NewWithLoaders(nil, nil, starlet.ModuleLoaderMap{
        "markdown": mod.LoadModule(),
    })

    script := `
load("markdown", "convert")
html = convert(text="# Hello World\n\nThis is **bold** text.")
print(html)
`
    if _, err := interpreter.RunScript([]byte(script), nil); err != nil {
        fmt.Printf("Error: %v\n", err)
    }
}

From Starlark, render in one call or build a reusable converter:

load("markdown", "convert", "create_converter")

# One-shot conversion.
html = convert(text="# Hello World\n\nThis is **bold** text.")
print(html)
# <h1 id="hello-world">Hello World</h1>
# <p>This is <strong>bold</strong> text.</p>

# Reusable converter with preset options.
to_html = create_converter(table=False, linkify=False, hard_wraps=True)
print(to_html("# Title\n\nFirst line\nSecond line"))

Starlark API at a glance

Top-level builtins (load("markdown", …)):

  • convert(text, unsafe?, heading_id?, linkify?, table?, task_list?, strikethrough?, footnote?, definition?, typograph?, emoji?, hard_wraps?) — render Markdown to HTML in one call (text accepts string / bytes / None).
  • create_converter(unsafe?, heading_id?, linkify?, table?, task_list?, strikethrough?, footnote?, definition?, typograph?, emoji?, hard_wraps?) — build a reusable custom_converter with options frozen in.

Converter object:

  • custom_converter(text) — the callable returned by create_converter; renders a Markdown string with the preset options (no further keywords).

Configuration accessors:

  • get_max_input_bytes() — read the input-size cap. Host-only: set_max_input_bytes is intentionally not exposed, so a script cannot disable or widen the DoS limit — only the host can, in Go or via the env var.
  • get_max_convert_time() — read the per-conversion wall-clock time cap (seconds; 0 = no module limit). Also host-only: no set_max_convert_time.

See docs/API.md for the full signatures, return values, errors, the shared rendering-option table, and examples of every builtin above.

Configuration

The module's options — max_input_bytes (input size) and max_convert_time (per-conversion wall-clock time; goldmark's nested parsing is ~O(n²) so size alone doesn't bound CPU) — are both host-only, configured via the MARKDOWN_MAX_INPUT_BYTES / MARKDOWN_MAX_CONVERT_TIME environment variables or the Go host (a script can read them with get_max_input_bytes but cannot change it — set_max_input_bytes is not generated). See the Configuration section of docs/API.md for the full option table, default, accessors, and details.

License

This project is licensed under the MIT License — see the LICENSE file for details.

Documentation

Overview

Package markdown provides a Starlark module for converting markdown to HTML.

Index

Constants

View Source
const ModuleName = "markdown"

ModuleName defines the expected name for this module when used in Starlark's load() function, e.g., load('markdown', 'convert')

Variables

This section is empty.

Functions

This section is empty.

Types

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module wraps the ConfigurableModule with specific functionality for markdown conversion.

func NewModule

func NewModule() *Module

NewModule creates a new instance of Module with default configurations.

func (*Module) LoadModule

func (m *Module) LoadModule() starlet.ModuleLoader

LoadModule returns the Starlark module loader with markdown-specific functions.

Jump to

Keyboard shortcuts

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