CodeSampleX

샘플

prosemirror-markdown 1.13.7: MarkdownParser

검증된 샘플 — npm prosemirror-markdown 1.13.7: MarkdownParser. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: MarkdownParser is exported as a…

sha256:f64febe2c33836896719b17f491fdf446ad06c396fbb3b824e0ea61867c3e8b1

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-15

케이스

HOW
목표
verify prosemirror-markdown.MarkdownParser in pkg:npm/prosemirror-markdown@1.13.7
패키지
심벌
  • prosemirror-markdown.MarkdownParser
생성일
2026-09-15T06:58:54Z

컨트랙트

  1. MarkdownParser is exported as a constructor and defaultMarkdownParser is an instance of MarkdownParser
  2. MarkdownParser parses CommonMark headings and paragraphs into ProseMirror document nodes
  3. MarkdownParser parses inline formatting marks including strong, em, and code
  4. MarkdownParser parses container block structures including blockquotes and bullet lists
  5. custom MarkdownParser instance parses markdown using custom tokenizer and token mapping specifications
  6. MarkdownParser parses empty and whitespace input into a valid empty ProseMirror document

파일

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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 prosemirror-markdown.MarkdownParser in pkg:npm/prosemirror-markdown@1.13.7
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/prosemirror-markdown@1.13.7
Demonstrate these symbols/APIs:
  - prosemirror-markdown.MarkdownParser

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:48526a7b4e8fe0fa51bb59ca5abb94bff4dee791158a8c4e771596a22421cd88","contract":["MarkdownParser is exported as a constructor and defaultMarkdownParser is an instance of MarkdownParser","MarkdownParser parses CommonMark headings and paragraphs into ProseMirror document nodes","MarkdownParser parses inline formatting marks including strong, em, and code","MarkdownParser parses container block structures including blockquotes and bullet lists","custom MarkdownParser instance parses markdown using custom tokenizer and token mapping specifications","MarkdownParser parses empty and whitespace input into a valid empty ProseMirror document"],"goal":"verify prosemirror-markdown.MarkdownParser in pkg:npm/prosemirror-markdown@1.13.7","kind":"HOW","packages":["pkg:npm/prosemirror-markdown@1.13.7"],"schemaVersion":1,"symbols":["prosemirror-markdown.MarkdownParser"]},"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/prosemirror-markdown@1.13.7"],"schemaVersion":1,"subject":"pkg:npm/prosemirror-markdown@1.13.7","symbols":["prosemirror-markdown.MarkdownParser"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { MarkdownParser, defaultMarkdownParser, schema } from 'prosemirror-markdown';

/**
 * Parses markdown text into a ProseMirror Node using the provided parser (or defaultMarkdownParser).
 *
 * @param {string} markdown - The markdown string to parse.
 * @param {MarkdownParser} [parser] - Optional MarkdownParser instance.
 * @returns {import('prosemirror-model').Node} The parsed document node.
 */
export function parseMarkdown(markdown, parser = defaultMarkdownParser) {
  return parser.parse(markdown);
}

/**
 * Creates a custom MarkdownParser instance with the given schema, tokenizer, and tokens mapping.
 *
 * @param {object} [options] - Custom parser configuration.
 * @param {import('prosemirror-model').Schema} [options.schema] - ProseMirror schema.
 * @param {any} [options.tokenizer] - Markdown tokenizer instance.
 * @param {Record<string, any>} [options.tokens] - Token mapping specifications.
 * @returns {MarkdownParser} The configured MarkdownParser instance.
 */
export function createCustomMarkdownParser(options = {}) {
  const customSchema = options.schema || schema;
  const tokenizer = options.tokenizer || defaultMarkdownParser.tokenizer;
  const tokens = options.tokens || {
    paragraph: { block: 'paragraph' },
    heading: { block: 'heading', getAttrs: (tok) => ({ level: +tok.tag.slice(1) }) },
    em: { mark: 'em' },
    strong: { mark: 'strong' },
  };

  return new MarkdownParser(customSchema, tokenizer, tokens);
}

export { MarkdownParser, defaultMarkdownParser, schema };
package-lock.json
{
  "name": "sample-prosemirror-markdown-parser",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-prosemirror-markdown-parser",
      "version": "1.0.0",
      "dependencies": {
        "prosemirror-markdown": "1.13.7"
      }
    },
    "node_modules/@types/linkify-it": {
      "version": "5.0.0",
      "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz",
      "integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==",
      "license": "MIT"
    },
    "node_modules/@types/markdown-it": {
      "version": "14.2.0",
      "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.2.0.tgz",
      "integrity": "sha512-NoQ2yGlLWj4wpxMs+TYmRKk3thDrQ97agr7sFqfLsAlvoS8SNQuTrlObhFqG9iugdTtgOE9jpJ6FNM4ZGsa5xQ==",
      "license": "MIT",
      "dependencies": {
        "@types/linkify-it": "^5",
        "@types/mdurl": "^2"
      }
    },
    "node_modules/@types/mdurl": {
      "version": "2.0.0",
      "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-2.0.0.tgz",
      "integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==",
      "license": "MIT"
    },
    "node_modules/argparse": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
      "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
      "license": "Python-2.0"
    },
    "node_modules/entities": {
      "version": "4.5.0",
      "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz",
      "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==",
      "license": "BSD-2-Clause",
      "engines": {
        "node": ">=0.12"
      },
      "funding": {
        "url": "https://github.com/fb55/entities?sponsor=1"
      }
    },
    "node_modules/linkify-it": {
      "version": "5.0.2",
      "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.2.tgz",
      "integrity": "sha512-ONTm2jCMAVZjgQa/Fy1kScXsuOoF5NPTsoFBdE1KVIZ2vAh/r9+Bqo+0jINCBYnavTPQZz38QzFTme79ENoN3Q==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/puzrin"
        },
        {
          "type": "github",
          "url": "https://github.com/sponsors/markdown-it"
        }
      ],
      "license": "MIT",
      "dependencies": {
        "uc.micro": "^2.0.0"
      }
    },
    "node_modules/markdown-it": {
      "version": "14.3.2",
      "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.3.2.tgz",
      "integrity": "sha512-sHHjZ5fJKlgrG4qns2YwVcdNep35h5fERrfkD2YNsb9UFk0UIHarbiTaHKVMlPuWAoiilyK8Fv/jAm11slsY7Q==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/puzrin"
        },
        {
          "type": "github",
          "url": "https://github.com/sponsors/markdown-it"
        }
      ],
      "license": "MIT",
      "dependencies": {
        "argparse": "^2.0.1",
        "entities": "^4.5.0",
        "linkify-it": "^5.0.2",
        "mdurl": "^2.0.0",
        "punycode.js": "^2.3.1",
        "uc.micro": "^2.1.0"
      },
      "bin": {
        "markdown-it": "bin/markdown-it.mjs"
      }
    },
    "node_modules/mdurl": {
      "version": "2.1.0",
      "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.1.0.tgz",
      "integrity": "sha512-1+HBaOx0zi/dQWht8rNv9MYf9qqpqL/kxI0hXImU6Y547zM6Sni8BQibt7ifgMcYtQg41ao3Ivd6cnSM86inpg==",
      "license": "MIT"
    },
    "node_modules/orderedmap": {
      "version": "2.1.1",
      "resolved": "https://registry.npmjs.org/orderedmap/-/orderedmap-2.1.1.tgz",
      "integrity": "sha512-TvAWxi0nDe1j/rtMcWcIj94+Ffe6n7zhow33h40SKxmsmozs6dz/e+EajymfoFcHd7sxNn8yHM8839uixMOV6g==",
      "license": "MIT"
    },
    "node_modules/prosemirror-markdown": {
      "version": "1.13.7",
      "resolved": "https://registry.npmjs.org/prosemirror-markdown/-/prosemirror-markdown-1.13.7.tgz",
      "integrity": "sha512-NV57Oxe3fXR+bNGXS5XW4sKt/XGIyY3n0eHVUoJORcismeF4FFMpLBnl0YESy2BvJQHloexX+9P+zT3VqFj/CQ==",
      "license": "MIT",
      "dependencies": {
        "@types/markdown-it": "^14.0.0",
        "markdown-it": "^14.0.0",
        "prosemirror-model": "^1.25.0"
      }
    },
    "node_modules/prosemirror-model": {
      "version": "1.25.11",
      "resolved": "https://registry.npmjs.org/prosemirror-model/-/prosemirror-model-1.25.11.tgz",
      "integrity": "sha512-QWg9RhnpLlogAmp3p96uEFrE5txQpFynd4vhBAELkwgOCWQs/X0yCzB3/hrHqiPwf91RG5KyWq6553zs9JqIOQ==",
      "license": "MIT",
      "dependencies": {
        "orderedmap": "^2.0.0"
      }
    },
    "node_modules/punycode.js": {
      "version": "2.3.1",
      "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz",
      "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==",
      "license": "MIT",
      "engines": {
        "node": ">=6"
      }
    },
    "node_modules/uc.micro": {
      "version": "2.1.0",
      "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz",
      "integrity": "sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-prosemirror-markdown-parser",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "prosemirror-markdown": "1.13.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify prosemirror-markdown.MarkdownParser in pkg:npm/prosemirror-markdown@1.13.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/prosemirror-markdown@1.13.7"
  ],
  "symbols": [
    "prosemirror-markdown.MarkdownParser"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  MarkdownParser,
  defaultMarkdownParser,
  schema,
  parseMarkdown,
  createCustomMarkdownParser,
} from '../index.mjs';

// 1. MarkdownParser is exported as a constructor and defaultMarkdownParser is an instance of MarkdownParser
{
  assert.equal(typeof MarkdownParser, 'function', 'MarkdownParser must be a constructor function');
  assert.ok(defaultMarkdownParser instanceof MarkdownParser, 'defaultMarkdownParser must be an instance of MarkdownParser');
  assert.equal(typeof defaultMarkdownParser.parse, 'function', 'defaultMarkdownParser.parse must be a function');
  assert.ok(defaultMarkdownParser.schema, 'defaultMarkdownParser must hold a schema');
  assert.ok(defaultMarkdownParser.tokenizer, 'defaultMarkdownParser must hold a tokenizer');
  assert.ok(defaultMarkdownParser.tokens, 'defaultMarkdownParser must hold token specs');
}

// 2. MarkdownParser parses CommonMark headings and paragraphs into ProseMirror document nodes
{
  const markdown = '# Heading 1\n\n## Subheading 2\n\nStandard paragraph content.';
  const doc = parseMarkdown(markdown);

  assert.ok(doc, 'Parsed doc must not be null');
  assert.equal(doc.type.name, 'doc', 'Root node must be doc');
  assert.equal(doc.childCount, 3, 'Document must contain three top-level children');

  const h1 = doc.child(0);
  assert.equal(h1.type.name, 'heading');
  assert.equal(h1.attrs.level, 1);
  assert.equal(h1.textContent, 'Heading 1');

  const h2 = doc.child(1);
  assert.equal(h2.type.name, 'heading');
  assert.equal(h2.attrs.level, 2);
  assert.equal(h2.textContent, 'Subheading 2');

  const p = doc.child(2);
  assert.equal(p.type.name, 'paragraph');
  assert.equal(p.textContent, 'Standard paragraph content.');
}

// 3. MarkdownParser parses inline formatting marks including strong, em, and code
{
  const markdown = 'Here is **strong**, *emphasized*, and `inline code`.';
  const doc = parseMarkdown(markdown);
  const paragraph = doc.child(0);

  let hasStrong = false;
  let hasEm = false;
  let hasCode = false;

  paragraph.forEach((child) => {
    for (const mark of child.marks) {
      if (mark.type.name === 'strong' && child.text === 'strong') {
        hasStrong = true;
      }
      if (mark.type.name === 'em' && child.text === 'emphasized') {
        hasEm = true;
      }
      if (mark.type.name === 'code' && child.text === 'inline code') {
        hasCode = true;
      }
    }
  });

  assert.ok(hasStrong, 'Expected strong mark on "strong"');
  assert.ok(hasEm, 'Expected em mark on "emphasized"');
  assert.ok(hasCode, 'Expected code mark on "inline code"');
}

// 4. MarkdownParser parses container block structures including blockquotes and bullet lists
{
  const markdown = '> Quoted block content\n\n- first item\n- second item';
  const doc = parseMarkdown(markdown);

  assert.equal(doc.childCount, 2, 'Document should have 2 children');

  const blockquote = doc.child(0);
  assert.equal(blockquote.type.name, 'blockquote');
  assert.equal(blockquote.child(0).type.name, 'paragraph');
  assert.equal(blockquote.child(0).textContent, 'Quoted block content');

  const list = doc.child(1);
  assert.equal(list.type.name, 'bullet_list');
  assert.equal(list.childCount, 2);
  assert.equal(list.child(0).type.name, 'list_item');
  assert.equal(list.child(0).child(0).textContent, 'first item');
  assert.equal(list.child(1).type.name, 'list_item');
  assert.equal(list.child(1).child(0).textContent, 'second item');
}

// 5. custom MarkdownParser instance parses markdown using custom tokenizer and token mapping specifications
{
  const customTokens = {
    paragraph: { block: 'paragraph' },
    heading: { block: 'heading', getAttrs: (tok) => ({ level: +tok.tag.slice(1) }) },
    em: { mark: 'em' },
    strong: { mark: 'strong' },
  };
  const customParser = createCustomMarkdownParser({ tokens: customTokens });
  assert.ok(customParser instanceof MarkdownParser, 'customParser must be an instance of MarkdownParser');

  const customDoc = customParser.parse('# Custom Title\n\nCustom **bold** text.');
  assert.equal(customDoc.type.name, 'doc');
  assert.equal(customDoc.childCount, 2);
  assert.equal(customDoc.child(0).type.name, 'heading');
  assert.equal(customDoc.child(0).attrs.level, 1);
  assert.equal(customDoc.child(0).textContent, 'Custom Title');
  assert.equal(customDoc.child(1).type.name, 'paragraph');
}

// 6. MarkdownParser parses empty and whitespace input into a valid empty ProseMirror document
{
  const emptyDoc = parseMarkdown('');
  assert.ok(emptyDoc, 'Empty document must be produced');
  assert.equal(emptyDoc.type.name, 'doc');
  assert.equal(emptyDoc.childCount, 1);
  assert.equal(emptyDoc.child(0).type.name, 'paragraph');
  assert.equal(emptyDoc.child(0).textContent, '');

  const whitespaceDoc = parseMarkdown('   \n\n   ');
  assert.ok(whitespaceDoc, 'Whitespace document must be produced');
  assert.equal(whitespaceDoc.type.name, 'doc');
  assert.equal(whitespaceDoc.childCount, 1);
  assert.equal(whitespaceDoc.child(0).textContent, '');
}

console.log('All prosemirror-markdown MarkdownParser contract tests passed successfully.');

오리진 시더

익명