diff --git a/src/components/editor/QEditor.vue b/src/components/editor/QEditor.vue index 6b85bb1..b476b89 100644 --- a/src/components/editor/QEditor.vue +++ b/src/components/editor/QEditor.vue @@ -132,14 +132,26 @@ initCheckImageIndex(); } - // 영상 넣기. + // 퍼온 영상 넣기 quillInstance.getModule('toolbar').addHandler('video', () => { - const url = prompt('영상 URL을 입력하세요:'); - if (url) { - // 에디터에 iframe 형태로 영상 삽입 - const index = quillInstance.getSelection().index; // 현재 커서 위치 - quillInstance.insertEmbed(index, 'video', url); - quillInstance.setSelection(index + 1); // 커서를 삽입된 콘텐츠 뒤로 이동 + const url = prompt('iframe 태그가 포함된 주소를 입력해 주세요:'); + if (url && url.indexOf(' + //가라로 추출이라 불안정 할듯 + + // DOMParser를 사용하여 embeded url만 추출 + const parser = new DOMParser(); + const doc = parser.parseFromString(url, 'text/html'); + const iframeEL = doc.querySelector('iframe'); + const src = iframeEL.getAttribute('src'); + const width = iframeEL.getAttribute('width'); + const height = iframeEL.getAttribute('height'); + + // 에디터에 삽입 + const index = quillInstance.getSelection().index; + quillInstance.insertEmbed(index, 'video', src); + quillInstance.setSelection(index + 1); } });