Merge pull request #80 from useplunk/75-pasting-an-link-with-a-template-tag-breaks-the-template
Added proper handling for pasted links in Plunk editor
This commit is contained in:
+2
-4
@@ -1,12 +1,10 @@
|
||||
{
|
||||
"name": "plunk",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.4",
|
||||
"private": true,
|
||||
"license": "agpl-3.0",
|
||||
"workspaces": {
|
||||
"packages": [
|
||||
"packages/*"
|
||||
]
|
||||
"packages": ["packages/*"]
|
||||
},
|
||||
"engines": {
|
||||
"npm": ">=6.14.x",
|
||||
|
||||
@@ -108,6 +108,22 @@ export default function Editor({ value, onChange, mode, modeSwitcher }: Markdown
|
||||
keydown: (_view, event) => {
|
||||
return event.key === "Enter" && !event.shiftKey;
|
||||
},
|
||||
paste: (view, event) => {
|
||||
const text = event.clipboardData?.getData("text");
|
||||
const urlPattern = /^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*({{[\w-]+}})?)*$/;
|
||||
|
||||
if (editor && text && urlPattern.test(text)) {
|
||||
event.preventDefault();
|
||||
editor
|
||||
.chain()
|
||||
.focus()
|
||||
.extendMarkRange("link")
|
||||
.setLink({ href: text.startsWith("http") ? text : `https://${text}`, target: "_blank" })
|
||||
.run();
|
||||
editor.commands.insertContent(text);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
},
|
||||
onUpdate: ({ editor }) => {
|
||||
|
||||
Reference in New Issue
Block a user