✘✘✘ Javascript/Quill
[Quill] link에 https protocol Sanitization (http/https 붙이기)
PrettyLog
2023. 4. 5. 17:07
Search:: quill editor I try to edit embed link, but edit button does not work
Modify Link.sanitize
const Link = Quill.import('formats/link');
const originalSanitize = Link.sanitize;
Link.sanitize = function customSanitizeLinkInput(linkValueInput: any) {
let val = linkValueInput;
if (!/^(https|http?:\/\/)/.test(val)) val = `https://${val}`;
return originalSanitize.call(this, val); // retain the built-in logic
};
Quill link handler not working
Create module to customize sanitization
import Quill from "quill";
const Link = Quill.import('formats/link');
class CustomLink extends Link {
static sanitize(url: string): string {
const protocolPattern = /^(https?:\/\/)/;
if (!protocolPattern.test(url)) {
return 'http://' + url;
}
return super.sanitize(url);
}
}
CustomLink.blotName = 'link';
CustomLink.tagName = 'A';
Quill.register(CustomLink);