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有帮助,但是否有更好的东西允许<style>在纯HTML内容元素?
编辑:查看DB条目,html标记没有编码,所以没有"<“或">",而不是"<”和">“,所以这不是RTE的问题。
发布于 2021-12-29 18:48:42
经过更多的研究(再投资几个小时),我得出的结论是,唯一的方法是扩展HTMLSanitizer。
该解决方案使用了以下来源:
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_theme)中实现,并使用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/gpcf_theme/Composer.json:
{
"name": "oheil/gpcf_theme",
...
"autoload": {
"psr-4": {
"Oheil\\GpcfTheme\\": "Classes/"
}
},
...
}local_packages/gpcf_theme/ext_localcon.php:
<?php
defined('TYPO3_MODE') || die();
...
$GLOBALS['TYPO3_CONF_VARS']['SYS']['htmlSanitizer']['default'] = \Oheil\GpcfTheme\MyDefaultBuilder::class;
...local_packages/gpcf_theme/Classes/MyDefaultBuilder.php
<?php
namespace Oheil\GpcfTheme;
use TYPO3\CMS\Core\Html\DefaultSanitizerBuilder;
use TYPO3\HtmlSanitizer\Behavior;
use TYPO3\HtmlSanitizer\Behavior\Attr;
use TYPO3\HtmlSanitizer\Behavior\Tag;
class MyDefaultBuilder extends \TYPO3\CMS\Core\Html\DefaultSanitizerBuilder
{
protected function createBehavior(): \TYPO3\HtmlSanitizer\Behavior
{
// 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>https://stackoverflow.com/questions/70498334
复制相似问题