add react demo for markdown shortcuts

This commit is contained in:
Philipp Kühn
2021-06-25 11:28:28 +02:00
parent 9abf46b371
commit 68d64baf99
5 changed files with 102 additions and 11 deletions

View File

@@ -0,0 +1,37 @@
import React from 'react'
import { useEditor, EditorContent } from '@tiptap/react'
import StarterKit from '@tiptap/starter-kit'
import Highlight from '@tiptap/extension-highlight'
import Typography from '@tiptap/extension-typography'
import './styles.scss'
export default () => {
const editor = useEditor({
extensions: [
StarterKit,
Highlight,
Typography,
],
content: `
<p>
Markdown shortcuts make it easy to format the text while typing.
</p>
<p>
To test that, start a new line and type <code>#</code> followed by a space to get a heading. Try <code>#</code>, <code>##</code>, <code>###</code>, <code>####</code>, <code>#####</code>, <code>######</code> for different levels.
</p>
<p>
Those conventions are called input rules in tiptap. Some of them are enabled by default. Try <code>></code> for blockquotes, <code>*</code>, <code>-</code> or <code>+</code> for bullet lists, or <code>\`foobar\`</code> to highlight code, <code>~~tildes~~</code> to strike text, or <code>==equal signs==</code> to highlight text.
</p>
<p>
You can overwrite existing input rules or add your own to nodes, marks and extensions.
</p>
<p>
For example, we added the <code>Typography</code> extension here. Try typing <code>(c)</code> to see how its converted to a proper © character. You can also try <code>-></code>, <code>>></code>, <code>1/2</code>, <code>!=</code>, or <code>--</code>.
</p>
`,
})
return (
<EditorContent editor={editor} />
)
}

View File

@@ -0,0 +1,53 @@
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
ul,
ol {
padding: 0 1rem;
}
h1,
h2,
h3,
h4,
h5,
h6 {
line-height: 1.1;
}
code {
background-color: rgba(#616161, 0.1);
color: #616161;
}
pre {
background: #0D0D0D;
color: #FFF;
font-family: 'JetBrainsMono', monospace;
padding: 0.75rem 1rem;
border-radius: 0.5rem;
code {
color: inherit;
padding: 0;
background: none;
font-size: 0.8rem;
}
}
img {
max-width: 100%;
height: auto;
}
hr {
margin: 1rem 0;
}
blockquote {
padding-left: 1rem;
border-left: 2px solid rgba(#0D0D0D, 0.1);
}
}

View File

@@ -1,6 +1,6 @@
context('/demos/Examples/MarkdownShortcuts', () => {
context('/demos/Examples/MarkdownShortcuts/Vue', () => {
before(() => {
cy.visit('/demos/Examples/MarkdownShortcuts')
cy.visit('/demos/Examples/MarkdownShortcuts/Vue')
})
beforeEach(() => {

View File

@@ -1,7 +1,5 @@
<template>
<div>
<editor-content :editor="editor" />
</div>
</template>
<script>
@@ -23,6 +21,11 @@ export default {
mounted() {
this.editor = new Editor({
extensions: [
StarterKit,
Highlight,
Typography,
],
content: `
<p>
Markdown shortcuts make it easy to format the text while typing.
@@ -40,11 +43,6 @@ export default {
For example, we added the <code>Typography</code> extension here. Try typing <code>(c)</code> to see how its converted to a proper © character. You can also try <code>-></code>, <code>>></code>, <code>1/2</code>, <code>!=</code>, or <code>--</code>.
</p>
`,
extensions: [
StarterKit,
Highlight,
Typography,
],
})
},

View File

@@ -1,3 +1,6 @@
# Markdown shortcuts
<demo name="Examples/MarkdownShortcuts" />
<demos :items="{
Vue: 'Examples/MarkdownShortcuts/Vue',
React: 'Examples/MarkdownShortcuts/React',
}" />