1 import {orderedList, bulletList, listItem} from "prosemirror-schema-list";
4 * @param {HTMLElement} node
5 * @return {string|null}
7 function getAlignAttrFromDomNode(node) {
8 const classList = node.classList;
9 const styles = node.style || {};
10 const alignments = ['right', 'left', 'center', 'justify'];
11 for (const alignment of alignments) {
12 if (classList.contains('align-' + alignment) || styles.textAlign === alignment) {
20 * @param {String} className
21 * @param {Object} attrs
24 function addClassToAttrs(className, attrs) {
25 return Object.assign({}, attrs, {
26 class: attrs.class ? attrs.class + ' ' + className : className,
32 * @param {Object} attrs
35 function addAlignmentAttr(node, attrs) {
36 const positions = ['right', 'left', 'center', 'justify'];
37 for (const position of positions) {
38 if (node.attrs.align === position) {
39 return addClassToAttrs('align-' + position, attrs);
45 function getAttrsParserForAlignment(node) {
47 align: getAlignAttrFromDomNode(node),
61 getAttrs: getAttrsParserForAlignment,
70 return ["p", addAlignmentAttr(node, {}), 0];
78 parseDOM: [{tag: "blockquote", getAttrs: getAttrsParserForAlignment}],
85 return ["blockquote", addAlignmentAttr(node, {}), 0];
89 const horizontal_rule = {
91 parseDOM: [{tag: "hr"}],
98 const headingParseGetAttrs = (level) => {
99 return function (node) {
100 return {level, align: getAlignAttrFromDomNode(node)};
104 attrs: {level: {default: 1}, align: {default: null}},
109 {tag: "h1", getAttrs: headingParseGetAttrs(1)},
110 {tag: "h2", getAttrs: headingParseGetAttrs(2)},
111 {tag: "h3", getAttrs: headingParseGetAttrs(3)},
112 {tag: "h4", getAttrs: headingParseGetAttrs(4)},
113 {tag: "h5", getAttrs: headingParseGetAttrs(5)},
114 {tag: "h6", getAttrs: headingParseGetAttrs(6)},
117 return ["h" + node.attrs.level, addAlignmentAttr(node, {}), 0]
127 parseDOM: [{tag: "pre", preserveWhitespace: "full"}],
129 return ["pre", ["code", 0]];
141 alt: {default: null},
142 title: {default: null},
143 height: {default: null},
144 width: {default: null},
149 tag: "img[src]", getAttrs: function getAttrs(dom) {
151 src: dom.getAttribute("src"),
152 title: dom.getAttribute("title"),
153 alt: dom.getAttribute("alt"),
154 height: dom.getAttribute("height"),
155 width: dom.getAttribute("width"),
159 toDOM: function toDOM(node) {
160 const ref = node.attrs;
163 const title = ref.title;
164 const width = ref.width;
165 const height = ref.height;
166 return ["img", {src, alt, title, width, height}]
174 parseDOM: [{tag: "br"}],
181 const calloutParseGetAttrs = (type) => {
182 return function (node) {
183 return {type, align: getAlignAttrFromDomNode(node)};
188 type: {default: 'info'},
189 align: {default: null},
195 {tag: 'p.callout.info', getAttrs: calloutParseGetAttrs('info'), priority: 75},
196 {tag: 'p.callout.success', getAttrs: calloutParseGetAttrs('success'), priority: 75},
197 {tag: 'p.callout.danger', getAttrs: calloutParseGetAttrs('danger'), priority: 75},
198 {tag: 'p.callout.warning', getAttrs: calloutParseGetAttrs('warning'), priority: 75},
199 {tag: 'p.callout', getAttrs: calloutParseGetAttrs('info'), priority: 75},
202 const type = node.attrs.type || 'info';
203 return ['p', addAlignmentAttr(node, {class: 'callout ' + type}) , 0];
207 const ordered_list = Object.assign({}, orderedList, {content: "list_item+", group: "block"});
208 const bullet_list = Object.assign({}, bulletList, {content: "list_item+", group: "block"});
209 const list_item = Object.assign({}, listItem, {content: 'paragraph block*'});
227 export default nodes;