Fixed anchor tracking not working for anchors in tables

This commit is contained in:
squidfunk 2023-01-08 11:53:59 +01:00
parent 8a812aed83
commit 318903db58
4 changed files with 11 additions and 6 deletions

View File

@ -240,7 +240,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.56861ea1.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.2a903f2a.min.js' | url }}"></script>
{% for path in config.extra_javascript %}
<script src="{{ path | url }}"></script>
{% endfor %}

View File

@ -176,6 +176,11 @@ export function watchTableOfContents(
offset = target.offsetTop
}
/* Fix anchor offsets in tables - see https://bit.ly/3CUFOcn */
let parent = target.offsetParent as HTMLElement
for (; parent; parent = parent.offsetParent as HTMLElement)
offset += parent.offsetTop
/* Map reversed anchor path to vertical offset */
return index.set(
[...path = [...path, anchor]].reverse(),