{"library":"prosemirror-test-builder","title":"ProseMirror Test Document Builder","description":"`prosemirror-test-builder` is a specialized utility package designed to simplify the programmatic construction of ProseMirror documents for testing purposes. It provides a comprehensive set of helper functions, often named after common HTML tags like `p`, `h1`, `ul`, and `li`, allowing developers to intuitively build nodes and marks within a default, feature-rich ProseMirror schema. The package also includes a `builders` utility for generating these helpers based on a custom schema. A key differentiating feature is its integrated tag system, which enables developers to embed named markers within document content strings (e.g., `<a>`) to precisely track and retrieve cursor positions within the generated document, significantly streamlining assertion logic in tests. This current stable version is 1.1.1, and its release cadence is generally aligned with the broader ProseMirror ecosystem, ensuring compatibility for test setups.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install prosemirror-test-builder"],"cli":null},"imports":["import { doc, p } from 'prosemirror-test-builder'","import { schema } from 'prosemirror-test-builder'","import { builders } from 'prosemirror-test-builder/dist/build'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { doc, p, strong, ul, li, schema } from 'prosemirror-test-builder';\nimport { Schema } from 'prosemirror-model';\n\n// 1. Using the default builders and tag system\nconst defaultTestDoc = doc(\n  p('Hello, ', strong('world<a>! Here is some text.')),\n  ul(\n    li('Item one<b>'),\n    li('Item two'),\n    li('Item three<c> and more')\n  )\n);\n\nconsole.log('--- Default Schema Document ---');\nconsole.log('Document JSON:', defaultTestDoc.toJSON());\nconsole.log('Tag \"a\" position:', defaultTestDoc.tag.a); // Cursor position after 'world'\nconsole.log('Tag \"b\" position:', defaultTestDoc.tag.b); // Cursor position after 'Item one'\nconsole.log('Tag \"c\" position:', defaultTestDoc.tag.c); // Cursor position after 'Item three'\n\n// 2. Creating builders for a custom schema\nconst myCustomSchema = new Schema({\n  nodes: {\n    doc: { content: \"custom_paragraph+\" },\n    custom_paragraph: { content: \"text*\", group: \"block\" },\n    text: { inline: true }\n  },\n  marks: {}\n});\n\nimport { builders } from 'prosemirror-test-builder/dist/build';\nconst { doc: customDoc, custom_paragraph: customParagraph } = builders(myCustomSchema);\n\nconst customTestDoc = customDoc(\n  customParagraph('This is custom content with a <d>tag.')\n);\n\nconsole.log('\\n--- Custom Schema Document ---');\nconsole.log('Custom Document JSON:', customTestDoc.toJSON());\nconsole.log('Custom Tag \"d\" position:', customTestDoc.tag.d);\n\n// 3. Accessing the default schema directly\nconsole.log('\\n--- Default Test Schema Info ---');\nconsole.log('Default schema node types:', Object.keys(schema.nodes));\n","lang":"typescript","description":"This quickstart demonstrates building a ProseMirror document using both the default builders and the custom `builders` factory function, along with accessing the embedded tag positions.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}