2021-10-08 21:02:09 +08:00
|
|
|
|
import { Extension, textInputRule } from '@tiptap/core'
|
|
|
|
|
|
|
|
|
|
export const emDash = textInputRule({
|
|
|
|
|
find: /--$/,
|
|
|
|
|
replace: '—',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const ellipsis = textInputRule({
|
|
|
|
|
find: /\.\.\.$/,
|
|
|
|
|
replace: '…',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const openDoubleQuote = textInputRule({
|
|
|
|
|
find: /(?:^|[\s{[(<'"\u2018\u201C])(")$/,
|
|
|
|
|
replace: '“',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const closeDoubleQuote = textInputRule({
|
|
|
|
|
find: /"$/,
|
|
|
|
|
replace: '”',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const openSingleQuote = textInputRule({
|
|
|
|
|
find: /(?:^|[\s{[(<'"\u2018\u201C])(')$/,
|
|
|
|
|
replace: '‘',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const closeSingleQuote = textInputRule({
|
|
|
|
|
find: /'$/,
|
|
|
|
|
replace: '’',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const leftArrow = textInputRule({
|
|
|
|
|
find: /<-$/,
|
|
|
|
|
replace: '←',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const rightArrow = textInputRule({
|
|
|
|
|
find: /->$/,
|
|
|
|
|
replace: '→',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const copyright = textInputRule({
|
|
|
|
|
find: /\(c\)$/,
|
|
|
|
|
replace: '©',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const trademark = textInputRule({
|
|
|
|
|
find: /\(tm\)$/,
|
|
|
|
|
replace: '™',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const registeredTrademark = textInputRule({
|
|
|
|
|
find: /\(r\)$/,
|
|
|
|
|
replace: '®',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const oneHalf = textInputRule({
|
|
|
|
|
find: /1\/2$/,
|
|
|
|
|
replace: '½',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const plusMinus = textInputRule({
|
|
|
|
|
find: /\+\/-$/,
|
|
|
|
|
replace: '±',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const notEqual = textInputRule({
|
|
|
|
|
find: /!=$/,
|
|
|
|
|
replace: '≠',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const laquo = textInputRule({
|
|
|
|
|
find: /<<$/,
|
|
|
|
|
replace: '«',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const raquo = textInputRule({
|
|
|
|
|
find: />>$/,
|
|
|
|
|
replace: '»',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const multiplication = textInputRule({
|
|
|
|
|
find: /\d+\s?([*x])\s?\d+$/,
|
|
|
|
|
replace: '×',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const superscriptTwo = textInputRule({
|
|
|
|
|
find: /\^2$/,
|
|
|
|
|
replace: '²',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const superscriptThree = textInputRule({
|
|
|
|
|
find: /\^3$/,
|
|
|
|
|
replace: '³',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const oneQuarter = textInputRule({
|
|
|
|
|
find: /1\/4$/,
|
|
|
|
|
replace: '¼',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const threeQuarters = textInputRule({
|
|
|
|
|
find: /3\/4$/,
|
|
|
|
|
replace: '¾',
|
|
|
|
|
})
|
2020-11-06 05:50:07 +08:00
|
|
|
|
|
2020-12-08 04:32:50 +08:00
|
|
|
|
export const Typography = Extension.create({
|
2020-12-02 16:44:46 +08:00
|
|
|
|
name: 'typography',
|
|
|
|
|
|
2020-11-01 07:28:46 +08:00
|
|
|
|
addInputRules() {
|
|
|
|
|
return [
|
|
|
|
|
emDash,
|
|
|
|
|
ellipsis,
|
|
|
|
|
openDoubleQuote,
|
|
|
|
|
closeDoubleQuote,
|
|
|
|
|
openSingleQuote,
|
|
|
|
|
closeSingleQuote,
|
2020-11-06 06:06:59 +08:00
|
|
|
|
leftArrow,
|
|
|
|
|
rightArrow,
|
|
|
|
|
copyright,
|
2021-08-10 00:19:06 +08:00
|
|
|
|
trademark,
|
2020-11-06 06:06:59 +08:00
|
|
|
|
registeredTrademark,
|
|
|
|
|
oneHalf,
|
|
|
|
|
plusMinus,
|
|
|
|
|
notEqual,
|
|
|
|
|
laquo,
|
|
|
|
|
raquo,
|
2020-11-06 22:31:29 +08:00
|
|
|
|
multiplication,
|
2021-07-22 06:36:08 +08:00
|
|
|
|
superscriptTwo,
|
|
|
|
|
superscriptThree,
|
|
|
|
|
oneQuarter,
|
|
|
|
|
threeQuarters,
|
2020-11-01 07:28:46 +08:00
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
})
|