diff --git a/CHANGELOG.md b/CHANGELOG.md index 8043746..bc4019d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v3.2.1 +## 05/08/2023 + +1. [](#improved) + * Fixed a "Deprecated: mb_convert_encoding()" error + # v3.2.0 ## 02/23/2022 diff --git a/README.md b/README.md index 0959c6c..bad6ba5 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,22 @@ user/themes/quark/templates/components/page-toc.html.twig NOTE: It's not required to set the TOC plugin `active` if you use the shortcode syntax in your content. That is a good enough indication that you want the plugin to be active. +### Customizing specific anchors + +There are situations where you want to have absolute control over the exact anchor link rather than letting page-toc create one for you. The best way to achieve this is to add your own `id` attribute to the header tag. This can be done either via HTML in your markdown directly: + +```html +

H2 Header

+``` + +Or via using the header shortcodes. This approach is particularly useful if you have markdown inside your header tag: + +```markdown +[h2 id="my-custom-anchor"]H2 _header_[/h2] +``` + +If an `id` is found in one of the header tags that page-toc is configured to use for anchors, then it will use the provided value for the anchor id. + ### Anchor Shortcode Page TOC now includes a `anchor` shortcode that allows you to manually add linkable fragments in your content. diff --git a/blueprints.yaml b/blueprints.yaml index 38ae211..aa1017b 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Page Toc type: plugin slug: page-toc -version: 3.2.0 +version: 3.2.1 description: Generate a table of contents and anchors from a page icon: list author: diff --git a/classes/HtmlHelper.php b/classes/HtmlHelper.php index 14b9b26..5c964bc 100644 --- a/classes/HtmlHelper.php +++ b/classes/HtmlHelper.php @@ -31,7 +31,8 @@ protected function getHTMLParser($markup) { libxml_use_internal_errors(true); $domDocument = new \DOMDocument(); - $domDocument->loadHTML(mb_convert_encoding("$markup", 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); + $html = htmlspecialchars_decode(iconv('UTF-8', 'ISO-8859-1', htmlentities("$markup", ENT_COMPAT, 'UTF-8')), ENT_QUOTES); + $domDocument->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $domDocument->preserveWhiteSpace = true; return $domDocument; }