fix build for now
This commit is contained in:
67
packages/extension-italic/src/index.ts
Normal file
67
packages/extension-italic/src/index.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import {
|
||||
Command, createMark, markInputRule, markPasteRule,
|
||||
} from '@tiptap/core'
|
||||
|
||||
export const starInputRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/gm
|
||||
export const starPasteRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))/gm
|
||||
export const underscoreInputRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))$/gm
|
||||
export const underscorePasteRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))/gm
|
||||
|
||||
const Italic = createMark({
|
||||
name: 'italic',
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: 'em',
|
||||
},
|
||||
{
|
||||
tag: 'i',
|
||||
getAttrs: node => (node as HTMLElement).style.fontStyle !== 'normal' && null,
|
||||
},
|
||||
{
|
||||
style: 'font-style=italic',
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
renderHTML({ attributes }) {
|
||||
return ['em', attributes, 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
italic: (): Command => ({ commands }) => {
|
||||
return commands.toggleMark('italic')
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
return {
|
||||
'Mod-i': () => this.editor.italic(),
|
||||
}
|
||||
},
|
||||
|
||||
addInputRules() {
|
||||
return [
|
||||
markInputRule(starInputRegex, this.type),
|
||||
markInputRule(underscoreInputRegex, this.type),
|
||||
]
|
||||
},
|
||||
|
||||
addPasteRules() {
|
||||
return [
|
||||
markPasteRule(starPasteRegex, this.type),
|
||||
markPasteRule(underscorePasteRegex, this.type),
|
||||
]
|
||||
},
|
||||
})
|
||||
|
||||
export default Italic
|
||||
|
||||
declare module '@tiptap/core/src/Editor' {
|
||||
interface AllExtensions {
|
||||
Italic: typeof Italic,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user