如何在 Quill 编辑器中使用 http 预填充链接?

编程入门 行业动态 更新时间:2024-10-09 22:19:08
本文介绍了如何在 Quill 编辑器中使用 http 预填充链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用 Quill 编辑器添加链接时,我必须包含协议,否则链接将被视为相对链接.

When adding links with the Quill editor I must include the protocol or the link is treated as a relative link.

当有人点击添加链接时,我希望用 预填充该字段,这样当用户输入 google 时,它会创建一个链接到 google 而不是 myapp/something/google.

When someone clicks to add a link I would like to have the field prepopulate with so when a user types google it will create a link to google instead of myapp/something/google.

堆栈溢出这样做...

推荐答案

当您尝试保存现有链接时,上述解决方案将不起作用.它还忽略其他协议,例如 (mailto, tel, https)

The above solution wont work when you try to save an existing link. Also it ignores other protocols such as ( mailto, tel, https )

这是一个更好的解决方案:

Here is a better solution:

let Link = window.Quill.import('formats/link'); class CustomLink extends Link { static sanitize(url) { let value = super.sanitize(url); if(value) { for(let i=0;i<CustomLink.PROTOCOL_WHITELIST.length;i++) if(value.startsWith(CustomLink.PROTOCOL_WHITELIST[i])) return value; return `${value}` } return value; } } Quill.register(CustomLink);

更多推荐

如何在 Quill 编辑器中使用 http 预填充链接?

本文发布于:2023-05-31 14:01:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/393041.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:器中   编辑   链接   如何在   Quill

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!