tiptap/packages/extension-typography/src/typography.ts

53 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-11-16 06:25:25 +08:00
import { Extension } from '@tiptap/core'
2020-11-01 07:28:46 +08:00
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-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,
registeredTrademark,
oneHalf,
plusMinus,
notEqual,
laquo,
raquo,
2020-11-06 22:31:29 +08:00
multiplication,
2020-11-01 07:28:46 +08:00
]
},
})
declare module '@tiptap/core' {
interface AllExtensions {
Typography: typeof Typography,
2020-11-01 07:28:46 +08:00
}
}