// 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, /// 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 `

`. 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:` to a real address. /// Returning `null` keeps the URL as written. rewriteUrl?: (url: string, kind: UrlKind) => string?, }