Last active
May 24, 2021 09:33
-
-
Save joevallender/47e957298d7fbf4c41f5a1ba462d1d59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Mark, mergeAttributes } from '@tiptap/core' | |
export const Subscript = Mark.create({ | |
name: 'subscript', | |
defaultOptions: { | |
HTMLAttributes: {}, | |
}, | |
parseHTML() { | |
return [ | |
{ | |
tag: 'sub', | |
}, | |
{ | |
style: 'vertical-align', | |
getAttrs(value) { | |
// Don't match this rule if the vertical align isn't sub. | |
if (value !== 'sub') { | |
return false; | |
} | |
// If it falls through we'll match, and this mark will be applied. | |
}, | |
}, | |
] | |
}, | |
renderHTML({ HTMLAttributes }) { | |
return ['sub', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0] | |
}, | |
addCommands() { | |
return { | |
setSubscript: () => ({ commands }) => { | |
return commands.setMark('subscript') | |
}, | |
toggleSubscript: () => ({ commands }) => { | |
return commands.toggleMark('subscript') | |
}, | |
unsetSubscript: () => ({ commands }) => { | |
return commands.unsetMark('subscript') | |
}, | |
} | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment