2021-08-25 18:11:33 +00:00
|
|
|
import { Mark, mergeAttributes, markInputRule } from '@tiptap/core';
|
|
|
|
import { PARSE_HTML_PRIORITY_LOWEST } from '../constants';
|
|
|
|
import { markInputRegex, extractMarkAttributesFromMatch } from '../services/mark_utils';
|
|
|
|
|
|
|
|
const marks = [
|
|
|
|
'ins',
|
|
|
|
'abbr',
|
|
|
|
'bdo',
|
|
|
|
'cite',
|
|
|
|
'dfn',
|
|
|
|
'mark',
|
|
|
|
'small',
|
|
|
|
'span',
|
|
|
|
'time',
|
|
|
|
'kbd',
|
|
|
|
'q',
|
|
|
|
'samp',
|
|
|
|
'var',
|
|
|
|
'ruby',
|
|
|
|
'rp',
|
|
|
|
'rt',
|
|
|
|
];
|
|
|
|
|
|
|
|
const attrs = {
|
|
|
|
time: ['datetime'],
|
|
|
|
abbr: ['title'],
|
|
|
|
span: ['dir'],
|
|
|
|
bdo: ['dir'],
|
|
|
|
};
|
|
|
|
|
|
|
|
export default marks.map((name) =>
|
|
|
|
Mark.create({
|
|
|
|
name,
|
|
|
|
inclusive: false,
|
2021-11-18 18:14:27 +00:00
|
|
|
addOptions() {
|
|
|
|
return {
|
|
|
|
HTMLAttributes: {},
|
|
|
|
};
|
2021-08-25 18:11:33 +00:00
|
|
|
},
|
|
|
|
addAttributes() {
|
|
|
|
return (attrs[name] || []).reduce(
|
|
|
|
(acc, attr) => ({
|
|
|
|
...acc,
|
|
|
|
[attr]: {
|
|
|
|
default: null,
|
2021-09-16 15:12:47 +00:00
|
|
|
parseHTML: (element) => element.getAttribute(attr),
|
2021-08-25 18:11:33 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
parseHTML() {
|
|
|
|
return [{ tag: name, priority: PARSE_HTML_PRIORITY_LOWEST }];
|
|
|
|
},
|
|
|
|
|
|
|
|
renderHTML({ HTMLAttributes }) {
|
|
|
|
return [name, mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
|
|
|
|
},
|
|
|
|
|
|
|
|
addInputRules() {
|
2021-10-22 09:09:20 +00:00
|
|
|
return [
|
|
|
|
markInputRule({
|
|
|
|
find: markInputRegex(name),
|
|
|
|
type: this.type,
|
|
|
|
getAttributes: extractMarkAttributesFromMatch,
|
|
|
|
}),
|
|
|
|
];
|
2021-08-25 18:11:33 +00:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|