2017-10-27 16 views
0

reltargetを手動で設定する必要があるカスタムブロットを作成しました。しかし、これらの属性を持つコンテンツを読み込むときには、それらを取り除きます。なぜ私は分からない。カスタムブロットを使用すると、カスタム属性が削除されます

問題を説明するためにcodepenを作成しました。

これは私のカスタムブロットである:

const Inline = Quill.import('blots/inline') 

class CustomLink extends Inline { 
    static create(options) { 
    const node = super.create() 
    node.setAttribute('href', options.url) 

    if (options.target) { node.setAttribute('target', '_blank') } 
    if (options.follow === 'nofollow') { node.setAttribute('rel', 'nofollow') } 

    return node 
    } 

    static formats(node) { 
    return node.getAttribute('href') 
    } 
} 

CustomLink.blotName = 'custom_link' 
CustomLink.tagName = 'A' 
Quill.register({'formats/custom_link': CustomLink}) 

は、私は特定のatttributesを許可するようにクイルを伝える必要がありますか?

答えて

1

既存のHTMLからの初期化時に、クイルはインラインブロットのための葉ブロットのためcreate()value()、そしてformats()間の対称性であることから、データモデルを構築しようとします。 create()が実装されているかを考えると、あなたはこのようなものであることをformats()が必要になります。この変更にフォーク作業

static formats(node) { 
    let ret = { 
     url: node.getAttribute('href'), 
    }; 
    if (node.getAttribute('target') == '_blank') { 
     ret.target = true; 
    } 
    if (node.getAttribute('rel') == 'nofollow') { 
     ret.follow = 'nofollow'; 
    } 
    return ret; 
    } 

https://codepen.io/quill/pen/xPxGgw

は、私はデフォルトのリンクを上書きするだけでなくかかわらず、代わりに別のものを作成することはお勧めします、何らかの理由がある場合を除き、両方のタイプが必要です。

関連する問題