tiptap/packages/extension-typography/index.ts

53 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-11-01 07:28:46 +08:00
import { createExtension } from '@tiptap/core'
import {
emDash,
ellipsis,
openDoubleQuote,
closeDoubleQuote,
openSingleQuote,
closeSingleQuote,
2020-11-06 05:50:07 +08:00
InputRule,
2020-11-01 07:28:46 +08:00
} from 'prosemirror-inputrules'
2020-11-06 06:06:59 +08:00
export const leftArrow = new InputRule(/<-$/, '←')
export const rightArrow = new InputRule(/->$/, '→')
export const copyright = new InputRule(/\(c\)$/, '©')
export const registeredTrademark = new InputRule(/\(r\)$/, '®')
export const oneHalf = new InputRule(/1\/2$/, '½')
export const plusMinus = new InputRule(/\+\/-$/, '±')
export const notEqual = new InputRule(/!=$/, '≠')
export const laquo = new InputRule(/<<$/, '«')
export const raquo = new InputRule(/>>$/, '»')
2020-11-06 22:31:29 +08:00
export const multiplication = new InputRule(/\d+\s?([*x])\s?\d+$/, '×')
2020-11-06 05:50:07 +08:00
2020-11-01 07:28:46 +08:00
const Typography = createExtension({
addInputRules() {
return [
emDash,
ellipsis,
openDoubleQuote,
closeDoubleQuote,
openSingleQuote,
closeSingleQuote,
2020-11-06 06:06:59 +08:00
leftArrow,
rightArrow,
copyright,
registeredTrademark,
oneHalf,
plusMinus,
notEqual,
laquo,
raquo,
2020-11-06 22:31:29 +08:00
multiplication,
2020-11-01 07:28:46 +08:00
]
},
})
export default Typography
declare module '@tiptap/core/src/Editor' {
interface AllExtensions {
Typography: typeof Typography,
}
}