HTML5闭合标签

huangapple go评论62阅读模式
英文:

TYPO3 HTML5 closing tags

问题

我已经在typoscript中设置了以下内容:

config.doctype = html5

然而,我仍然得到以下输出:

<meta http-equiv="x-ua-compatible" content="IE=edge" />
<meta name="generator" content="TYPO3 CMS" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="robots" content="index, follow" />
<meta name="author" content="test" />
<meta name="keywords" content="TYPO3" />
<meta name="description" content="Bootstrap" />
<meta name="twitter:card" content="summary" />

我想要移除末尾的斜杠。我该如何做?

我还在一些内容项上得到了斜杠:

<img class="image-embed-item" title="title" alt="alt" width="50" height="50" loading="lazy" />

这也应该被移除。最佳操作方法是什么?

英文:

I have set the following in the typoscript:

config.doctype = html5

nevertheless I get the following output:

<meta http-equiv="x-ua-compatible" content="IE=edge" />
<meta name="generator" content="TYPO3 CMS" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="robots" content="index, follow" />
<meta name="author" content="test" />
<meta name="keywords" content="TYPO3" />
<meta name="description" content="Bootstrap" />
<meta name="twitter:card" content="summary" />

I want to remove the slashes at the end. How can I do that?

I also get the slash on some content items

<img class="image-embed-item" title="title" alt="alt" width="50" height="50" loading="lazy" />

that should also be removed. What is the best way to proceed?

答案1

得分: 1

以下是您要翻译的内容:

I also think, that this is waste of time. But if you really need to do this you could add the meta-data via TypoScript headerdata:

page.headerData {
10 = TEXT
10.value (
<meta http-equiv="x-ua-compatible" content="IE=edge">
<meta name="generator" content="TYPO3 CMS">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="index, follow">
<meta name="author" content="test">
<meta name="keywords" content="TYPO3">
<meta name="description" content="Bootstrap">
<meta name="twitter:card" content="summary">
)
}

Check in the TypoScript-Object-Browser if 10 is occupied before. In case it is use a free number. (i.e. 20 HTML5闭合标签

To remove the slash in the image tag, i think the only way is to implement your own viewhelper. Maybe you could xclass the tag-based-viewhelper to achive non-closing tags for all tag-based viewhelper.

EDIT:

If all that doesn't fit your requirements, the only way i see is to implement a middleware to remove all the closing tags.

First implement the configuration in your extension.

/Configuration/RequestMiddlewares.php

&lt;?php

return [
    &#39;frontend&#39; =&gt; [
        &#39;remove-closing-tags-middleware&#39; =&gt; [
            &#39;target&#39; =&gt; \VENDOR\ExtName\Middleware\RemoveClosingTagsMiddleware::class,
            &#39;after&#39; =&gt; [
                // Check Configuration for middlewares in Backend and replace last-middleware
                // as described here: https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/RequestHandling/Index.html#debugging
                &#39;last-middleware&#39;,
            ]
        ],
    ]
];

And then implement the middleware in your extension.

/Classes/Middleware/RemoveClosingTagsMiddleware.php

&lt;?php
namespace VENDOR\ExtName\Middleware;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Http\NullResponse;
use TYPO3\CMS\Core\Http\Stream;

class RemoveClosingTagsMiddleware implements MiddlewareInterface
{


    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = $handler-&gt;handle($request);
        if ($response instanceof NullResponse) {
            return $response;
        }
        $body = $response-&gt;getBody();
        $body-&gt;rewind();
        $content = $response-&gt;getBody()-&gt;getContents();
        $content = str_replace(&#39;/&gt;&#39;, &#39;&gt;&#39;, $content);
        $body = new Stream(&#39;php://temp&#39;, &#39;rw&#39;);
        $body-&gt;write($content);
        return $response-&gt;withBody($body);
    }
}

Don't forget to adjust VENDOR and ExtName to your extension.

Further information can be found here:

https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/RequestHandling/Index.html

and here:

https://reelworx.at/blog/detail/correct-manipulation-of-generated-html-in-typo3/

英文:

I also think, that this is waste of time. But if you really need to do this you could add the meta-data via TypoScript headerdata:

page.headerData {
10 = TEXT
10.value (
    &lt;meta http-equiv=&quot;x-ua-compatible&quot; content=&quot;IE=edge&quot;&gt;
    &lt;meta name=&quot;generator&quot; content=&quot;TYPO3 CMS&quot;&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
    &lt;meta name=&quot;robots&quot; content=&quot;index, follow&quot;&gt;
    &lt;meta name=&quot;author&quot; content=&quot;test&quot;&gt;
    &lt;meta name=&quot;keywords&quot; content=&quot;TYPO3&quot;&gt;
    &lt;meta name=&quot;description&quot; content=&quot;Bootstrap&quot;&gt;
    &lt;meta name=&quot;twitter:card&quot; content=&quot;summary&quot;&gt;
)

}

Check in the TypoScript-Object-Browser if 10 is occupied before. In case it is use a free number. (i.e. 20 HTML5闭合标签

To remove the slash in the image tag, i think the only way is to implement your own viewhelper. Maybe you could xclass the tag-based-viewhelper to achive non-closing tags for all tag-based viewhelper.

EDIT:

If all that doesn't fit your requirements, the only way i see is to implement a middleware to remove all the closing tags.

First implement the configuration in your extension.

/Configuration/RequestMiddlewares.php

&lt;?php

return [
    &#39;frontend&#39; =&gt; [
        &#39;remove-closing-tags-middleware&#39; =&gt; [
            &#39;target&#39; =&gt; \VENDOR\ExtName\Middleware\RemoveClosingTagsMiddleware::class,
            &#39;after&#39; =&gt; [
                // Check Configuration for middlewares in Backend and replace last-middleware
                // as described here: https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/RequestHandling/Index.html#debugging
                &#39;last-middleware&#39;,
            ]
        ],
    ]
];

And then implement the middleware in your extension.

/Classes/Middleware/RemoveClosingTagsMiddleware.php

&lt;?php
namespace VENDOR\ExtName\Middleware;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Http\NullResponse;
use TYPO3\CMS\Core\Http\Stream;

class RemoveClosingTagsMiddleware implements MiddlewareInterface
{


    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = $handler-&gt;handle($request);
        if ($response instanceof NullResponse) {
            return $response;
        }
        $body = $response-&gt;getBody();
        $body-&gt;rewind();
        $content = $response-&gt;getBody()-&gt;getContents();
        $content = str_replace(&#39;/&gt;&#39;, &#39;&gt;&#39;, $content);
        $body = new Stream(&#39;php://temp&#39;, &#39;rw&#39;);
        $body-&gt;write($content);
        return $response-&gt;withBody($body);
    }
}

Don't forget to adjust VENDOR and ExtName to your extension.

Further information can be found here:

https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/RequestHandling/Index.html

and here:

https://reelworx.at/blog/detail/correct-manipulation-of-generated-html-in-typo3/

huangapple
  • 本文由 发表于 2023年6月26日 17:57:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76555573.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定