diff --git a/src/core/view/components/editor/formats/image.js b/src/core/view/components/editor/formats/image.js index e332fe54b496ff88892ae46b59e6ad60d094b666..fde53fc0db58cef8b67b0e47b7162cd7a1eb593a 100644 --- a/src/core/view/components/editor/formats/image.js +++ b/src/core/view/components/editor/formats/image.js @@ -1,3 +1,5 @@ +import getRealPath from 'uni-platform/helpers/get-real-path' + export default function (Quill) { const Image = Quill.import('formats/image') const ATTRIBUTES = [ @@ -8,7 +10,7 @@ export default function (Quill) { 'class', 'data-local' ] - Image.sanitize = url => url + Image.sanitize = url => url ? getRealPath(url) : url Image.formats = function formats (domNode) { return ATTRIBUTES.reduce(function (formats, attribute) { if (domNode.hasAttribute(attribute)) { diff --git a/src/core/view/components/editor/formats/index.js b/src/core/view/components/editor/formats/index.js index f9dcad8c3679280dafd7521b8b3fa1aa6c2b51d9..6a887aece24b8792162d213c6a79b41e07f468d1 100644 --- a/src/core/view/components/editor/formats/index.js +++ b/src/core/view/components/editor/formats/index.js @@ -8,6 +8,7 @@ import box from './box' import font from './font' import text from './text' import image from './image' +import link from './link' export function register (Quill) { const formats = { @@ -20,7 +21,8 @@ export function register (Quill) { box, font, text, - image + image, + link } const options = {} Object.values(formats).forEach(value => Object.assign(options, value(Quill))) diff --git a/src/core/view/components/editor/formats/link.js b/src/core/view/components/editor/formats/link.js new file mode 100644 index 0000000000000000000000000000000000000000..8fd4a44e3e5ff799af8fbdcee39b50a9eb7993e0 --- /dev/null +++ b/src/core/view/components/editor/formats/link.js @@ -0,0 +1,9 @@ +export default function (Quill) { + const Link = Quill.import('formats/link') + Link.sanitize = url => { + const anchor = document.createElement('a') + anchor.href = url + const protocol = anchor.href.slice(0, anchor.href.indexOf(':')) + return Link.PROTOCOL_WHITELIST.concat('file').indexOf(protocol) > -1 ? url : Link.SANITIZED_URL + } +}