CodeSampleX

サンプル

marked 18.0.5: marked

検証済みサンプル — npm marked 18.0.5: marked. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: marked exports marked function and parse, parseInline…

sha256:a045891bc008528e55d4eb19457fc54781d30223272d70c50ce3291e653d0ba4

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
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-08-28

ケース

HOW
ゴール
verify marked.marked in pkg:npm/marked@18.0.5
パッケージ
シンボル
  • marked.marked
作成日
2026-08-28T00:03:45Z

コントラクト

  1. marked exports marked function and parse, parseInline, lexer, parser, use, and walkTokens methods
  2. marked parses markdown into HTML synchronously by default with heading and paragraph formatting
  3. marked.parseInline parses inline markdown without wrapping in block-level paragraph tags
  4. marked.lexer tokenizes markdown string into structured token objects
  5. marked.parser renders an array of token objects into an HTML string
  6. marked.walkTokens iterates over all token nodes in a token tree
  7. marked.use extends behavior with custom hooks

ファイル

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • test/contract.mjs

ソースアーティファクトをダウンロード (tar.gz)

ソース

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify marked.marked in pkg:npm/marked@18.0.5
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/marked@18.0.5
Demonstrate these symbols/APIs:
  - marked.marked

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:a7e15f9e2c97bacd5774bf56c866f4f99e59aee68efefa8020b4ccce47e36b21","contract":["marked exports marked function and parse, parseInline, lexer, parser, use, and walkTokens methods","marked parses markdown into HTML synchronously by default with heading and paragraph formatting","marked.parseInline parses inline markdown without wrapping in block-level paragraph tags","marked.lexer tokenizes markdown string into structured token objects","marked.parser renders an array of token objects into an HTML string","marked.walkTokens iterates over all token nodes in a token tree","marked.use extends behavior with custom hooks"],"goal":"verify marked.marked in pkg:npm/marked@18.0.5","kind":"HOW","packages":["pkg:npm/marked@18.0.5"],"schemaVersion":1,"symbols":["marked.marked"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/marked@18.0.5"],"schemaVersion":1,"subject":"pkg:npm/marked@18.0.5","symbols":["marked.marked"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-marked-marked",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-marked-marked",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "marked": "18.0.5"
      }
    },
    "node_modules/marked": {
      "version": "18.0.5",
      "resolved": "https://registry.npmjs.org/marked/-/marked-18.0.5.tgz",
      "integrity": "sha512-S6GcvALHg6K4ohtu4E7x0a1AqhAjp6cV8KhLSyN9qVapnzJkusVBxZRcIU9AeYsbe6P1hKDusSbEOzGyyuce6w==",
      "license": "MIT",
      "bin": {
        "marked": "bin/marked.js"
      },
      "engines": {
        "node": ">= 20"
      }
    }
  }
}
package.json
{
  "name": "sample-marked-marked",
  "version": "1.0.0",
  "private": true,
  "license": "MIT-0",
  "main": "src/index.js",
  "dependencies": {
    "marked": "18.0.5"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify marked.marked in pkg:npm/marked@18.0.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/marked@18.0.5"
  ],
  "symbols": [
    "marked.marked"
  ]
}
src/index.js
const { marked } = require('marked');

/**
 * Parses markdown string to HTML using marked.
 *
 * @param {string} src - Markdown input string.
 * @param {object} [options] - Parsing options.
 * @returns {string|Promise<string>} Parsed HTML string (or Promise if async).
 */
function parseMarkdown(src, options) {
  return marked(src, options);
}

/**
 * Parses inline markdown tokens without wrapping with paragraph tags.
 *
 * @param {string} src - Inline markdown string.
 * @param {object} [options] - Parsing options.
 * @returns {string} Inline HTML string.
 */
function parseInlineMarkdown(src, options) {
  return marked.parseInline(src, options);
}

/**
 * Tokenizes markdown source into structured token nodes.
 *
 * @param {string} src - Markdown input string.
 * @param {object} [options] - Lexer options.
 * @returns {Array<object>} Array of parsed token objects.
 */
function tokenizeMarkdown(src, options) {
  return marked.lexer(src, options);
}

/**
 * Compiles a token list back into HTML output.
 *
 * @param {Array<object>} tokens - Array of token objects.
 * @param {object} [options] - Parser options.
 * @returns {string} Compiled HTML string.
 */
function parseTokens(tokens, options) {
  return marked.parser(tokens, options);
}

/**
 * Configures marked instance with extensions or options.
 *
 * @param {...object} extensions - Extensions or options to apply.
 * @returns {typeof marked} The marked instance.
 */
function configureMarked(...extensions) {
  return marked.use(...extensions);
}

module.exports = {
  marked,
  parseMarkdown,
  parseInlineMarkdown,
  tokenizeMarkdown,
  parseTokens,
  configureMarked
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  marked,
  parseMarkdown,
  parseInlineMarkdown,
  tokenizeMarkdown,
  parseTokens,
  configureMarked
} = require('../src/index.js');
const markedModule = require('marked');

// 1. Verify marked export and member methods
assert.equal(typeof marked, 'function', 'marked must be a function');
assert.strictEqual(marked, markedModule.marked, 'marked export must match marked.marked from the package');
assert.strictEqual(marked, markedModule.parse, 'marked function must equal marked.parse');
assert.equal(typeof marked.parse, 'function', 'marked.parse must be a function');
assert.equal(typeof marked.parseInline, 'function', 'marked.parseInline must be a function');
assert.equal(typeof marked.lexer, 'function', 'marked.lexer must be a function');
assert.equal(typeof marked.parser, 'function', 'marked.parser must be a function');
assert.equal(typeof marked.use, 'function', 'marked.use must be a function');
assert.equal(typeof marked.walkTokens, 'function', 'marked.walkTokens must be a function');

// 2. marked parses markdown into HTML synchronously by default with heading and paragraph formatting
const markdownInput = '# Main Title\n\nThis is a paragraph with **bold** text and *italic* text.';
const renderedHtml = marked(markdownInput);
assert.equal(typeof renderedHtml, 'string', 'marked output must be a string');
assert.ok(renderedHtml.includes('<h1>Main Title</h1>'), 'rendered HTML must contain <h1>Main Title</h1>');
assert.ok(
  renderedHtml.includes('<p>This is a paragraph with <strong>bold</strong> text and <em>italic</em> text.</p>'),
  'rendered HTML must contain formatted paragraph'
);

const helperRendered = parseMarkdown(markdownInput);
assert.equal(helperRendered, renderedHtml, 'parseMarkdown helper must produce identical HTML');

// 3. marked.parseInline parses inline markdown without wrapping in block-level paragraph tags
const inlineInput = '**Bold statement** and [Link](https://example.com)';
const inlineOutput = marked.parseInline(inlineInput);
assert.equal(typeof inlineOutput, 'string', 'parseInline output must be a string');
assert.ok(inlineOutput.includes('<strong>Bold statement</strong>'), 'parseInline must render bold tags');
assert.ok(inlineOutput.includes('<a href="https://example.com">Link</a>'), 'parseInline must render anchor tags');
assert.ok(!inlineOutput.includes('<p>'), 'parseInline must not wrap content in paragraph tags');

const helperInline = parseInlineMarkdown(inlineInput);
assert.equal(helperInline, inlineOutput, 'parseInlineMarkdown helper must match marked.parseInline output');

// 4. marked.lexer tokenizes markdown string into structured token objects
const complexMarkdown = '# Section Heading\n\nParagraph text.\n\n- Item 1\n- Item 2';
const tokens = marked.lexer(complexMarkdown);
assert.ok(Array.isArray(tokens), 'lexer must return an array of tokens');
assert.equal(tokens[0].type, 'heading', 'first token must be heading');
assert.equal(tokens[0].depth, 1, 'heading depth must be 1');
assert.equal(tokens[0].text, 'Section Heading', 'heading text must match');
assert.equal(tokens[1].type, 'space', 'second token must be space');
assert.equal(tokens[2].type, 'paragraph', 'third token must be paragraph');
assert.equal(tokens[4].type, 'list', 'fifth token must be list');
assert.equal(tokens[4].items.length, 2, 'list must contain 2 items');

const helperTokens = tokenizeMarkdown(complexMarkdown);
assert.deepEqual(helperTokens, tokens, 'tokenizeMarkdown helper must match marked.lexer output');

// 5. marked.parser renders an array of token objects into an HTML string
const htmlFromTokens = marked.parser(tokens);
assert.equal(typeof htmlFromTokens, 'string', 'parser output must be a string');
assert.ok(htmlFromTokens.includes('<h1>Section Heading</h1>'), 'parsed tokens must include heading');
assert.ok(htmlFromTokens.includes('<p>Paragraph text.</p>'), 'parsed tokens must include paragraph');
assert.ok(htmlFromTokens.includes('<ul>'), 'parsed tokens must include unordered list');
assert.ok(htmlFromTokens.includes('<li>Item 1</li>'), 'parsed tokens must include list items');

const helperParsedTokens = parseTokens(tokens);
assert.equal(helperParsedTokens, htmlFromTokens, 'parseTokens helper must match marked.parser output');

// 6. marked.walkTokens iterates over all token nodes in a token tree
const visitedTypes = [];
marked.walkTokens(tokens, (token) => {
  visitedTypes.push(token.type);
});
assert.ok(visitedTypes.includes('heading'), 'walkTokens must visit heading token');
assert.ok(visitedTypes.includes('paragraph'), 'walkTokens must visit paragraph token');
assert.ok(visitedTypes.includes('list'), 'walkTokens must visit list token');
assert.ok(visitedTypes.includes('list_item'), 'walkTokens must visit nested list items');

// 7. marked.use extends behavior with custom hooks
configureMarked({
  hooks: {
    postprocess(html) {
      return html.trim() + '\n<!-- verified -->';
    }
  }
});
const hookedOutput = marked('# Hook Test');
assert.ok(hookedOutput.includes('<h1>Hook Test</h1>'), 'hooked output must contain heading');
assert.ok(hookedOutput.endsWith('<!-- verified -->'), 'postprocess hook must append comment');

console.log('Contract tests passed successfully.');

オリジンシーダー

匿名