From 5c4dd60f556c03ebde35c0bef653dd092ddbc4a1 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 18 Mar 2021 13:46:11 +0100 Subject: [PATCH 1/2] Updated literal blocks to improve word breaking --- src/Renderers/SpanNodeRenderer.php | 16 +++++++++++++++- .../fixtures/expected/blocks/nodes/literal.html | 10 +++++++++- tests/fixtures/expected/main/datetime.html | 4 ++-- tests/fixtures/source/blocks/nodes/literal.rst | 4 +++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/Renderers/SpanNodeRenderer.php b/src/Renderers/SpanNodeRenderer.php index 2268b6b..308aabf 100644 --- a/src/Renderers/SpanNodeRenderer.php +++ b/src/Renderers/SpanNodeRenderer.php @@ -62,7 +62,21 @@ public function link(?string $url, string $title, array $attributes = []): strin ); } - public function isExternalUrl($url): bool + public function literal(string $text): string + { + // some browsers can't break long properly, so we inject a + // `` (word-break HTML tag) after some characters to help break those + // We only do this for very long (4 or more \\) to not break short + // and common ` such as App\Entity\Something + if (substr_count($text, '\\') >= 4) { + // breaking before the backslask is what Firefox browser does + $text = str_replace('\\', '\\', $text); + } + + return $this->templateRenderer->render('literal.html.twig', ['text' => $text]); + } + + private function isExternalUrl($url): bool { return u($url)->containsAny('://'); } diff --git a/tests/fixtures/expected/blocks/nodes/literal.html b/tests/fixtures/expected/blocks/nodes/literal.html index d85a683..f0eaec8 100644 --- a/tests/fixtures/expected/blocks/nodes/literal.html +++ b/tests/fixtures/expected/blocks/nodes/literal.html @@ -28,5 +28,13 @@ +

+ The CRUD controller of App\Entity\Example must implement +the + EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\CrudControllerInterface + , +but you can also extend from the AbstractCrudController class. +

+ - \ No newline at end of file + diff --git a/tests/fixtures/expected/main/datetime.html b/tests/fixtures/expected/main/datetime.html index d250b1a..41a6b1e 100644 --- a/tests/fixtures/expected/main/datetime.html +++ b/tests/fixtures/expected/main/datetime.html @@ -126,7 +126,7 @@

format

-

type: stringdefault: Symfony\Component\Form\Extension\Core\Type\DateTimeType::HTML5_FORMAT

+

type: stringdefault: Symfony\Component\Form\Extension\Core\Type\DateTimeType::HTML5_FORMAT

If the widget option is set to single_text, this option specifies the format of the input, i.e. how Symfony will interpret the given input as a datetime string. See Date/Time Format Syntax.

@@ -317,4 +317,4 @@

- \ No newline at end of file + diff --git a/tests/fixtures/source/blocks/nodes/literal.rst b/tests/fixtures/source/blocks/nodes/literal.rst index 6521364..43e6570 100644 --- a/tests/fixtures/source/blocks/nodes/literal.rst +++ b/tests/fixtures/source/blocks/nodes/literal.rst @@ -1,4 +1,3 @@ - here is some php code from literal:: // config/routes.php @@ -9,3 +8,6 @@ here is some php code from literal:: ->controller('App\Controller\CompanyController::about'); }; +The CRUD controller of ``App\Entity\Example`` must implement +the ``EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\CrudControllerInterface``, +but you can also extend from the ``AbstractCrudController`` class. From b7b3dedd72ccf46adf84dcc64581a85b37303993 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 18 Mar 2021 13:50:04 +0100 Subject: [PATCH 2/2] - --- src/Renderers/SpanNodeRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Renderers/SpanNodeRenderer.php b/src/Renderers/SpanNodeRenderer.php index 308aabf..0fc9f9c 100644 --- a/src/Renderers/SpanNodeRenderer.php +++ b/src/Renderers/SpanNodeRenderer.php @@ -67,7 +67,7 @@ public function literal(string $text): string // some browsers can't break long properly, so we inject a // `` (word-break HTML tag) after some characters to help break those // We only do this for very long (4 or more \\) to not break short - // and common ` such as App\Entity\Something + // and common `` such as App\Entity\Something if (substr_count($text, '\\') >= 4) { // breaking before the backslask is what Firefox browser does $text = str_replace('\\', '\\', $text);