chipzoller / hugo-clarity

A theme for Hugo based on VMware Clarity
Other
578 stars 266 forks source link

Search result keyword highlighting errors #328

Closed rootwork closed 2 years ago

rootwork commented 2 years ago

I have checked all the prerequisites below and I'm yet experiencing a problem

Describe the bug

When performing a search and then clicking on a result, on the resulting page the terms you searched for are highlighted with the <mark> element.

Sometimes (but not always) those <mark>s are being inserted inside URLs. Here's an example:

https://neonmirrors.net/post/2022-05/harbor-cosign-and-kyverno/?query=sigstore

If you inspect it, this is what you'll see:

mark element inside a-href

Note the <mark> elements inserted inside the href portion of the link.

Additionally, you can see that even in the regular text, there are <mark>s nested 2 deep. Sometimes they are nested 3 or 4 deep. Here's a good example of that:

https://neonmirrors.net/post/2021-02/kubernetes-policy-comparison-opa-gatekeeper-vs-kyverno/?query=kubernetes

"Kubernetes" in the post title, and in the blockquote, is wrapped in just one <mark>. But in the body of the post, the first instance of "Kubernetes" looks like this when inspected:

multiple marks

This is an issue if you're styling the highlighting, for instance applying a border to <mark> elements means this one will look like it has 4x the width. Using CSS to improve its accessibility for screen readers also gets impacted.

I'm not sure if it's the wrapText function itself or where it shows up in the search script here and here, but I think the <mark> wrapping needs some tweaks.

Also, the function is being worked on already, it might be nice to throw a class on those <mark>s so they can be styled differently, if wanted, than ones used elsewhere (MDN points out it's sometimes used to highlight passages in a blockquote, and I feel like I've seen it used in the same way to highlight lines in code excerpts).

rootwork commented 2 years ago

Added section at the top noting even more significant bug, <mark> wrapping being inserted inside href attributes.

rootwork commented 2 years ago

^ PR #329

onweru commented 2 years ago

@rootwork, I will review your PR asap. Thanks for helping me fix these.