(function (Drupal, CKEditor5) { const pluginNamespace = 'blockquoteAttribution'; const toolbarItem = 'blockquote_attribution'; const icon = ''; function escapeHtml(value) { return String(value || '') .replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); } function getSelectedHtml(editor) { const selection = editor.model.document.selection; if (selection.isCollapsed) { return '
' + Drupal.t('Quote text') + '
'; } try { const selectedContent = editor.model.getSelectedContent(selection); const html = editor.data.stringify(selectedContent); return html && html.trim() ? html : '' + Drupal.t('Quote text') + '
'; } catch (e) { return '' + Drupal.t('Quote text') + '
'; } } function insertHtml(editor, html) { const viewFragment = editor.data.processor.toView(html); const modelFragment = editor.data.toModel(viewFragment); editor.model.change(() => { editor.model.insertContent(modelFragment); }); editor.editing.view.focus(); } class BlockquoteAttribution extends CKEditor5.core.Plugin { static get pluginName() { return 'BlockquoteAttribution'; } init() { const editor = this.editor; editor.ui.componentFactory.add(toolbarItem, (locale) => { const button = new CKEditor5.ui.ButtonView(locale); button.set({ label: Drupal.t('Blockquote with Attribution'), icon, tooltip: true, }); button.on('execute', () => { const source = window.prompt(Drupal.t('Source attribution:'), ''); if (source === null) { return; } const selectedHtml = getSelectedHtml(editor); const attribution = escapeHtml(source.trim()); const figcaption = attribution ? '' + selectedHtml + '' + figcaption + '