From 0e9930f90f253f8667d1436dcf6c93279fda9aed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20K=C3=BChn?= Date: Wed, 5 Jan 2022 10:27:23 +0100 Subject: [PATCH] fix: prevent named capturing groups, fix #2128 --- packages/extension-code-block/src/code-block.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/extension-code-block/src/code-block.ts b/packages/extension-code-block/src/code-block.ts index 14fab268..69bdc34d 100644 --- a/packages/extension-code-block/src/code-block.ts +++ b/packages/extension-code-block/src/code-block.ts @@ -38,8 +38,8 @@ declare module '@tiptap/core' { } } -export const backtickInputRegex = /^```(?[a-z]*)?[\s\n]$/ -export const tildeInputRegex = /^~~~(?[a-z]*)?[\s\n]$/ +export const backtickInputRegex = /^```([a-z]+)?[\s\n]$/ +export const tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/ export const CodeBlock = Node.create({ name: 'codeBlock', @@ -212,12 +212,16 @@ export const CodeBlock = Node.create({ textblockTypeInputRule({ find: backtickInputRegex, type: this.type, - getAttributes: ({ groups }) => groups, + getAttributes: match => ({ + language: match[1], + }), }), textblockTypeInputRule({ find: tildeInputRegex, type: this.type, - getAttributes: ({ groups }) => groups, + getAttributes: match => ({ + language: match[1], + }), }), ] },