feature: add subscript and superscript extensions, docs and tests

This commit is contained in:
Hans Pagel
2021-06-01 16:18:25 +02:00
committed by Hans Pagel
parent 7387eaf51b
commit 3f57a13d19
16 changed files with 492 additions and 10 deletions

View File

@@ -0,0 +1,14 @@
# @tiptap/extension-superscript
[![Version](https://img.shields.io/npm/v/@tiptap/extension-superscript.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-superscript)
[![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-superscript.svg)](https://npmcharts.com/compare/tiptap?minimal=true)
[![License](https://img.shields.io/npm/l/@tiptap/extension-superscript.svg)](https://www.npmjs.com/package/@tiptap/extension-superscript)
[![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](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).

View File

@@ -0,0 +1,26 @@
{
"name": "@tiptap/extension-subscript",
"description": "subscript 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-subscript.cjs.js",
"umd": "dist/tiptap-extension-subscript.umd.js",
"module": "dist/tiptap-extension-subscript.esm.js",
"types": "dist/packages/extension-subscript/src/index.d.ts",
"files": [
"src",
"dist"
],
"peerDependencies": {
"@tiptap/core": "^2.0.0-beta.1"
}
}

View File

@@ -0,0 +1,5 @@
import { Subscript } from './subscript'
export * from './subscript'
export default Subscript

View File

@@ -0,0 +1,69 @@
import { Command, Mark, mergeAttributes } from '@tiptap/core'
export interface SubscriptExtensionOptions {
HTMLAttributes: Object,
}
declare module '@tiptap/core' {
interface Commands {
subscript: {
/**
* Set a subscript mark
*/
setSubscript: () => Command,
/**
* Toggle a subscript mark
*/
toggleSubscript: () => Command,
/**
* Unset a subscript mark
*/
unsetSubscript: () => Command,
}
}
}
export const Subscript = Mark.create<SubscriptExtensionOptions>({
name: 'subscript',
defaultOptions: {
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.
},
},
]
},
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')
},
}
},
})

View File

@@ -0,0 +1,14 @@
# @tiptap/extension-superscript
[![Version](https://img.shields.io/npm/v/@tiptap/extension-superscript.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-superscript)
[![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-superscript.svg)](https://npmcharts.com/compare/tiptap?minimal=true)
[![License](https://img.shields.io/npm/l/@tiptap/extension-superscript.svg)](https://www.npmjs.com/package/@tiptap/extension-superscript)
[![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](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).

View 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"
}
}

View File

@@ -0,0 +1,5 @@
import { Superscript } from './superscript'
export * from './superscript'
export default Superscript

View 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) {
// Dont match this rule if the vertical align isnt super.
if (value !== 'super') {
return false
}
// If it falls through well 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')
},
}
},
})