HTML5闭合标签

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

TYPO3 HTML5 closing tags

问题

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

  1. config.doctype = html5

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

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

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

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

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

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

英文:

I have set the following in the typoscript:

  1. config.doctype = html5

nevertheless I get the following output:

  1. <meta http-equiv="x-ua-compatible" content="IE=edge" />
  2. <meta name="generator" content="TYPO3 CMS" />
  3. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  4. <meta name="robots" content="index, follow" />
  5. <meta name="author" content="test" />
  6. <meta name="keywords" content="TYPO3" />
  7. <meta name="description" content="Bootstrap" />
  8. <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

  1. <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

  1. &lt;?php
  2. return [
  3. &#39;frontend&#39; =&gt; [
  4. &#39;remove-closing-tags-middleware&#39; =&gt; [
  5. &#39;target&#39; =&gt; \VENDOR\ExtName\Middleware\RemoveClosingTagsMiddleware::class,
  6. &#39;after&#39; =&gt; [
  7. // Check Configuration for middlewares in Backend and replace last-middleware
  8. // as described here: https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/RequestHandling/Index.html#debugging
  9. &#39;last-middleware&#39;,
  10. ]
  11. ],
  12. ]
  13. ];

And then implement the middleware in your extension.

/Classes/Middleware/RemoveClosingTagsMiddleware.php

  1. &lt;?php
  2. namespace VENDOR\ExtName\Middleware;
  3. use Psr\Http\Message\ResponseInterface;
  4. use Psr\Http\Message\ServerRequestInterface;
  5. use Psr\Http\Server\MiddlewareInterface;
  6. use Psr\Http\Server\RequestHandlerInterface;
  7. use TYPO3\CMS\Core\Http\NullResponse;
  8. use TYPO3\CMS\Core\Http\Stream;
  9. class RemoveClosingTagsMiddleware implements MiddlewareInterface
  10. {
  11. public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
  12. {
  13. $response = $handler-&gt;handle($request);
  14. if ($response instanceof NullResponse) {
  15. return $response;
  16. }
  17. $body = $response-&gt;getBody();
  18. $body-&gt;rewind();
  19. $content = $response-&gt;getBody()-&gt;getContents();
  20. $content = str_replace(&#39;/&gt;&#39;, &#39;&gt;&#39;, $content);
  21. $body = new Stream(&#39;php://temp&#39;, &#39;rw&#39;);
  22. $body-&gt;write($content);
  23. return $response-&gt;withBody($body);
  24. }
  25. }

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:

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

}

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

  1. &lt;?php
  2. return [
  3. &#39;frontend&#39; =&gt; [
  4. &#39;remove-closing-tags-middleware&#39; =&gt; [
  5. &#39;target&#39; =&gt; \VENDOR\ExtName\Middleware\RemoveClosingTagsMiddleware::class,
  6. &#39;after&#39; =&gt; [
  7. // Check Configuration for middlewares in Backend and replace last-middleware
  8. // as described here: https://docs.typo3.org/m/typo3/reference-coreapi/10.4/en-us/ApiOverview/RequestHandling/Index.html#debugging
  9. &#39;last-middleware&#39;,
  10. ]
  11. ],
  12. ]
  13. ];

And then implement the middleware in your extension.

/Classes/Middleware/RemoveClosingTagsMiddleware.php

  1. &lt;?php
  2. namespace VENDOR\ExtName\Middleware;
  3. use Psr\Http\Message\ResponseInterface;
  4. use Psr\Http\Message\ServerRequestInterface;
  5. use Psr\Http\Server\MiddlewareInterface;
  6. use Psr\Http\Server\RequestHandlerInterface;
  7. use TYPO3\CMS\Core\Http\NullResponse;
  8. use TYPO3\CMS\Core\Http\Stream;
  9. class RemoveClosingTagsMiddleware implements MiddlewareInterface
  10. {
  11. public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
  12. {
  13. $response = $handler-&gt;handle($request);
  14. if ($response instanceof NullResponse) {
  15. return $response;
  16. }
  17. $body = $response-&gt;getBody();
  18. $body-&gt;rewind();
  19. $content = $response-&gt;getBody()-&gt;getContents();
  20. $content = str_replace(&#39;/&gt;&#39;, &#39;&gt;&#39;, $content);
  21. $body = new Stream(&#39;php://temp&#39;, &#39;rw&#39;);
  22. $body-&gt;write($content);
  23. return $response-&gt;withBody($body);
  24. }
  25. }

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:

确定