TYPO3 11内容元素纯HTML,<;Style>; [英] TYPO3 11 content element Plain HTML with <style>
问题描述
TYPO3 11.5.4
我要向页面添加纯HTML内容元素,例如:
<style type="text/css">
h1#testheader { font-weight: bold; }
</style>
<h1 id="testheader">
Header
</h1>
(仅作为简化示例)
但呈现的输出为:
<style type="text/css"> h1#testheader { font-weight: bold; } </style>
Header
我认为该样式是允许的,因为我设置了:
lib.parseFunc.allowTags = ...,style,...
lib.parseFunc_RTE.allowTags = ...,style,...
但是它不起作用。 设置
lib.parseFunc.htmlSanitize = 0
有帮助,但是否可以在纯HTML内容元素中允许<style>
更好的内容?
编辑: 查看数据库条目时,html标记未编码,因此不是";<;";或";>;";而不是";<;";和";>;";,因此这不是RTE的问题。
推荐答案
经过进一步研究(再次投入小时数),我得出结论,唯一的办法就是扩展HTMLSaniizer。
此解决方案使用了以下来源:
https://punkt.de/de/blog/2021/htmlsanitizer-in-typo3.html https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/9.5.x/Important-94484-IntroduceHTMLSanitizer.html https://gist.github.com/ohader/2239dab247e18d23e677fd1b816f4fd5
允许<style>
、<script>
和<iframe>
的完整解决方案如下所示。
我仍然不能允许<font>
使用此方法!
它在本地站点包(Gpcf_Heme)中实现,并使用Composer。
将<style>
、<script>
和<iframe>
添加到
lib.parseFunc.allowTags = ... style, ..., iframe, script, ...
在网站包的TypoScript部分。
style
似乎是标准的,并且已经是此列表的一部分。
本地站点包路径为:
local_packages/gpcf_theme
其符号链接来自:
public/typo3conf/ext/gpcf_theme -> ../../../local_packages/gpcf_theme
以下是重要的文件更改:
local_packages/gpcf_theme/composer.json:
{
"name": "oheil/gpcf_theme",
...
"autoload": {
"psr-4": {
"Oheil\GpcfTheme\": "Classes/"
}
},
...
}
local_packages/gpcf_theme/ext_localconf.php:
<?php
defined('TYPO3_MODE') || die();
...
$GLOBALS['TYPO3_CONF_VARS']['SYS']['htmlSanitizer']['default'] = OheilGpcfThemeMyDefaultBuilder::class;
...
local_packages/gpcf_theme/Classes/MyDefaultBuilder.php
<?php
namespace OheilGpcfTheme;
use TYPO3CMSCoreHtmlDefaultSanitizerBuilder;
use TYPO3HtmlSanitizerBehavior;
use TYPO3HtmlSanitizerBehaviorAttr;
use TYPO3HtmlSanitizerBehaviorTag;
class MyDefaultBuilder extends TYPO3CMSCoreHtmlDefaultSanitizerBuilder
{
protected function createBehavior(): TYPO3HtmlSanitizerBehavior
{
// https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/9.5.x/Important-94484-IntroduceHTMLSanitizer.html
return parent::createBehavior()
->withName('common')
->withTags(
(new Tag(
'style',
Tag::ALLOW_CHILDREN + Behavior::ENCODE_INVALID_TAG
))->addAttrs(
(new Attr('type')),
...$this->globalAttrs
),
(new Tag(
'iframe',
Tag::ALLOW_CHILDREN
))->addAttrs(
...array_merge(
$this->globalAttrs,
[$this->srcAttr],
$this->createAttrs('scrolling', 'marginwidth', 'marginheight', 'frameborder', 'vspace', 'hspace', 'height', 'width')
)
),
(new Tag(
'script',
Tag::ALLOW_CHILDREN
))->addAttrs(
...array_merge(
$this->globalAttrs,
[$this->srcAttr]
)
),
// more tags...
);
}
}
完成这些更改后,您当然需要清除TYPO3缓存,并且(此处不确定)您需要执行以下操作:
composer remove "oheil/gpcf_theme"
composer require "oheil/gpcf_theme"
上述方法现在正在发挥作用,但我仍然很高兴任何专家能就哪些地方出错或可以做得更好(也许更容易)提供更多的见解?
为什么这不适用于<font>
?
示例:
<font class="font713099">Some Text</font>
这篇关于TYPO3 11内容元素纯HTML,<;Style>;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!