Skip to content

Instantly share code, notes, and snippets.

@joevallender
Last active May 24, 2021 09:33
Show Gist options
  • Save joevallender/47e957298d7fbf4c41f5a1ba462d1d59 to your computer and use it in GitHub Desktop.
Save joevallender/47e957298d7fbf4c41f5a1ba462d1d59 to your computer and use it in GitHub Desktop.
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