Skip to content

Commit 781d189

Browse files
committed
Configure preview renderer via page TSconfig
1 parent 51d2096 commit 781d189

5 files changed

Lines changed: 76 additions & 99 deletions

File tree

Classes/Preview/ContentPreviewRenderer.php

Lines changed: 0 additions & 97 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the "codehighlight" extension for TYPO3 CMS.
7+
*
8+
* For the full copyright and license information, please read the
9+
* LICENSE.txt file that was distributed with this source code.
10+
*/
11+
12+
namespace Brotkrueml\CodeHighlight\ViewHelpers\Format;
13+
14+
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
15+
16+
/**
17+
* @internal
18+
*/
19+
final class CropLinesViewHelper extends AbstractViewHelper
20+
{
21+
private const MAX_LINES = 20;
22+
23+
public function render(): string
24+
{
25+
$stringToTruncate = (string) $this->renderChildren();
26+
27+
$lines = \preg_split('/\R/', $stringToTruncate);
28+
if ($lines === false) {
29+
return $stringToTruncate;
30+
}
31+
32+
$slicedLines = \array_slice($lines, 0, self::MAX_LINES);
33+
$output = \implode("\r\n", $slicedLines);
34+
if (\count($lines) !== \count($slicedLines)) {
35+
$output .= "\r\n\r\n...";
36+
}
37+
38+
return $output;
39+
}
40+
}

Configuration/TCA/Overrides/tt_content.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
use Brotkrueml\CodeHighlight\Extension;
11-
use Brotkrueml\CodeHighlight\Preview\ContentPreviewRenderer;
1211
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
1312

1413
defined('TYPO3') || die();
@@ -35,7 +34,6 @@
3534
);
3635

3736
$GLOBALS['TCA']['tt_content']['types'][$contentType] = [
38-
'previewRenderer' => ContentPreviewRenderer::class,
3937
'columnsOverrides' => [
4038
'bodytext' => [
4139
'label' => Extension::LANGUAGE_PATH_CONTENT_ELEMENT . ':codeSnippet',

Configuration/page.tsconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
@import "EXT:codehighlight/Configuration/TsConfig/Page/*.tsconfig"
2+
3+
mod.web_layout.tt_content.preview {
4+
tx_codehighlight_codesnippet = EXT:codehighlight/Resources/Private/Templates/Preview/CodeSnippetPreview.html
5+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<html
2+
data-namespace-typo3-fluid="true"
3+
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
4+
lang="en"
5+
>
6+
7+
<f:if condition="{record.bodytext}">
8+
<f:then>
9+
<pre><code>{record.bodytext -> codeHighlight:format.cropLines()}</code></pre>
10+
</f:then>
11+
<f:else>
12+
<br>
13+
<div class="alert alert-warning">
14+
<f:translate key="LLL:EXT:codehighlight/Resources/Private/Language/ContentElement.xlf:codeSnippet.notDefined"/>
15+
</div>
16+
</f:else>
17+
</f:if>
18+
19+
<f:if condition="{record.pi_flexform.programmingLanguage} || {record.pi_flexform.filename}">
20+
<div class="t3-page-ce-footer" style="margin-inline:-20px;margin-block-end:-20px;">
21+
<div class="t3-page-ce-info">
22+
<f:if condition="{record.pi_flexform.programmingLanguage}">
23+
<strong>{record.pi_flexform.programmingLanguage.0 -> f:format.case()}</strong>
24+
</f:if>
25+
<f:if condition="{record.pi_flexform.filename}">
26+
{record.pi_flexform.filename}
27+
</f:if>
28+
</div>
29+
</div>
30+
</f:if>
31+
32+
</html>

0 commit comments

Comments
 (0)