最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Quill.js 不斷從錨標(biāo)記中剝離類(lèi)

Quill.js 不斷從錨標(biāo)記中剝離類(lèi)

慕萊塢森 2023-06-29 22:41:33
我編寫(xiě)了一個(gè)自定義鏈接模塊來(lái)處理內(nèi)部鏈接等。該模塊還向 A 標(biāo)記添加了一些類(lèi),以便它們可以以不同的方式顯示。但一旦再次實(shí)例化,Quill 就會(huì)刪除這些類(lèi)。我已經(jīng)發(fā)現(xiàn)您需要一個(gè)自定義歸因者。但我無(wú)法讓它工作。為了保持簡(jiǎn)單,我創(chuàng)建了一個(gè)沙箱(沒(méi)有我的模塊)。這是代碼:<!-- ... --><div id="editor">? <a href="/test" class="btn">Foo</a></div><!-- ... -->import Quill from "quill";import "quill-paste-smart";import "quill/dist/quill.snow.css";const Parchment = Quill.import("parchment");let LinkClass = new Parchment.Attributor.Class("link", "ql-link", {? scope: Parchment.Scope.INLINE,? whitelist: ["btn"]});Quill.register({ "attributors/class/link": LinkClass }, true);new Quill("#editor", {? theme: "snow",? modules: {? ? toolbar: ["bold", "italic", "underline", "link", "clean"]? }});
查看完整描述

3 回答

?
紫衣仙女

TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊

不幸的是,接受的答案并沒(méi)有完全解決我的問(wèn)題。

我正在尋找一種添加/保留多個(gè)類(lèi)的可能方法。


這是最終的解決方案:


const Inline = Quill.import("blots/inline");


const ATTRIBUTES = ["href", "rel", "target", "class"];

class InternalLink extends Inline {

  static create(value) {

    let node = super.create(value);

    node.setAttribute("href", value.href);

    if (value.rel) node.setAttribute("rel", value.rel);

    if (value.target) node.setAttribute("target", value.target);

    if (value.class) node.setAttribute("class", value.class);

    return node;

  }


  static formats(domNode) {

    return ATTRIBUTES.reduce((formats, attribute) => {

      if (domNode.hasAttribute(attribute)) {

        formats[attribute] = domNode.getAttribute(attribute);

      }

      return formats;

    }, {});

  }

}


InternalLink.blotName = "internal_link";

InternalLink.tagName = "A";


Quill.register({

  "formats/link": InternalLink

});


查看完整回答
反對(duì) 回復(fù) 2023-06-29
?
Helenr

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超4個(gè)贊

您還需要使用該類(lèi)將該元素添加到 Quill 實(shí)例的一側(cè)Inline。


這是一個(gè)例子:


const Inline = Quill.import("blots/inline");



InternalLink.blotName = "internal_link";

InternalLink.className = "btn";

InternalLink.tagName = "A";


Quill.register({

  "attributors/class/link": LinkClass,

  "formats/internal_link": InternalLink

});


查看完整回答
反對(duì) 回復(fù) 2023-06-29
?
胡說(shuō)叔叔

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊

此版本將保留所有屬性(在我的初步測(cè)試中)并且不需要將它們顯式定義為印跡。


const Inline = Quill.import("blots/inline");


class FixedLink extends Inline {

? ? static create(value) {

? ? ? ? let node = super.create(value);

? ? ? ? for (const key in value){

? ? ? ? ? ? node.setAttribute(key, value[key]);

? ? ? ? }

? ? ? ? return node;

? ? }


? ? static formats(domNode) {

? ? ? ? const attributes = {};

? ? ? ? for (const attr of domNode.attributes){

? ? ? ? ? ? attributes[attr.name] = attr.value;

? ? ? ? }

? ? ? ? return attributes;

? ? }

}


FixedLink.blotName = "fixed_link";

FixedLink.tagName = "A";


查看完整回答
反對(duì) 回復(fù) 2023-06-29
  • 3 回答
  • 0 關(guān)注
  • 275 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)