TYPO3 ckeditor: allow img tag without enabling image plugin

霸气de小男生 提交于 2019-12-24 13:32:33

问题


On a plain TYPO3 8 installation, I want ckeditor to allow the img tag in the source, without enabling the image plugin. The default configuration of ckeditor in TYPO3 removes the image plugin, which causes img tags to be removed as well.

According to the ckeditor documentation, this can be achieved with the property

config.extraAllowedContent = 'img'

but it does not work in my custom yaml configuration. img tags are always striped when I switch from source to wysiwyg mode.

If I enable the image plugin, img tags are kept. But I do not want to give to the editors this button as an option.

What am I doing wrong?

Here is my test yaml configuration. At the bottom is the extraAllowedContent option

imports:
    - { resource: "EXT:rte_ckeditor/Configuration/RTE/Processing.yaml" }
    - { resource: "EXT:rte_ckeditor/Configuration/RTE/Editor/Base.yaml" }
    - { resource: "EXT:rte_ckeditor/Configuration/RTE/Editor/Plugins.yaml" }
editor:
  config:
    contentsCss: ["EXT:rte_ckeditor/Resources/Public/Css/contents.css", "EXT:tucmmforumhook/Resources/Public/Styles/Tucmain.css"]
    stylesSet:
      - { name: "XYZ Text", element: "span", attributes: { class: "highlighted red"} }
      - { name: "Button", element: "a", attributes: { class: "button"} }
      - { name: "Checklist", element: "ul", attributes: { class: "check-list"} }
    format_tags: "p;h2;h3;h4;h5"
    toolbarGroups:
      - { name: styles, groups: [ styles, format ] }
      - { name: basicstyles, groups: [ basicstyles ] }
      - { name: paragraph, groups: [ list, indent, blocks, align ] }
      - { name: links, groups: [ links ] }
      - { name: clipboard, groups: [ clipboard, cleanup, undo ] }
      - { name: editing, groups: [ spellchecker ] }
      - { name: insert, groups: [ insert ] }
      - { name: tools, groups: [ table, specialchar ] }
      - { name: document, groups: [ mode ] }
    justifyClasses:
      - text-left
      - text-center
      - text-right
      - text-justify
    extraPlugins:
      - justify
    removePlugins:
      - image
    removeButtons:
      - Strike
      - Anchor
      - Outdent
      - Indent
      - Blockquote
      - JustifyBlock

    extraAllowedContent:
      - img

回答1:


Based on @ikon answer, I managed to make the extraAllowedContent to work. Instead of

extraAllowedContent:
  - img

it was enough to use

extraAllowedContent:
  - img[!src,alt,width,height]

This keeps the img tags intact, without needing the image plugin




回答2:


In order to achieve this you need to switch to the custom mode of AFC: https://sdk.ckeditor.com/samples/acfcustom.html .

Use:

allowedContent: 
- img[!src,alt,width,height]

to allow images. It might be tricky than to make configuration/filtering fitting to your presets: you have to add other allowed tags to allowedContentlist as well, otherwise the buttons for tables, list etc would not be rendered.

Avoid using

allowedContent: true
because it would allow everything!

来源:https://stackoverflow.com/questions/49422412/typo3-ckeditor-allow-img-tag-without-enabling-image-plugin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!