Browse Source

Fix: Exclude headings inside `.example` from the Table of Contents (#2354)

BG-Software 4 months ago
parent
commit
7773ff22b9
2 changed files with 7 additions and 2 deletions
  1. 5 0
      .changeset/strong-frogs-brush.md
  2. 2 2
      docs/eleventy.config.mjs

+ 5 - 0
.changeset/strong-frogs-brush.md

@@ -0,0 +1,5 @@
+---
+"@tabler/docs": patch
+---
+
+Exclude headings inside `.example` from the Table of Contents

+ 2 - 2
docs/eleventy.config.mjs

@@ -1,4 +1,3 @@
-
 import { appFilters } from "../shared/e11ty/filters.mjs"
 import { appFilters } from "../shared/e11ty/filters.mjs"
 import { appData, getCopyList } from "../shared/e11ty/data.mjs";
 import { appData, getCopyList } from "../shared/e11ty/data.mjs";
 import { readFileSync, existsSync } from 'node:fs';
 import { readFileSync, existsSync } from 'node:fs';
@@ -227,7 +226,8 @@ export default function (eleventyConfig) {
 	eleventyConfig.addFilter("toc", function (name) {
 	eleventyConfig.addFilter("toc", function (name) {
 		const toc = [];
 		const toc = [];
 
 
-		const headings = name.match(/<h([2-3])>([^<]+)<\/h\1>/g);
+		const contentWithoutExamples = name.replace(/<div[^>]*\bclass=["'][^"']*\bexample\b[^"']*".*?>.*?<\/div>/gs, '');
+		const headings = contentWithoutExamples.match(/<h([23])>([^<]+)<\/h\1>/g);
 
 
 		if (headings) {
 		if (headings) {
 			headings.forEach(heading => {
 			headings.forEach(heading => {