1 import {orderedList, bulletList, listItem} from "prosemirror-schema-list";
2 import {tableNodes} from "prosemirror-tables";
5 * @param {HTMLElement} node
6 * @return {string|null}
8 function getAlignAttrFromDomNode(node) {
9 const classList = node.classList;
10 const styles = node.style || {};
11 const alignments = ['right', 'left', 'center', 'justify'];
12 for (const alignment of alignments) {
13 if (classList.contains('align-' + alignment) || styles.textAlign === alignment) {
21 * @param {String} className
22 * @param {Object} attrs
25 function addClassToAttrs(className, attrs) {
26 return Object.assign({}, attrs, {
27 class: attrs.class ? attrs.class + ' ' + className : className,
33 * @param {Object} attrs
36 function addAlignmentAttr(node, attrs) {
37 const positions = ['right', 'left', 'center', 'justify'];
38 for (const position of positions) {
39 if (node.attrs.align === position) {
40 return addClassToAttrs('align-' + position, attrs);
46 function getAttrsParserForAlignment(node) {
48 align: getAlignAttrFromDomNode(node),
62 getAttrs: getAttrsParserForAlignment,
71 return ["p", addAlignmentAttr(node, {}), 0];
79 parseDOM: [{tag: "blockquote", getAttrs: getAttrsParserForAlignment}],
86 return ["blockquote", addAlignmentAttr(node, {}), 0];
90 const horizontal_rule = {
92 parseDOM: [{tag: "hr"}],
99 const headingParseGetAttrs = (level) => {
100 return function (node) {
101 return {level, align: getAlignAttrFromDomNode(node)};
105 attrs: {level: {default: 1}, align: {default: null}},
110 {tag: "h1", getAttrs: headingParseGetAttrs(1)},
111 {tag: "h2", getAttrs: headingParseGetAttrs(2)},
112 {tag: "h3", getAttrs: headingParseGetAttrs(3)},
113 {tag: "h4", getAttrs: headingParseGetAttrs(4)},
114 {tag: "h5", getAttrs: headingParseGetAttrs(5)},
115 {tag: "h6", getAttrs: headingParseGetAttrs(6)},
118 return ["h" + node.attrs.level, addAlignmentAttr(node, {}), 0]
128 parseDOM: [{tag: "pre", preserveWhitespace: "full"}],
130 return ["pre", ["code", 0]];
142 alt: {default: null},
143 title: {default: null},
144 height: {default: null},
145 width: {default: null},
150 tag: "img[src]", getAttrs: function getAttrs(dom) {
152 src: dom.getAttribute("src"),
153 title: dom.getAttribute("title"),
154 alt: dom.getAttribute("alt"),
155 height: dom.getAttribute("height"),
156 width: dom.getAttribute("width"),
160 toDOM: function toDOM(node) {
161 const ref = node.attrs;
164 const title = ref.title;
165 const width = ref.width;
166 const height = ref.height;
167 return ["img", {src, alt, title, width, height}]
175 parseDOM: [{tag: "br"}],
182 const calloutParseGetAttrs = (type) => {
183 return function (node) {
184 return {type, align: getAlignAttrFromDomNode(node)};
189 type: {default: 'info'},
190 align: {default: null},
196 {tag: 'p.callout.info', getAttrs: calloutParseGetAttrs('info'), priority: 75},
197 {tag: 'p.callout.success', getAttrs: calloutParseGetAttrs('success'), priority: 75},
198 {tag: 'p.callout.danger', getAttrs: calloutParseGetAttrs('danger'), priority: 75},
199 {tag: 'p.callout.warning', getAttrs: calloutParseGetAttrs('warning'), priority: 75},
200 {tag: 'p.callout', getAttrs: calloutParseGetAttrs('info'), priority: 75},
203 const type = node.attrs.type || 'info';
204 return ['p', addAlignmentAttr(node, {class: 'callout ' + type}), 0];
208 const ordered_list = Object.assign({}, orderedList, {content: "list_item+", group: "block"});
209 const bullet_list = Object.assign({}, bulletList, {content: "list_item+", group: "block"});
210 const list_item = Object.assign({}, listItem, {content: 'paragraph block*'});
219 cellContent: "block*"
242 export default nodes;