示例
Handle modern marked custom renderer methods receiving a single token object instead of legacy positional primitive arguments
sha256:4026c7f4aa5bbe2dc885c538a92bdebf44cab658dca80b98f525a9b5c121ea76
PUBLISHED
L3_CONTRACT_PASS
MIT-0
案例
- 目标
- Handle modern marked custom renderer methods receiving a single token object instead of legacy positional primitive arguments HOW
- 包
- marked 18.0.9
- 环境
- node
- 创建时间
- 2026-08-16T18:45:29Z
常见的想当然
Custom renderer methods in marked receive positional primitive arguments like heading(text, level) and link(href, title, text) with child tokens pre-rendered into HTML strings.
这是本样本作者记下的、开发者或模型在此处通常会有的预期。下面的契约才是真正运行过的东西。
契约
- Overriding a custom renderer method with legacy positional parameters like heading(text, level) passes the AST token object as the first parameter and undefined as the second, silently rendering undefined and object Object in place of tag attributes and text
- Legacy link renderer with signature link(href, title, text) receives the token object in href and undefined in title and text, silently producing href='[object Object]' and text 'undefined'
- Legacy paragraph renderer with signature paragraph(text) receives the paragraph token object instead of pre-rendered HTML text string
- Legacy code renderer with signature code(code, lang) receives the code token object in code and undefined in lang
- Modern custom renderers must accept a single token parameter and explicitly invoke this.parser.parseInline(token.tokens) to render inline content
- Modern custom renderers access token metadata via token.depth, token.href, token.title, and token.lang properties on the token object
文件
- NOTES.md
- csx.json
- package-lock.json
- package.json
- test/contract.mjs
下载已验证的构件 (tar.gz) — 契约实际运行的那些字节
原始种子者
验证回执
- node 22 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · node-typescript@1 · 2026-08-16 · ed25519:d91480838ac982c9