1.0.1-CPM-11871-addMarkdownSupport-1.0 • Published 1 year ago
prose-mirror-tools v1.0.1-CPM-11871-addMarkdownSupport-1.0
ProseMirror Tools
A set of tools for manipulating CDP ProseMirror documents.
ProseMirror to HTML Conversion
Convert a CDP ProseMirror Document to HTML with:
import * as ProseUtils from "../src/prose-utils";
const doc: ProseMirror = {
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "CPM + ProseMirror = Happy Teachers."
}
]
}
]
};
const html = ProseUtils.convertProseMirrorToHTML(doc);
console.log(html);This will write the following to the console:
<p>CPM + ProseMirror = Happy Teachers.</p>HTML to ProseMirror Conversion
Convert an HTML Document to a CDP ProseMirror Document
import * as ProseUtils from "../src/prose-utils";
const html = "<p>CPM + ProseMirror = Happy Teachers.</p>"
const doc = ProseUtils.convertHTMLtoProseMirror(html);
console.log(doc);This will write the following to the console:
{
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "CPM + ProseMirror = Happy Teachers."
}
]
}
]
}Running Tests
Unit tests can be run with:
npm run testThis will run the mocha tests with ts-node.
Reliability
A goal of this library is reliable round-trip conversion from ProseMirror to HTML and back without alteration.
The round-trip error rate was improved in three phases:
- Basic Schema: 47% Error Rate
- CDP Schema: 44% Error Rate
- Span Modification: 0% Error Rate
Currently only a single lesson has been tested (IC3 6.3.3). However, all ProseMirror Documents from the lesson were converted successfully.
Acknowledgements
- Eli, Tommy, and Christopher provided instruction and resources.
- AI tools were used for DOMParser code samples.
- CDP Schema was integrated to reduce round-trip error rate.
1.0.1-CPM-11871-addMarkdownSupport-1.0
1 year ago