我對在 ckeditor5 中向鏈接添加類有一些特定要求 - 我已經閱讀了文檔并嘗試了多種方法,但我仍然在努力實現我想要的。我的要求是:添加的所有鏈接(無論是使用鏈接 UI 還是通過粘貼)都必須分配一個類。defaultClass如果未分配類或分配的類不在有效類列表中,則應將該類設置為鏈接類必須在有效鏈接類列表中我建立了一個包含有效類列表的下拉列表并將其添加到鏈接界面這是我到目前為止的代碼: const { editor } = this const linkClasses = editor.config.get('link.options.classes') const defaultLinkClass = editor.config.get('link.options.defaultClass') editor.model.schema.extend('$text', { allowAttributes: 'linkClass' }) editor.conversion.for('downcast').attributeToElement({ model: 'linkClass', view: (attributeValue, writer) => writer.createAttributeElement('a', { class: attributeValue }, { priority: 5 }), converterPriority: 'low' }) editor.conversion.for('upcast').attributeToAttribute({ view: { name: 'a', key: 'class' }, model: 'linkClass', converterPriority: 'low' })
向 CKeditor 中的鏈接添加類
Helenr
2021-10-14 14:05:45