From 4999285796585161e500c8cbc456c0c81ca1ee4b Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Wed, 20 Oct 2021 14:43:41 +0200 Subject: [PATCH] add an abbreviation extension --- demos/src/Marks/Abbreviation/Vue/index.html | 15 ++++ .../src/Marks/Abbreviation/Vue/index.spec.js | 7 ++ demos/src/Marks/Abbreviation/Vue/index.vue | 80 +++++++++++++++++++ packages/extension-abbreviation/README.md | 14 ++++ packages/extension-abbreviation/package.json | 31 +++++++ .../src/abbreviation.ts | 73 +++++++++++++++++ packages/extension-abbreviation/src/index.ts | 5 ++ 7 files changed, 225 insertions(+) create mode 100644 demos/src/Marks/Abbreviation/Vue/index.html create mode 100644 demos/src/Marks/Abbreviation/Vue/index.spec.js create mode 100644 demos/src/Marks/Abbreviation/Vue/index.vue create mode 100644 packages/extension-abbreviation/README.md create mode 100644 packages/extension-abbreviation/package.json create mode 100644 packages/extension-abbreviation/src/abbreviation.ts create mode 100644 packages/extension-abbreviation/src/index.ts diff --git a/demos/src/Marks/Abbreviation/Vue/index.html b/demos/src/Marks/Abbreviation/Vue/index.html new file mode 100644 index 000000000..7e6ada02f --- /dev/null +++ b/demos/src/Marks/Abbreviation/Vue/index.html @@ -0,0 +1,15 @@ + + + + + + + +
+ + + diff --git a/demos/src/Marks/Abbreviation/Vue/index.spec.js b/demos/src/Marks/Abbreviation/Vue/index.spec.js new file mode 100644 index 000000000..657f13141 --- /dev/null +++ b/demos/src/Marks/Abbreviation/Vue/index.spec.js @@ -0,0 +1,7 @@ +context('/src/Marks/Abbreviation/Vue/', () => { + before(() => { + cy.visit('/src/Marks/Abbreviation/Vue/') + }) + + // TODO: Write tests +}) diff --git a/demos/src/Marks/Abbreviation/Vue/index.vue b/demos/src/Marks/Abbreviation/Vue/index.vue new file mode 100644 index 000000000..12f7a6eee --- /dev/null +++ b/demos/src/Marks/Abbreviation/Vue/index.vue @@ -0,0 +1,80 @@ + + + diff --git a/packages/extension-abbreviation/README.md b/packages/extension-abbreviation/README.md new file mode 100644 index 000000000..8db960f94 --- /dev/null +++ b/packages/extension-abbreviation/README.md @@ -0,0 +1,14 @@ +# @tiptap/extension-abbreviation +[![Version](https://img.shields.io/npm/v/@tiptap/extension-abbreviation.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-abbreviation) +[![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-abbreviation.svg)](https://npmcharts.com/compare/tiptap?minimal=true) +[![License](https://img.shields.io/npm/l/@tiptap/extension-abbreviation.svg)](https://www.npmjs.com/package/@tiptap/extension-abbreviation) +[![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). diff --git a/packages/extension-abbreviation/package.json b/packages/extension-abbreviation/package.json new file mode 100644 index 000000000..8d21f6ad7 --- /dev/null +++ b/packages/extension-abbreviation/package.json @@ -0,0 +1,31 @@ +{ + "name": "@tiptap/extension-abbreviation", + "description": "document 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-abbreviation.cjs.js", + "umd": "dist/tiptap-extension-abbreviation.umd.js", + "module": "dist/tiptap-extension-abbreviation.esm.js", + "types": "dist/packages/extension-abbreviation/src/index.d.ts", + "files": [ + "src", + "dist" + ], + "peerDependencies": { + "@tiptap/core": "^2.0.0-beta.1" + }, + "repository": { + "type": "git", + "url": "https://github.com/ueberdosis/tiptap", + "directory": "packages/extension-abbreviation" + } +} diff --git a/packages/extension-abbreviation/src/abbreviation.ts b/packages/extension-abbreviation/src/abbreviation.ts new file mode 100644 index 000000000..7861e7279 --- /dev/null +++ b/packages/extension-abbreviation/src/abbreviation.ts @@ -0,0 +1,73 @@ +import { Mark } from '@tiptap/core' + +export interface AbbreviationOptions { + HTMLAttributes: Record, +} + +declare module '@tiptap/core' { + interface Commands { + abbreviation: { + /** + * Set an abbreviation mark + */ + setAbbreviation: (title?: string) => ReturnType, + /** + * Toggle an abbreviation mark + */ + toggleAbbreviation: (title?: string) => ReturnType, + /** + * Unset an abbreviation mark + */ + unsetAbbreviation: () => ReturnType, + } + } +} + +export const Abbreviation = Mark.create({ + name: 'abbreviation', + + defaultOptions: { + HTMLAttributes: {}, + }, + + addAttributes() { + return { + title: { + default: null, + }, + } + }, + + parseHTML() { + return [ + { + tag: 'abbr', + }, + { + tag: 'acronym', + }, + ] + }, + + renderHTML({ HTMLAttributes }) { + return ['abbr', HTMLAttributes, 0] + }, + + addCommands() { + return { + setAbbreviation: title => ({ commands }) => { + return commands.setMark('abbreviation', { + title, + }) + }, + toggleAbbreviation: title => ({ commands }) => { + return commands.toggleMark('abbreviation', { + title, + }) + }, + unsetAbbreviation: () => ({ commands }) => { + return commands.unsetMark('abbreviation') + }, + } + }, +}) diff --git a/packages/extension-abbreviation/src/index.ts b/packages/extension-abbreviation/src/index.ts new file mode 100644 index 000000000..4a279d11f --- /dev/null +++ b/packages/extension-abbreviation/src/index.ts @@ -0,0 +1,5 @@ +import { Abbreviation } from './abbreviation' + +export * from './abbreviation' + +export default Abbreviation