@shelf/table-of-contents 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  const parser = new DOMParser();
2
2
  const hasAnchorTagsInHeader = (data) => {
3
- const doc = parser.parseFromString(data.header, 'text/xml');
3
+ const doc = parser.parseFromString(data.all, 'text/html');
4
4
  // Extract any existing anchor tags from the header variable
5
5
  const anchorElement = doc.querySelector('a');
6
6
  return anchorElement?.outerHTML;
@@ -12,10 +12,17 @@ export const getDataWithoutNestedAnchors = (data, headerTemplate) => {
12
12
  }
13
13
  const doc = parser.parseFromString(results, 'text/xml');
14
14
  // get Toc pointer anchor node
15
- const firstAnchorElement = doc.querySelector(`a[href="#${data.anchor}"]:not(:empty)`);
15
+ const firstAnchorElement = doc.querySelector(`a[href="#${data.anchor}"]`);
16
+ const parentNode = firstAnchorElement?.parentElement;
17
+ // EDGECASE - other anchors in this header
18
+ const otherAnchorElements = doc?.querySelectorAll(`a:not([href="#${data.anchor}"]):empty`);
19
+ if (otherAnchorElements && otherAnchorElements?.length > 0) {
20
+ otherAnchorElements.forEach(node => {
21
+ node.remove();
22
+ });
23
+ }
16
24
  // get all content nodes from Toc pointer anchor node
17
25
  const contentArray = Array.from(firstAnchorElement?.childNodes ?? []);
18
- const parentNode = firstAnchorElement?.parentElement;
19
26
  // remove all content nodes from Toc pointer anchor node
20
27
  contentArray.forEach(node => {
21
28
  firstAnchorElement?.removeChild(node);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shelf/table-of-contents",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Fork of node-toc to reduce bundle size & rewritten in TypeScript",
5
5
  "license": "MIT",
6
6
  "author": {