微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在CKEditor5中对齐图像标题<figcaption>?

如何解决如何在CKEditor5中对齐图像标题<figcaption>?

我有一个自定义插件来插入图像,并且在插入图像时,我试图使标题认为左对齐。 此外,当我在CKEditor中编辑标题时,工具栏中的Alignment插件被禁用。

我的插件

class Insertimage extends Plugin {
    init() {
        const { editor } = this;

        editor.ui.componentFactory.add('insertimage',(locale) => {
            const view = new ButtonView(locale);

            view.set({
                label: 'Insert image',icon: imageIcon,tooltip: true,});

            // Callback executed once the image icon is clicked.
            view.on('execute',() => {
                // 1. open image list modal
                const openImagesDialogEvent = new Event('open-image-list');
                document.body.dispatchEvent(openImagesDialogEvent);

                // 2. wait for url and description from modal
                document.body.addEventListener(
                    'add-image-to-textfield',function addImagetoTextfield(event) {
                        if (event.detail.imageUrl) {
                            editor.model.change((writer) => {
                                const image = writer.createElement('image',{
                                    src: event.detail.imageUrl,});

                                if (event.detail.imageCaption) {
                                    const caption = writer.createElement('caption');

                                    writer.appendText(event.detail.imageCaption,caption);
                                    writer.setAttribute('alignment','left',caption);
                                    writer.append(caption,image);
                                }

                                editor.model.insertContent(image);
                                editor.execute('bold');
                            });
                        }

                        document.body.removeEventListener(
                            'add-image-to-textfield',addImagetoTextfield
                        );
                    }
                );
            });

            return view;
        });
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。