Watch
1
0
Fork
You've already forked packages
0

packages/ at markup-kit dd1e6eb5270e

A snapshot of packages/ in the Weft repository; the official packages are published from these commits.

Markup-Kit-Commit: dd1e6eb5270e62e0c8b6c202b3d01f0da6e00ddc
This commit is contained in:
Weft packages 2026-11-19 20:43:26 +00:00
commit 306b143104
72 changed files with 10915 additions and 0 deletions

83
markdown/ast.weft Normal file
View file

@ -0,0 +1,83 @@
// The Markdown syntax tree and the options of every function in `@weft/markdown`.
/// A parsed document: its blocks, in order.
export type Document = { children: Block[] }
/// A table column's alignment, `null` when its delimiter row doesn't say.
export type Align = "left" | "center" | "right" | null
/// A block: what a document, a quote or a list item is made of.
///
/// - `CodeBlock`: `info` is the text after the opening fence (`""` for an indented block).
/// - `HtmlBlock`: raw HTML as written, rendered according to `Options.html`.
/// - `BulletList`, `OrderedList`: a `tight` list has no blank lines between its items; `start` is the first number.
/// - `Table`: a GFM table, with one cell per column in every row.
export type Block =
| Paragraph { children: Inline[] }
| Heading { level: float, children: Inline[] }
| ThematicBreak
| CodeBlock { info: string, code: string }
| HtmlBlock { html: string }
| Blockquote { children: Block[] }
| BulletList { tight: boolean, items: ListItem[] }
| OrderedList { tight: boolean, start: float, items: ListItem[] }
| Table { align: Align[], head: TableCell[], rows: TableCell[][] }
/// A list item. `checked` is `null` unless the item is a GFM task (`- [x] done`).
export type ListItem = { children: Block[], checked: boolean? }
/// A table cell.
export type TableCell = { children: Inline[] }
/// An inline: what paragraphs, headings and cells are made of. `HtmlInline` is raw HTML as written, rendered according
/// to `Options.html`.
export type Inline =
| Str { text: string }
| SoftBreak
| HardBreak
| CodeSpan { code: string }
| Emphasis { children: Inline[] }
| Strong { children: Inline[] }
| Strikethrough { children: Inline[] }
| Link { url: string, title: string?, children: Inline[] }
| Picture { url: string, title: string?, alt: Inline[] }
| HtmlInline { html: string }
/// What happens to raw HTML in the source:
/// - `"escape"` (the default) shows it as text;
/// - `"sanitize"` keeps what the `policy` allows and removes the rest;
/// - `"trust"` passes it through. Use it only for Markdown you wrote yourself.
export type HtmlMode = "escape" | "sanitize" | "trust"
/// What `sanitize` keeps. Anything left out takes the default: common formatting tags, no scripts, styles, event
/// handlers or forms.
export type Policy = {
/// Lowercase tag names to keep. A tag not listed is removed and its content kept.
tags?: string[],
/// Attributes to keep, per lowercase tag name.
attributes?: Map<string, string[]>,
/// URL schemes `href` and `src` may use. Relative URLs are always allowed.
schemes?: string[],
}
/// Whether a URL is a link's or an image's.
export type UrlKind = "link" | "image"
/// Options for parsing and rendering. Every field is optional.
export type Options = {
/// GitHub Flavored Markdown: tables, task lists, strikethrough and bare autolinks. On by default.
gfm?: boolean,
/// What happens to raw HTML. `"escape"` by default.
html?: HtmlMode,
/// What `html: "sanitize"` keeps.
policy?: Policy,
/// URL schemes links and images may use: `http`, `https`, `mailto` and `tel` by default. Relative URLs are always
/// allowed, and images may also be `data:image/` PNG, GIF, JPEG or WebP. A link to anything else renders as its text.
schemes?: string[],
/// Added to every heading's level, up to 6: `1` renders `# Title` as `<h2>`.
headingOffset?: float,
/// `target` for every link. `"_blank"` also adds `rel="noopener noreferrer"`.
linkTarget?: string,
/// Rewrites a URL before it is checked and rendered, as an app resolves `upload:<id>` to a real address.
/// Returning `null` keeps the URL as written.
rewriteUrl?: (url: string, kind: UrlKind) => string?,
}