Skip to content

Updated literal blocks to improve word breaking #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Renderers/SpanNodeRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code> properly, so we inject a
// `<wbr>` (word-break HTML tag) after some characters to help break those
// We only do this for very long <code> (4 or more \\) to not break short
// and common `<code>` such as App\Entity\Something
if (substr_count($text, '\\') >= 4) {
// breaking before the backslask is what Firefox browser does
$text = str_replace('\\', '<wbr>\\', $text);
}

return $this->templateRenderer->render('literal.html.twig', ['text' => $text]);
}

private function isExternalUrl($url): bool
{
return u($url)->containsAny('://');
}
Expand Down
10 changes: 9 additions & 1 deletion tests/fixtures/expected/blocks/nodes/literal.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,13 @@
</div>
</div>

<p>
The CRUD controller of <code translate="no" class="notranslate">App\Entity\Example</code> must implement
the
<code translate="no" class="notranslate">EasyCorp<wbr>\Bundle<wbr>\EasyAdminBundle<wbr>\Contracts<wbr>\Controller<wbr>\CrudControllerInterface</code>
,
but you can also extend from the <code translate="no" class="notranslate">AbstractCrudController</code> class.
</p>

</body>
</html>
</html>
4 changes: 2 additions & 2 deletions tests/fixtures/expected/main/datetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ <h3 id="placeholder"><a class="headerlink" href="#placeholder" title="Permalink
</div>
<div class="section">
<h3 id="format"><a class="headerlink" href="#format" title="Permalink to this headline">format</a></h3>
<p><strong>type</strong>: <code translate="no" class="notranslate">string</code><strong>default</strong>: <code translate="no" class="notranslate">Symfony\Component\Form\Extension\Core\Type\DateTimeType::HTML5_FORMAT</code></p>
<p><strong>type</strong>: <code translate="no" class="notranslate">string</code><strong>default</strong>: <code translate="no" class="notranslate">Symfony<wbr>\Component<wbr>\Form<wbr>\Extension<wbr>\Core<wbr>\Type<wbr>\DateTimeType::HTML5_FORMAT</code></p>
<p>If the <code translate="no" class="notranslate">widget</code> option is set to <code translate="no" class="notranslate">single_text</code>, this option specifies
the format of the input, i.e. how Symfony will interpret the given input
as a datetime string. See <a href="http://userguide.icu-project.org/formatparse/datetime#TOC-Date-Time-Format-Syntax" class="reference external">Date/Time Format Syntax</a>.</p>
Expand Down Expand Up @@ -317,4 +317,4 @@ <h2 id="url-checker-errors"><a class="headerlink" href="#url-checker-errors" tit
</div>

</body>
</html>
</html>
4 changes: 3 additions & 1 deletion tests/fixtures/source/blocks/nodes/literal.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

here is some php code from literal::

// config/routes.php
Expand All @@ -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.