Strip tags of ToC item's aria label

Some plugins/extensions might use the data-toc-label attribute
of headings to set a particular string for the ToC item title.

While not explicitly documented as possible or allowed,
they might set some HTML code instead of text.
In this case, the aria label of Toc nav elements break the HTML
as they will contain unescaped double quotes.

To fix this, we use the `striptags` filter
to remove any tags from the aria label, keeping text only.
This commit is contained in:
Timothée Mazzucotelli 2023-05-22 18:27:28 +02:00
parent 2cff287097
commit 3f978d86f6
2 changed files with 2 additions and 2 deletions

View File

@ -6,7 +6,7 @@
{{ toc_item.title }}
</a>
{% if toc_item.children %}
<nav class="md-nav" aria-label="{{ toc_item.title }}">
<nav class="md-nav" aria-label="{{ toc_item.title | striptags }}">
<ul class="md-nav__list">
{% for toc_item in toc_item.children %}
{% include "partials/toc-item.html" %}

View File

@ -28,7 +28,7 @@
<!-- Table of contents list -->
{% if toc_item.children %}
<nav class="md-nav" aria-label="{{ toc_item.title }}">
<nav class="md-nav" aria-label="{{ toc_item.title | striptags }}">
<ul class="md-nav__list">
{% for toc_item in toc_item.children %}
{% include "partials/toc-item.html" %}