CodeSampleX

Sample

prosemirror-markdown 1.13.7: MarkdownSerializer

Verified sample for npm prosemirror-markdown 1.13.7: MarkdownSerializer. The contract ran on node 22 · linux debian/x64 · docker and passed.

sha256:f5bb0c0a1ca93b680b732f80b2e689a33527d208d422af6a1c4f49face5602ff

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 npm

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify prosemirror-markdown.MarkdownSerializer in pkg:npm/prosemirror-markdown@1.13.7
Packages
Symbols
  • prosemirror-markdown.MarkdownSerializer
Created
2026-09-15T09:02:55Z

Contract

  1. assert MarkdownSerializer initializes with nodes and marks dictionaries
  2. assert MarkdownSerializer.serialize converts paragraphs with bold italic and code marks to markdown
  3. assert MarkdownSerializer.serialize converts links with href and title attributes
  4. assert MarkdownSerializer.serialize converts heading nodes to matching ATX markdown levels
  5. assert MarkdownSerializer.serialize converts blockquotes and fenced code blocks
  6. assert MarkdownSerializer.serialize converts bullet lists and ordered lists
  7. assert MarkdownSerializer supports custom node serialization handlers

Files

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

Download the source artifact (tar.gz)

Source

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.MarkdownSerializer 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.MarkdownSerializer

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:d8aaabd0e232255dc1f80d2b26ea0e0683c6cacd341cfe5edfca6cd7fdc5f8ab","contract":["assert MarkdownSerializer initializes with nodes and marks dictionaries","assert MarkdownSerializer.serialize converts paragraphs with bold italic and code marks to markdown","assert MarkdownSerializer.serialize converts links with href and title attributes","assert MarkdownSerializer.serialize converts heading nodes to matching ATX markdown levels","assert MarkdownSerializer.serialize converts blockquotes and fenced code blocks","assert MarkdownSerializer.serialize converts bullet lists and ordered lists","assert MarkdownSerializer supports custom node serialization handlers"],"goal":"verify prosemirror-markdown.MarkdownSerializer in pkg:npm/prosemirror-markdown@1.13.7","kind":"HOW","packages":["pkg:npm/prosemirror-markdown@1.13.7"],"schemaVersion":1,"symbols":["prosemirror-markdown.MarkdownSerializer"]},"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.MarkdownSerializer"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-prosemirror-markdown",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-prosemirror-markdown",
      "version": "1.0.0",
      "license": "MIT-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",
  "version": "1.0.0",
  "description": "Clean-room sample verifying pkg:npm/prosemirror-markdown@1.13.7 functionality",
  "private": true,
  "type": "module",
  "main": "src/index.js",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "license": "MIT-0",
  "dependencies": {
    "prosemirror-markdown": "1.13.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify prosemirror-markdown.MarkdownSerializer in pkg:npm/prosemirror-markdown@1.13.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/prosemirror-markdown@1.13.7"
  ],
  "symbols": [
    "prosemirror-markdown.MarkdownSerializer"
  ]
}
src/index.js
import { MarkdownSerializer, defaultMarkdownSerializer, schema } from 'prosemirror-markdown';

/**
 * Creates a custom MarkdownSerializer with the specified nodes, marks, and options.
 *
 * @param {Record<string, Function>} nodes - Mapping of node names to serializer functions.
 * @param {Record<string, Object>} marks - Mapping of mark names to mark serializer specifications.
 * @param {Object} [options] - Optional serialization settings (e.g., tightLists).
 * @returns {MarkdownSerializer} Configured MarkdownSerializer instance.
 */
export function createSerializer(nodes, marks, options = {}) {
  return new MarkdownSerializer(nodes, marks, options);
}

/**
 * Serializes a ProseMirror document to a markdown string using the provided serializer.
 *
 * @param {import('prosemirror-model').Node} doc - ProseMirror document root node.
 * @param {MarkdownSerializer} [serializer] - Serializer to use (defaults to defaultMarkdownSerializer).
 * @param {Object} [options] - Serialization options.
 * @returns {string} Serialized markdown representation.
 */
export function serializeDocument(doc, serializer = defaultMarkdownSerializer, options = {}) {
  return serializer.serialize(doc, options);
}

export { MarkdownSerializer, defaultMarkdownSerializer, schema };
test/contract.mjs
import assert from 'node:assert/strict';
import { MarkdownSerializer, defaultMarkdownSerializer, schema } from 'prosemirror-markdown';
import { createSerializer, serializeDocument } from '../src/index.js';

// 1. MarkdownSerializer constructor and instance properties
const nodes = { ...defaultMarkdownSerializer.nodes };
const marks = { ...defaultMarkdownSerializer.marks };
const options = { tightLists: true };

const serializer = createSerializer(nodes, marks, options);
assert.ok(serializer instanceof MarkdownSerializer, 'Must be instance of MarkdownSerializer');
assert.strictEqual(typeof serializer.serialize, 'function', 'Must have serialize method');
assert.strictEqual(serializer.nodes, nodes, 'Must store nodes dictionary');
assert.strictEqual(serializer.marks, marks, 'Must store marks dictionary');
assert.deepStrictEqual(serializer.options, options, 'Must store options object');

// 2. Serialize basic paragraph with inline formatting marks
const paragraphDoc = schema.node('doc', null, [
  schema.node('paragraph', null, [
    schema.text('Plain text, '),
    schema.text('bold text', [schema.mark('strong')]),
    schema.text(', '),
    schema.text('italic text', [schema.mark('em')]),
    schema.text(', and '),
    schema.text('inline code', [schema.mark('code')])
  ])
]);

const paragraphMarkdown = serializeDocument(paragraphDoc, serializer);
assert.strictEqual(
  paragraphMarkdown,
  'Plain text, **bold text**, *italic text*, and `inline code`',
  'Must serialize paragraph with strong, em, and code marks'
);

// 3. Serialize links with href and title
const linkDoc = schema.node('doc', null, [
  schema.node('paragraph', null, [
    schema.text('Visit '),
    schema.text('example', [
      schema.mark('link', { href: 'https://example.com', title: 'Example Domain' })
    ])
  ])
]);

const linkMarkdown = serializeDocument(linkDoc, serializer);
assert.strictEqual(
  linkMarkdown,
  'Visit [example](https://example.com "Example Domain")',
  'Must serialize link mark with href and title'
);

// 4. Serialize headings with levels
const headingDoc = schema.node('doc', null, [
  schema.node('heading', { level: 1 }, [schema.text('Title')]),
  schema.node('heading', { level: 2 }, [schema.text('Subtitle')]),
  schema.node('paragraph', null, [schema.text('Section content')])
]);

const headingMarkdown = serializeDocument(headingDoc, serializer);
assert.strictEqual(
  headingMarkdown,
  '# Title\n\n## Subtitle\n\nSection content',
  'Must serialize heading nodes with matching ATX hash levels'
);

// 5. Serialize blockquotes and code blocks
const blockDoc = schema.node('doc', null, [
  schema.node('blockquote', null, [
    schema.node('paragraph', null, [schema.text('Quoted text')])
  ]),
  schema.node('code_block', { params: 'js' }, [
    schema.text('const x = 42;')
  ])
]);

const blockMarkdown = serializeDocument(blockDoc, serializer);
assert.strictEqual(
  blockMarkdown,
  '> Quoted text\n\n```js\nconst x = 42;\n```',
  'Must serialize blockquote and fenced code_block'
);

// 6. Serialize bullet and ordered lists
const listDoc = schema.node('doc', null, [
  schema.node('bullet_list', null, [
    schema.node('list_item', null, [
      schema.node('paragraph', null, [schema.text('First bullet')])
    ]),
    schema.node('list_item', null, [
      schema.node('paragraph', null, [schema.text('Second bullet')])
    ])
  ]),
  schema.node('ordered_list', { order: 1 }, [
    schema.node('list_item', null, [
      schema.node('paragraph', null, [schema.text('First item')])
    ]),
    schema.node('list_item', null, [
      schema.node('paragraph', null, [schema.text('Second item')])
    ])
  ])
]);

const listMarkdown = serializeDocument(listDoc, serializer);
assert.strictEqual(
  listMarkdown,
  '* First bullet\n\n* Second bullet\n\n1. First item\n\n2. Second item',
  'Must serialize bullet lists with asterisks and ordered lists with numbers'
);

// 7. Custom node serializer support
const customNodes = {
  ...defaultMarkdownSerializer.nodes,
  horizontal_rule(state, node) {
    state.write('***\n\n');
  }
};
const customSerializer = createSerializer(customNodes, defaultMarkdownSerializer.marks);
const hrDoc = schema.node('doc', null, [
  schema.node('paragraph', null, [schema.text('Before')]),
  schema.node('horizontal_rule'),
  schema.node('paragraph', null, [schema.text('After')])
]);

const hrMarkdown = serializeDocument(hrDoc, customSerializer);
assert.strictEqual(
  hrMarkdown,
  'Before\n\n***\n\nAfter',
  'Must use custom node serialization handler when provided'
);

console.log('All MarkdownSerializer contract assertions passed.');

Origin Seeder

anonymous