You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
4.6 KiB

3 years ago
import { textInputRule, Extension } from '@tiptap/core';
const emDash = textInputRule({
find: /--$/,
replace: '—',
});
const ellipsis = textInputRule({
find: /\.\.\.$/,
replace: '…',
});
const openDoubleQuote = textInputRule({
find: /(?:^|[\s{[(<'"\u2018\u201C])(")$/,
replace: '“',
});
const closeDoubleQuote = textInputRule({
find: /"$/,
replace: '”',
});
const openSingleQuote = textInputRule({
find: /(?:^|[\s{[(<'"\u2018\u201C])(')$/,
replace: '',
});
const closeSingleQuote = textInputRule({
find: /'$/,
replace: '',
});
const leftArrow = textInputRule({
find: /<-$/,
replace: '←',
});
const rightArrow = textInputRule({
find: /->$/,
replace: '→',
});
const copyright = textInputRule({
find: /\(c\)$/,
replace: '©',
});
const trademark = textInputRule({
find: /\(tm\)$/,
replace: '™',
});
const servicemark = textInputRule({
find: /\(sm\)$/,
replace: '℠',
});
const registeredTrademark = textInputRule({
find: /\(r\)$/,
replace: '®',
});
const oneHalf = textInputRule({
find: /1\/2$/,
replace: '½',
});
const plusMinus = textInputRule({
find: /\+\/-$/,
replace: '±',
});
const notEqual = textInputRule({
find: /!=$/,
replace: '≠',
});
const laquo = textInputRule({
find: /<<$/,
replace: '«',
});
const raquo = textInputRule({
find: />>$/,
replace: '»',
});
const multiplication = textInputRule({
find: /\d+\s?([*x])\s?\d+$/,
replace: '×',
});
const superscriptTwo = textInputRule({
find: /\^2$/,
replace: '²',
});
const superscriptThree = textInputRule({
find: /\^3$/,
replace: '³',
});
const oneQuarter = textInputRule({
find: /1\/4$/,
replace: '¼',
});
const threeQuarters = textInputRule({
find: /3\/4$/,
replace: '¾',
});
const Typography = Extension.create({
name: 'typography',
addInputRules() {
const rules = [];
if (this.options.emDash !== false) {
rules.push(emDash);
}
if (this.options.ellipsis !== false) {
rules.push(ellipsis);
}
if (this.options.openDoubleQuote !== false) {
rules.push(openDoubleQuote);
}
if (this.options.closeDoubleQuote !== false) {
rules.push(closeDoubleQuote);
}
if (this.options.openSingleQuote !== false) {
rules.push(openSingleQuote);
}
if (this.options.closeSingleQuote !== false) {
rules.push(closeSingleQuote);
}
if (this.options.leftArrow !== false) {
rules.push(leftArrow);
}
if (this.options.rightArrow !== false) {
rules.push(rightArrow);
}
if (this.options.copyright !== false) {
rules.push(copyright);
}
if (this.options.trademark !== false) {
rules.push(trademark);
}
if (this.options.servicemark !== false) {
rules.push(servicemark);
}
if (this.options.registeredTrademark !== false) {
rules.push(registeredTrademark);
}
if (this.options.oneHalf !== false) {
rules.push(oneHalf);
}
if (this.options.plusMinus !== false) {
rules.push(plusMinus);
}
if (this.options.notEqual !== false) {
rules.push(notEqual);
}
if (this.options.laquo !== false) {
rules.push(laquo);
}
if (this.options.raquo !== false) {
rules.push(raquo);
}
if (this.options.multiplication !== false) {
rules.push(multiplication);
}
if (this.options.superscriptTwo !== false) {
rules.push(superscriptTwo);
}
if (this.options.superscriptThree !== false) {
rules.push(superscriptThree);
}
if (this.options.oneQuarter !== false) {
rules.push(oneQuarter);
}
if (this.options.threeQuarters !== false) {
rules.push(threeQuarters);
}
return rules;
},
});
export { Typography, closeDoubleQuote, closeSingleQuote, copyright, Typography as default, ellipsis, emDash, laquo, leftArrow, multiplication, notEqual, oneHalf, oneQuarter, openDoubleQuote, openSingleQuote, plusMinus, raquo, registeredTrademark, rightArrow, servicemark, superscriptThree, superscriptTwo, threeQuarters, trademark };
//# sourceMappingURL=tiptap-extension-typography.esm.js.map