Parser for converting DA Admin HTML to DA Live ProseMirror/YDoc format
npm install @da-tools/da-parserParser for converting DA Admin HTML to ProseMirror/YDoc format and back.
DA Parser provides bidirectional conversion between:
- AEM HTML (stored in DA Admin) ↔ ProseMirror documents (used in the DA Live editor)
The parser handles:
- Block structures (divs with classes → tables for editing)
- Section breaks ( elements)
- Images with links (hoisting/unhoisting link attributes)
- Diff markers (da-diff-added, da-diff-deleted) for regional edits
- Custom DA metadata
- List handling with diff markers
``bash`
npm install da-parser
`javascript
import { aem2doc } from 'da-parser';
import * as Y from 'yjs';
const html =
Hello world
;const ydoc = new Y.Doc();
aem2doc(html, ydoc);
`$3
`javascript
import { doc2aem } from 'da-parser';const html = doc2aem(ydoc);
`$3
`javascript
import { getSchema, isKnownHTMLTag } from 'da-parser/schema';const schema = getSchema();
// Check if a tag is recognized
isKnownHTMLTag('div'); // true
isKnownHTMLTag('custom-element'); // false
`Exports
| Export | Description |
|--------|-------------|
|
aem2doc(html, ydoc) | Convert AEM HTML string to YDoc |
| doc2aem(ydoc) | Convert YDoc back to AEM HTML |
| tableToBlock(child, fragment) | Convert a table node to block structure |
| EMPTY_DOC | Empty document HTML template |
| getSchema() | Get the ProseMirror schema |
| isKnownHTMLTag(tag) | Check if tag is a known HTML element |
| prosemirrorToYXmlFragment | Re-exported from y-prosemirror |
| yDocToProsemirror | Re-exported from y-prosemirror |Development
`bash
Install dependencies
npm installRun all tests (both environments)
npm testRun browser tests only (DOMParser path)
npm run test:browserRun Node.js tests only (hast-util-from-html path)
npm run test:nodeRun linter
npm run lint
`Testing Strategy
The parser has two HTML parsing code paths:
- Browser: Uses native
DOMParser (zero bundle size)
- Node.js/Workers: Uses hast-util-from-htmlThe same test files run in both environments to ensure parity:
-
npm run test:browser - Tests run in Chrome via @web/test-runner (wtr)
- npm run test:node - Tests run in Node.js via mochaThe
test/test-utils.js module provides environment-agnostic utilities (expect, readTestFile) that work in both wtr and mocha.Test Fixtures
-
htmldown/ - HTML files for parser testing
- htmltest/ - Additional HTML test cases
- test/mocks/` - Mock HTML files for specific test scenariosApache-2.0