feature: add subscript and superscript extensions, docs and tests
This commit is contained in:
14
packages/extension-superscript/README.md
Normal file
14
packages/extension-superscript/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# @tiptap/extension-superscript
|
||||
[](https://www.npmjs.com/package/@tiptap/extension-superscript)
|
||||
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
||||
[](https://www.npmjs.com/package/@tiptap/extension-superscript)
|
||||
[](https://github.com/sponsors/ueberdosis)
|
||||
|
||||
## Introduction
|
||||
tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
|
||||
|
||||
## Official Documentation
|
||||
Documentation can be found on the [tiptap website](https://tiptap.dev).
|
||||
|
||||
## License
|
||||
tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
|
||||
26
packages/extension-superscript/package.json
Normal file
26
packages/extension-superscript/package.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "@tiptap/extension-superscript",
|
||||
"description": "superscript extension for tiptap",
|
||||
"version": "2.0.0-beta.1",
|
||||
"homepage": "https://tiptap.dev",
|
||||
"keywords": [
|
||||
"tiptap",
|
||||
"tiptap extension"
|
||||
],
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/ueberdosis"
|
||||
},
|
||||
"main": "dist/tiptap-extension-superscript.cjs.js",
|
||||
"umd": "dist/tiptap-extension-superscript.umd.js",
|
||||
"module": "dist/tiptap-extension-superscript.esm.js",
|
||||
"types": "dist/packages/extension-superscript/src/index.d.ts",
|
||||
"files": [
|
||||
"src",
|
||||
"dist"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"@tiptap/core": "^2.0.0-beta.1"
|
||||
}
|
||||
}
|
||||
5
packages/extension-superscript/src/index.ts
Normal file
5
packages/extension-superscript/src/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Superscript } from './superscript'
|
||||
|
||||
export * from './superscript'
|
||||
|
||||
export default Superscript
|
||||
69
packages/extension-superscript/src/superscript.ts
Normal file
69
packages/extension-superscript/src/superscript.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { Command, Mark, mergeAttributes } from '@tiptap/core'
|
||||
|
||||
export interface SuperscriptExtensionOptions {
|
||||
HTMLAttributes: Object,
|
||||
}
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface Commands {
|
||||
superscript: {
|
||||
/**
|
||||
* Set a superscript mark
|
||||
*/
|
||||
setSuperscript: () => Command,
|
||||
/**
|
||||
* Toggle a superscript mark
|
||||
*/
|
||||
toggleSuperscript: () => Command,
|
||||
/**
|
||||
* Unset a superscript mark
|
||||
*/
|
||||
unsetSuperscript: () => Command,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const Superscript = Mark.create<SuperscriptExtensionOptions>({
|
||||
name: 'superscript',
|
||||
|
||||
defaultOptions: {
|
||||
HTMLAttributes: {},
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: 'sup',
|
||||
},
|
||||
{
|
||||
style: 'vertical-align',
|
||||
getAttrs(value) {
|
||||
// Don’t match this rule if the vertical align isn’t super.
|
||||
if (value !== 'super') {
|
||||
return false
|
||||
}
|
||||
|
||||
// If it falls through we’ll match, and this mark will be applied.
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
return ['sup', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
setSuperscript: () => ({ commands }) => {
|
||||
return commands.setMark('superscript')
|
||||
},
|
||||
toggleSuperscript: () => ({ commands }) => {
|
||||
return commands.toggleMark('superscript')
|
||||
},
|
||||
unsetSuperscript: () => ({ commands }) => {
|
||||
return commands.unsetMark('superscript')
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user