add arrows to the typography extension

This commit is contained in:
Hans Pagel 2020-11-05 22:50:07 +01:00
parent 44865a2ea7
commit 7a7e517577
3 changed files with 21 additions and 1 deletions

View File

@ -44,4 +44,16 @@ context('/api/extensions/typography', () => {
.type("'closeSingleQuote'")
.should('contain', 'closeSingleQuote')
})
it('should make a leftwards arrow', () => {
cy.get('.ProseMirror')
.type('<- leftwardsArrow')
.should('contain', '← leftwardsArrow')
})
it('should make a rightwards arrow', () => {
cy.get('.ProseMirror')
.type('-> rightwardsArrow')
.should('contain', '→ rightwardsArrow')
})
})

View File

@ -1,5 +1,5 @@
# Typography
This extension tries to help with common text patterns with the correct typographic character.
This extension tries to help with common text patterns with the correct typographic character. Under the hood all rules are input rules.
## Installation
```bash
@ -19,6 +19,8 @@ yarn add @tiptap/typography
| closeDoubleQuote | “Smart`”` closing double quotes. |
| openSingleQuote | ``Smart opening single quotes. |
| closeSingleQuote | Smart`` closing single quotes. |
| leftwardsArrow | Converts <code><&dash;</code> to an arrow `←`. |
| leftwardsArrow | Converts <code>&dash;></code> to an arrow `→`. |
## Source code
[packages/typography/](https://github.com/ueberdosis/tiptap-next/blob/main/packages/typography/)

View File

@ -6,8 +6,12 @@ import {
closeDoubleQuote,
openSingleQuote,
closeSingleQuote,
InputRule,
} from 'prosemirror-inputrules'
export const leftwardsArrow = new InputRule(/<-$/, '←')
export const rightwardsArrow = new InputRule(/->$/, '→')
const Typography = createExtension({
addInputRules() {
return [
@ -17,6 +21,8 @@ const Typography = createExtension({
closeDoubleQuote,
openSingleQuote,
closeSingleQuote,
leftwardsArrow,
rightwardsArrow,
]
},
})