From 64da5cbcf78ebf2dc4ef756a39487b36b7de8976 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Fri, 2 Oct 2020 14:54:10 +0200 Subject: [PATCH 1/8] add tilde markdown shortcut support to code blocks --- .../demos/Extensions/CodeBlock/index.spec.js | 46 ++++++++++++++----- packages/extension-code-block/index.ts | 6 ++- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/docs/src/demos/Extensions/CodeBlock/index.spec.js b/docs/src/demos/Extensions/CodeBlock/index.spec.js index 746605c0..7da58542 100644 --- a/docs/src/demos/Extensions/CodeBlock/index.spec.js +++ b/docs/src/demos/Extensions/CodeBlock/index.spec.js @@ -58,17 +58,6 @@ context('/api/extensions/code-block', () => { .should('not.exist') }) - it('should make a code block from markdown shortcuts', () => { - cy.get('.ProseMirror').then(([{ editor }]) => { - editor.clearContent() - - cy.get('.ProseMirror') - .type('``` Code') - .find('pre>code') - .should('contain', 'Code') - }) - }) - it('should parse the language from a HTML code block', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.setContent('
body { display: none; }
') @@ -79,7 +68,29 @@ context('/api/extensions/code-block', () => { }) }) - it('should make a code block for js', () => { + it('should make a code block from backtick markdown shortcuts', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.clearContent() + + cy.get('.ProseMirror') + .type('``` Code') + .find('pre>code') + .should('contain', 'Code') + }) + }) + + it('should make a code block from tilde markdown shortcuts', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.clearContent() + + cy.get('.ProseMirror') + .type('~~~ Code') + .find('pre>code') + .should('contain', 'Code') + }) + }) + + it('should make a code block for js with backticks', () => { cy.get('.ProseMirror').then(([{ editor }]) => { editor.clearContent() @@ -89,4 +100,15 @@ context('/api/extensions/code-block', () => { .should('contain', 'Code') }) }) + + it('should make a code block for js with tildes', () => { + cy.get('.ProseMirror').then(([{ editor }]) => { + editor.clearContent() + + cy.get('.ProseMirror') + .type('~~~js Code') + .find('pre>code.language-js') + .should('contain', 'Code') + }) + }) }) diff --git a/packages/extension-code-block/index.ts b/packages/extension-code-block/index.ts index 4119e7ec..9b69b8fb 100644 --- a/packages/extension-code-block/index.ts +++ b/packages/extension-code-block/index.ts @@ -13,7 +13,8 @@ declare module '@tiptap/core/src/Editor' { } } -export const inputRegex = /^```(?[a-z]*)? $/ +export const backtickInputRegex = /^```(?[a-z]*)? $/ +export const tildeInputRegex = /^~~~(?[a-z]*)? $/ export default new Node() .name('code_block') @@ -62,6 +63,7 @@ export default new Node() 'Shift-Control-\\': () => editor.codeBlock(), })) .inputRules(({ type }) => [ - textblockTypeInputRule(inputRegex, type, ({ groups }: any) => groups), + textblockTypeInputRule(backtickInputRegex, type, ({ groups }: any) => groups), + textblockTypeInputRule(tildeInputRegex, type, ({ groups }: any) => groups), ]) .create() From eeec5b68718db612f1919642859e2f0b4e3a78bf Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Fri, 2 Oct 2020 15:05:26 +0200 Subject: [PATCH 2/8] change markdown shortcut for striked text to two tildes --- docs/src/demos/Extensions/Strike/index.spec.js | 2 +- docs/src/docPages/api/extensions/strike.md | 2 +- packages/extension-strike/index.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/src/demos/Extensions/Strike/index.spec.js b/docs/src/demos/Extensions/Strike/index.spec.js index ad51e03f..54db052b 100644 --- a/docs/src/demos/Extensions/Strike/index.spec.js +++ b/docs/src/demos/Extensions/Strike/index.spec.js @@ -51,7 +51,7 @@ context('/api/extensions/strike', () => { it('should make a striked text from the markdown shortcut', () => { cy.get('.ProseMirror') - .type('~Strike~') + .type('~~Strike~~') .find('s') .should('contain', 'Strike') }) diff --git a/docs/src/docPages/api/extensions/strike.md b/docs/src/docPages/api/extensions/strike.md index 15729c2e..4cff00dd 100644 --- a/docs/src/docPages/api/extensions/strike.md +++ b/docs/src/docPages/api/extensions/strike.md @@ -1,7 +1,7 @@ # Strike Use this extension to render ~~striked text~~. If you pass ``, ``, `` tags, or text with inline `style` attributes setting `text-decoration: line-through` in the editor’s initial content, they all will be rendered accordingly. -Type ~text between tildes~ and it will be magically ~~striked through~~ while you type. +Type ∼∼text between tildes∼∼ and it will be magically ~~striked through~~ while you type. ::: warning Restrictions The extension will generate the corresponding `` HTML tags when reading contents of the `Editor` instance. All text striked through, regardless of the method will be normalized to `` HTML tags. diff --git a/packages/extension-strike/index.ts b/packages/extension-strike/index.ts index 2f33e1cc..2813884e 100644 --- a/packages/extension-strike/index.ts +++ b/packages/extension-strike/index.ts @@ -10,8 +10,8 @@ declare module '@tiptap/core/src/Editor' { } } -export const inputRegex = /(?:^|\s)((?:~)((?:[^~]+))(?:~))$/gm -export const pasteRegex = /(?:^|\s)((?:~)((?:[^~]+))(?:~))/gm +export const inputRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/gm +export const pasteRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/gm export default new Mark() .name('strike') From 26504027b746c7c7df5e23a2baedb5fc04346b95 Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Fri, 2 Oct 2020 15:12:01 +0200 Subject: [PATCH 3/8] update the documentation --- docs/src/docPages/api/extensions/code-block.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/docPages/api/extensions/code-block.md b/docs/src/docPages/api/extensions/code-block.md index 6608c521..a87e56d3 100644 --- a/docs/src/docPages/api/extensions/code-block.md +++ b/docs/src/docPages/api/extensions/code-block.md @@ -1,7 +1,7 @@ # CodeBlock With the CodeBlock extension you can add fenced code blocks to your documents. It’ll wrap the code in `
` and `` HTML tags.
 
-Type three backticks and a space ``` and a code block is instantly added for you.
+Type ```  (three backticks and a space) or ∼∼∼  (three tildes and a space) and a code block is instantly added for you. You can even specify the language, try writing ```css . That should add a `language-css` class to the ``-tag.
 
 ::: warning Restrictions
 The CodeBlock extension doesn’t come with styling and has no syntax highlighting built-in. It’s on our roadmap though.

From eabcecb550e90b37be7dbb697b0f58ea4604cf91 Mon Sep 17 00:00:00 2001
From: Hans Pagel 
Date: Fri, 2 Oct 2020 15:45:45 +0200
Subject: [PATCH 4/8] add comment about broken autoFocus option

---
 docs/src/demos/Examples/Focus/index.spec.js | 2 --
 docs/src/demos/Examples/Focus/index.vue     | 2 +-
 docs/src/links.yaml                         | 4 ++--
 packages/core/src/Editor.ts                 | 7 +++++++
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/docs/src/demos/Examples/Focus/index.spec.js b/docs/src/demos/Examples/Focus/index.spec.js
index f36629de..1c7271a6 100644
--- a/docs/src/demos/Examples/Focus/index.spec.js
+++ b/docs/src/demos/Examples/Focus/index.spec.js
@@ -5,8 +5,6 @@ context('/examples/focus', () => {
 
   it('should have class', () => {
     cy.get('.ProseMirror').then(([{ editor }]) => {
-      editor.focus('start')
-
       cy.get('.ProseMirror p:first').should('have.class', 'has-focus')
     })
   })
diff --git a/docs/src/demos/Examples/Focus/index.vue b/docs/src/demos/Examples/Focus/index.vue
index 063f9212..033c14da 100644
--- a/docs/src/demos/Examples/Focus/index.vue
+++ b/docs/src/demos/Examples/Focus/index.vue
@@ -1,5 +1,5 @@
 
diff --git a/docs/src/links.yaml b/docs/src/links.yaml
index 94e80146..fb415661 100644
--- a/docs/src/links.yaml
+++ b/docs/src/links.yaml
@@ -56,8 +56,8 @@
         # - title: Placeholder
         #   link: /examples/placeholder
         #   draft: true
-        # - title: Focus
-        #   link: /examples/focus
+        - title: Focus
+          link: /examples/focus
         # - title: Title
         #   link: /examples/title
         #   draft: true
diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts
index 2be9f517..87e50e39 100644
--- a/packages/core/src/Editor.ts
+++ b/packages/core/src/Editor.ts
@@ -122,7 +122,14 @@ export class Editor extends EventEmitter {
     this.registerCommands(coreCommands)
     this.injectCSS()
 
+    // TODO: The autoFocus option has no impact
+    // Doesn’t work
     this.proxy.focus(this.options.autoFocus)
+    // Does work
+    // window.setTimeout(() => {
+    //   console.log(this.options.autoFocus)
+    //   this.proxy.focus(this.options.autoFocus)
+    // }, 100)
   }
 
   /**

From 6baa758ec321098d42b3bda7dffa766458f127a0 Mon Sep 17 00:00:00 2001
From: Hans Pagel 
Date: Fri, 2 Oct 2020 15:49:58 +0200
Subject: [PATCH 5/8] clean up the test

---
 docs/src/demos/Examples/Focus/index.spec.js | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/docs/src/demos/Examples/Focus/index.spec.js b/docs/src/demos/Examples/Focus/index.spec.js
index 1c7271a6..029eb69e 100644
--- a/docs/src/demos/Examples/Focus/index.spec.js
+++ b/docs/src/demos/Examples/Focus/index.spec.js
@@ -4,8 +4,6 @@ context('/examples/focus', () => {
   })
 
   it('should have class', () => {
-    cy.get('.ProseMirror').then(([{ editor }]) => {
-      cy.get('.ProseMirror p:first').should('have.class', 'has-focus')
-    })
+    cy.get('.ProseMirror p:first').should('have.class', 'has-focus')
   })
 })

From b6a06c071fb2057c9767f25574961501c56b0673 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= 
Date: Fri, 2 Oct 2020 21:57:46 +0200
Subject: [PATCH 6/8] refactoring

---
 packages/core/src/Editor.ts | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts
index 87e50e39..f935946e 100644
--- a/packages/core/src/Editor.ts
+++ b/packages/core/src/Editor.ts
@@ -122,14 +122,7 @@ export class Editor extends EventEmitter {
     this.registerCommands(coreCommands)
     this.injectCSS()
 
-    // TODO: The autoFocus option has no impact
-    // Doesn’t work
-    this.proxy.focus(this.options.autoFocus)
-    // Does work
-    // window.setTimeout(() => {
-    //   console.log(this.options.autoFocus)
-    //   this.proxy.focus(this.options.autoFocus)
-    // }, 100)
+    window.setTimeout(() => this.proxy.focus(this.options.autoFocus), 0)
   }
 
   /**

From 6cec81d79142238ed171af6cdcd491e07869a1e6 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 5 Oct 2020 06:20:48 +0000
Subject: [PATCH 7/8] Bump actions/upload-artifact from v2.1.4 to v2.2.0

Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from v2.1.4 to v2.2.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v2.1.4...27bce4eee761b5bc643f46a8dfb41b430c8d05f6)

Signed-off-by: dependabot[bot] 
---
 .github/workflows/main.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index ddf8fb4e..d6e81503 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -87,14 +87,14 @@ jobs:
         browser: chrome
 
     - name: Export screenshots (on failure only)
-      uses: actions/upload-artifact@v2.1.4
+      uses: actions/upload-artifact@v2.2.0
       if: failure()
       with:
         name: cypress-screenshots
         path: tests/cypress/screenshots
 
     - name: Export screen recordings (on failure only)
-      uses: actions/upload-artifact@v2.1.4
+      uses: actions/upload-artifact@v2.2.0
       if: failure()
       with:
         name: cypress-videos

From 4cc47f16d3389f9d3aa8f3bb0bdf33605b8bfaf6 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Mon, 5 Oct 2020 06:20:52 +0000
Subject: [PATCH 8/8] Bump actions/setup-node from v2.1.1 to v2.1.2

Bumps [actions/setup-node](https://github.com/actions/setup-node) from v2.1.1 to v2.1.2.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v2.1.1...c6fd00ceb9747fb23ffdf72987450a2664414867)

Signed-off-by: dependabot[bot] 
---
 .github/workflows/main.yml | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index ddf8fb4e..cbf3a7df 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -27,7 +27,7 @@ jobs:
     - uses: actions/checkout@v2.3.3
 
     - name: Use Node.js ${{ matrix.node-version }}
-      uses: actions/setup-node@v2.1.1
+      uses: actions/setup-node@v2.1.2
       with:
         node-version: ${{ matrix.node-version }}
 
@@ -72,7 +72,7 @@ jobs:
     - uses: actions/checkout@v2.3.3
 
     - name: Use Node.js ${{ matrix.node-version }}
-      uses: actions/setup-node@v2.1.1
+      uses: actions/setup-node@v2.1.2
       with:
         node-version: ${{ matrix.node-version }}
 
@@ -125,7 +125,7 @@ jobs:
     - uses: actions/checkout@v2.3.3
 
     - name: Use Node.js ${{ matrix.node-version }}
-      uses: actions/setup-node@v2.1.1
+      uses: actions/setup-node@v2.1.2
       with:
         node-version: ${{ matrix.node-version }}