V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
weiqipeng
V2EX  ›  程序员

前端 各位佬 CKEditor5 在 vue3 vite 环境下的源码自定义构建模式 添加了 htmlSupport 这个配置 好像不起作用 有遇到同样问题的佬吗

  •  
  •   weiqipeng · 20 天前 · 504 次点击

    官方文档: [https://ckeditor.com/docs/ckeditor5/latest/installation/advanced/alternative-setups/integrating-from-source-vite.html#running-the-editor-method-1]

    不使用 htmlSupport 这个配置 在源代码编辑模式会自动把 css 的内联 style 自动过滤 预防漏洞攻击 需求就是 关闭这个自动过滤 但是发现在自定义构建模式下不起作用

    直接使用在线选好功能打包之后再引入是没有问题的 但后续更新麻烦 所以想直接使用源码构建方式

    版本: 41.4.1

    我的代码:

    editor.js

    
    
    import { ClassicEditor } from '@ckeditor/ckeditor5-editor-classic'
    import { Autoformat } from '@ckeditor/ckeditor5-autoformat'
    import { GeneralHtmlSupport, HtmlComment } from '@ckeditor/ckeditor5-html-support'
    import { Undo } from '@ckeditor/ckeditor5-undo'
    import { SourceEditing } from '@ckeditor/ckeditor5-source-editing'
    
    import '@ckeditor/ckeditor5-build-classic/build/translations/zh-cn'
    
    class Editor extends ClassicEditor {
    	static builtinPlugins = [
    		GeneralHtmlSupport,
    		HtmlComment,
    		Undo,
            SourceEditing,
            Autoformat
    	]
    
    	static defaultConfig = {
    		htmlSupport: {
                allow: [{
                    name: /.*/,
                    attributes: true,
                    classes: true,
                    styles: true
                }],
                disallow: [ /* HTML features to disallow */]
            },
    		toolbar: {
    			items: [
    				'sourceEditing',
    				'undo',
    				'redo'
    			]
    		},
    		language: 'zh-cn'
    	}
    }
    
    export default Editor;
    
    

    xxx.vue

    import ClassicEditor from 'xxx/editor.js'
    
    <Ckeditor v-model="code" :editor="ClassicEditor" />
    
    3 条回复    2024-05-31 02:21:24 +08:00
    webbillion
        2
    webbillion  
       20 天前   ❤️ 1
    @webbillion #1 看错了,你有个 defaultConfig ,不过也可以试试创建的时候再添加配置呢
    weiqipeng
        3
    weiqipeng  
    OP
       18 天前 via iPhone
    @webbillion 这个方式我也尝试过 创建的时候添加配置和这个 js 文件做的事情是等价的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3109 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:20 · PVG 19:20 · LAX 04:20 · JFK 07:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.