Package md provides helper functions for generating Markdown content programmatically.
It includes utilities for text formatting, creating lists, blockquotes, code blocks, links, images, and more.
Highlights: - Supports basic Markdown syntax such as bold, italic, strikethrough, headers, and lists. - Manages multiline support in lists (e.g., bullet, ordered, and todo lists). - Includes advanced helpers like inline images with links and nested list prefixes.
For a comprehensive example of how to use these helpers, see: https://gno.land/r/docs/moul_md
Sanitization contract
Some helpers in this package sanitize their user-derived arguments INTERNALLY (via p/nt/markdown/sanitize/v0). When using these, pass raw user input — do NOT pre-wrap with sanitize.*, or you will double-wrap (the escapers are not idempotent and double-wrap is a bug):
Example
1Link, UserLink, Image, InlineImageWithLink, FootnoteDefinition,
2LinkReferenceDefinition, CollapsibleSection (title only),
3InlineCode, CodeBlock, LanguageCodeBlock, Blockquote
The other helpers DO NOT sanitize — they are pure builders that wrap their input in markdown chrome. User-derived input reaches the output unmodified, so callers MUST wrap with sanitize.* at the call site:
Example
1Bold, Italic, Strikethrough, H1-H6, BulletList, BulletItem,
2OrderedList, TodoList, TodoItem, Nested, Paragraph, Columns,
3ColumnsN, HorizontalRule
Examples:
Example
1// Sanitizing helper — pass raw:
2out += md.Link(post.Title, post.URL) // good
3out += md.Link(sanitize.InlineText(post.Title), sanitize.URL(post.URL)) // BAD: double-wrap
4
5// Non-sanitizing helper — wrap once:
6out += md.H2(sanitize.InlineText(post.Title)) // good
7out += md.H2(post.Title) // BAD: raw user input
8out += md.H2(sanitize.InlineText(sanitize.InlineText(post.Title))) // BAD: double-wrap
Composition: outputs of sanitizing helpers are safe markdown chrome and can be embedded inside non-sanitizing helpers freely:
Example
1out += md.H2(md.Link(post.Title, post.URL)) // good — H2 doesn't re-escape Link's output
The reverse is unsafe: do NOT embed a non-sanitizing helper's markdown chrome inside a sanitizing helper's arg, or the inner markdown gets re-escaped:
Example
1out += md.Link(md.Bold(post.Title), post.URL) // BAD: Link's internal sanitize
2 // escapes the ** chars from md.Bold