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.

1 line
9.5 KiB

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