Ejemplo
marked 18.0.9: Handle modern marked custom renderer methods receiving a single token object instead of legacy positional primitive arguments
Muestra verificada para npm marked 18.0.9: Handle modern marked custom renderer methods receiving a single token object instead of legacy positional…
sha256:4026c7f4aa5bbe2dc885c538a92bdebf44cab658dca80b98f525a9b5c121ea76
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 3
- Claves de firma que lo compilaron
- 3
Entorno declarado
node linux x64 node node npm
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-16 |
| node 22 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-18 |
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-09-08 |
Caso
HOW- Objetivo
- Handle modern marked custom renderer methods receiving a single token object instead of legacy positional primitive arguments
- Paquetes
- Símbolos
-
- marked.use
- Marked.prototype.parse
- Renderer.prototype.heading
- Entorno
- node
- Creado
- 2026-08-16T18:45:29Z
Contrato
- 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
Archivos
- NOTES.md
- csx.json
- package-lock.json
- package.json
- test/contract.mjs
Código fuente
# Marked Custom Renderer Signature and Token Objects
## Network Search Results
Searching the known solutions registry for `pkg:npm/marked` with query `marked markdown parsing options breaking changes version behavior` returned no existing solutions for marked (the nearest fallback entries were unrelated crates like semver `sha256:135433c9e1bd94f656bcd195488e72bbd4deac30203f7ef9f814378f28aeb022`). No existing entry covered marked custom renderer signatures or breaking AST changes.
## Failure Mode
When callers use the legacy positional parameter renderer signatures (such as `heading(text, level)`, `link(href, title, text)`, `code(code, lang)`, or `paragraph(text)`), the code executes silently with a green build and exit code 0, but corrupts the output HTML by rendering `<hundefined>[object Object]</hundefined>`, `<a href="[object Object]">undefined</a>`, and `<p class="...">[object Object]</p>`.
## Behavior Details
In marked v12 and earlier, custom renderer override functions received primitive positional arguments where inline formatting was already resolved into HTML strings.
In marked v14 and later (including v15, v16, v17, and v18):
- Renderer functions receive a single AST token object (e.g. `heading(token)`, `link(token)`, `code(token)`).
- Metadata is accessed via token properties: `token.depth` (heading level), `token.href` (URL), `token.title`, `token.lang`, `token.text`.
- Child tokens are not pre-rendered to HTML; callers must explicitly invoke `this.parser.parseInline(token.tokens)` or `this.parser.parse(token.tokens)` to process child inline tokens.
{"case":{"believed":"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.","caseId":"case:sha256:761e97bd88ffc16a77af7d7e40c465ff8a334ed9572f75e164f3b5778f8d960f","contract":["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"],"goal":"Handle modern marked custom renderer methods receiving a single token object instead of legacy positional primitive arguments","kind":"HOW","packages":["pkg:npm/marked@18.0.9"],"schemaVersion":1,"symbols":["marked.use","Marked.prototype.parse","Renderer.prototype.heading"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","executionContext":"node","language":"node","os":"linux","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/marked@18.0.9"],"schemaVersion":1,"symbols":["marked.use","Marked.prototype.parse","Renderer.prototype.heading"],"verifierAdapter":"node-typescript@1"}
{
"name": "npm-marked-version",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "npm-marked-version",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"marked": "^18.0.9"
}
},
"node_modules/marked": {
"version": "18.0.9",
"resolved": "https://registry.npmjs.org/marked/-/marked-18.0.9.tgz",
"integrity": "sha512-/Sa4qiiHZxf0/FQdBBowr9q4r10krCwMvpK48FUBdXdUXScDxiQGR9zCPrFgRVR5LU3iySOiIjy09ZQvADir1w==",
"license": "MIT",
"bin": {
"marked": "bin/marked.js"
},
"engines": {
"node": ">= 20"
}
}
}
}
{
"name": "npm-marked-version",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "node test/contract.mjs"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs",
"dependencies": {
"marked": "^18.0.9"
}
}
import assert from 'node:assert/strict';
import { Marked } from 'marked';
// Contract Line 1 (published finding):
// 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.
{
let capturedFirstArg = null;
let capturedSecondArg = null;
const instance = new Marked({
renderer: {
heading(text, level) {
capturedFirstArg = text;
capturedSecondArg = level;
return `<h${level}>${text}</h${level}>\n`;
}
}
});
const output = instance.parse('# Hello World');
// Instead of throwing an error or receiving ('Hello World', 1), the legacy signature receives
// the Token object as the first argument and undefined as the second argument.
assert.strictEqual(typeof capturedFirstArg, 'object');
assert.strictEqual(capturedFirstArg.type, 'heading');
assert.strictEqual(capturedFirstArg.depth, 1);
assert.strictEqual(capturedFirstArg.text, 'Hello World');
assert.strictEqual(capturedSecondArg, undefined);
// String interpolation produces <hundefined>[object Object]</hundefined> rather than <h1>Hello World</h1>
assert.strictEqual(output, '<hundefined>[object Object]</hundefined>\n');
assert.notStrictEqual(output, '<h1>Hello World</h1>\n');
}
// Contract Line 2:
// 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'
{
let capturedHref = null;
let capturedTitle = null;
let capturedText = null;
const instance = new Marked({
renderer: {
link(href, title, text) {
capturedHref = href;
capturedTitle = title;
capturedText = text;
return `<a href="${href}" title="${title}">${text}</a>`;
}
}
});
const output = instance.parse('[Documentation](https://example.com/docs)');
assert.strictEqual(typeof capturedHref, 'object');
assert.strictEqual(capturedHref.type, 'link');
assert.strictEqual(capturedHref.href, 'https://example.com/docs');
assert.strictEqual(capturedTitle, undefined);
assert.strictEqual(capturedText, undefined);
assert.strictEqual(output, '<p><a href="[object Object]" title="undefined">undefined</a></p>\n');
}
// Contract Line 3:
// Legacy paragraph renderer with signature paragraph(text) receives the paragraph token object instead of pre-rendered HTML text string
{
let capturedText = null;
const instance = new Marked({
renderer: {
paragraph(text) {
capturedText = text;
return `<p class="custom-p">${text}</p>\n`;
}
}
});
const output = instance.parse('This is a simple paragraph.');
assert.strictEqual(typeof capturedText, 'object');
assert.strictEqual(capturedText.type, 'paragraph');
assert.strictEqual(capturedText.text, 'This is a simple paragraph.');
assert.strictEqual(output, '<p class="custom-p">[object Object]</p>\n');
}
// Contract Line 4:
// Legacy code renderer with signature code(code, lang) receives the code token object in code and undefined in lang
{
let capturedCode = null;
let capturedLang = null;
const instance = new Marked({
renderer: {
code(code, lang) {
capturedCode = code;
capturedLang = lang;
return `<pre><code class="${lang}">${code}</code></pre>\n`;
}
}
});
const output = instance.parse('```js\nconst answer = 42;\n```');
assert.strictEqual(typeof capturedCode, 'object');
assert.strictEqual(capturedCode.type, 'code');
assert.strictEqual(capturedCode.lang, 'js');
assert.strictEqual(capturedCode.text, 'const answer = 42;');
assert.strictEqual(capturedLang, undefined);
assert.strictEqual(output, '<pre><code class="undefined">[object Object]</code></pre>\n');
}
// Contract Line 5:
// Modern custom renderers must accept a single token parameter and explicitly invoke this.parser.parseInline(token.tokens) to render inline content
{
const instance = new Marked({
renderer: {
heading(token) {
const text = this.parser.parseInline(token.tokens);
return `<h${token.depth} class="heading-${token.depth}">${text}</h${token.depth}>\n`;
},
link(token) {
const text = this.parser.parseInline(token.tokens);
const titleAttr = token.title ? ` title="${token.title}"` : '';
return `<a href="${token.href}"${titleAttr} class="custom-link">${text}</a>`;
},
code(token) {
const langClass = token.lang ? ` class="language-${token.lang}"` : '';
return `<pre><code${langClass}>${token.text}</code></pre>\n`;
}
}
});
const headingOutput = instance.parse('# **Bold** Heading');
assert.strictEqual(headingOutput, '<h1 class="heading-1"><strong>Bold</strong> Heading</h1>\n');
const linkOutput = instance.parse('[**Home**](https://example.com/home "Homepage")');
assert.strictEqual(linkOutput, '<p><a href="https://example.com/home" title="Homepage" class="custom-link"><strong>Home</strong></a></p>\n');
const codeOutput = instance.parse('```python\nprint("hello")\n```');
assert.strictEqual(codeOutput, '<pre><code class="language-python">print("hello")</code></pre>\n');
}
// Contract Line 6:
// Modern custom renderers access token metadata via token.depth, token.href, token.title, and token.lang properties on the token object
{
const instance = new Marked({
renderer: {
image(token) {
const titleAttr = token.title ? ` title="${token.title}"` : '';
return `<img src="${token.href}" alt="${token.text}"${titleAttr} loading="lazy" />`;
}
}
});
const imgOutput = instance.parse('');
assert.strictEqual(imgOutput, '<p><img src="https://example.com/logo.png" alt="Alt description" title="Logo" loading="lazy" /></p>\n');
}