本文介绍了如何在 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 预填充链接?
发布评论