Files
tiptap/packages/extension-subscript/src/subscript.ts
Dominik 1ebc8f8e14 chore: migrate to new versions of prosemirror packages (#2854)
* refactor: upgrade prosemirror packages to new typescript versions

* refactor: migrate to new typings from prosemirror

* style: fix linting issues

* style: fix linting issues

* style: fix linting issues

* fix(ci): fix build process by reimplement filterTransaction

* fix(extension-test): fix broken build because of wrong output file names

* fix: fix prosemirror-tables not being bundled correctly for ES6

* fix: move to prosemirror-tables-contently until es6 build is working

* fix: fix tests for youtube

* fix: fix youtube test

* fix(demos): fix demos build
2022-06-20 11:45:37 +02:00

79 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Mark, mergeAttributes } from '@tiptap/core'
export interface SubscriptExtensionOptions {
HTMLAttributes: Object,
}
declare module '@tiptap/core' {
interface Commands<ReturnType> {
subscript: {
/**
* Set a subscript mark
*/
setSubscript: () => ReturnType,
/**
* Toggle a subscript mark
*/
toggleSubscript: () => ReturnType,
/**
* Unset a subscript mark
*/
unsetSubscript: () => ReturnType,
}
}
}
export const Subscript = Mark.create<SubscriptExtensionOptions>({
name: 'subscript',
addOptions() {
return {
HTMLAttributes: {},
}
},
parseHTML() {
return [
{
tag: 'sub',
},
{
style: 'vertical-align',
getAttrs(value) {
// Dont match this rule if the vertical align isnt sub.
if (value !== 'sub') {
return false
}
// If it falls through well match, and this mark will be applied.
return null
},
},
]
},
renderHTML({ HTMLAttributes }) {
return ['sub', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
},
addCommands() {
return {
setSubscript: () => ({ commands }) => {
return commands.setMark(this.name)
},
toggleSubscript: () => ({ commands }) => {
return commands.toggleMark(this.name)
},
unsetSubscript: () => ({ commands }) => {
return commands.unsetMark(this.name)
},
}
},
addKeyboardShortcuts() {
return {
'Mod-,': () => this.editor.commands.toggleSubscript(),
}
},
})