<ins> /*--------------------------------------------------------------------------------------------- *  Copyright (c) Microsoft Corporation. All rights reserved. *  Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as marked from '../../../../base/common/marked/marked.js'; // Copied from https://github.com/Flet/github-slugger since we can't use esm yet. // eslint-disable-next-line no-control-regex, no-misleading-character-class const githubSlugReplaceRegex = /[0-x1F!-,./:-@[-^`{-xA9xAB-xB4xB6-xB9xBB-xBFxD7xF7u02C2-u02C5u02D2-u02DFu02E5-u02EBu02EDu02EF-u02FFu0375u0378u0379u037Eu0380-u0385u0387u038Bu038Du03A2u03F6u0482u0530u0557u0558u055A-u055Fu0589-u0590u05BEu05C0u05C3u05C6u05C8-u05CFu05EB-u05EEu05F3-u060Fu061B-u061Fu066A-u066Du06D4u06DDu06DEu06E9u06FDu06FEu0700-u070Fu074Bu074Cu07B2-u07BFu07F6-u07F9u07FBu07FCu07FEu07FFu082E-u083Fu085C-u085Fu086B-u089Fu08B5u08C8-u08D2u08E2u0964u0965u0970u0984u098Du098Eu0991u0992u09A9u09B1u09B3-u09B5u09BAu09BBu09C5u09C6u09C9u09CAu09CF-u09D6u09D8-u09DBu09DEu09E4u09E5u09F2-u09FBu09FDu09FFu0A00u0A04u0A0B-u0A0Eu0A11u0A12u0A29u0A31u0A34u0A37u0A3Au0A3Bu0A3Du0A43-u0A46u0A49u0A4Au0A4E-u0A50u0A52-u0A58u0A5Du0A5F-u0A65u0A76-u0A80u0A84u0A8Eu0A92u0AA9u0AB1u0AB4u0ABAu0ABBu0AC6u0ACAu0ACEu0ACFu0AD1-u0ADFu0AE4u0AE5u0AF0-u0AF8u0B00u0B04u0B0Du0B0Eu0B11u0B12u0B29u0B31u0B34u0B3Au0B3Bu0B45u0B46u0B49u0B4Au0B4E-u0B54u0B58-u0B5Bu0B5Eu0B64u0B65u0B70u0B72-u0B81u0B84u0B8B-u0B8Du0B91u0B96-u0B98u0B9Bu0B9Du0BA0-u0BA2u0BA5-u0BA7u0BAB-u0BADu0BBA-u0BBDu0BC3-u0BC5u0BC9u0BCEu0BCFu0BD1-u0BD6u0BD8-u0BE5u0BF0-u0BFFu0C0Du0C11u0C29u0C3A-u0C3Cu0C45u0C49u0C4E-u0C54u0C57u0C5B-u0C5Fu0C64u0C65u0C70-u0C7Fu0C84u0C8Du0C91u0CA9u0CB4u0CBAu0CBBu0CC5u0CC9u0CCE-u0CD4u0CD7-u0CDDu0CDFu0CE4u0CE5u0CF0u0CF3-u0CFFu0D0Du0D11u0D45u0D49u0D4F-u0D53u0D58-u0D5Eu0D64u0D65u0D70-u0D79u0D80u0D84u0D97-u0D99u0DB2u0DBCu0DBEu0DBFu0DC7-u0DC9u0DCB-u0DCEu0DD5u0DD7u0DE0-u0DE5u0DF0u0DF1u0DF4-u0E00u0E3B-u0E3Fu0E4Fu0E5A-u0E80u0E83u0E85u0E8Bu0EA4u0EA6u0EBEu0EBFu0EC5u0EC7u0ECEu0ECFu0EDAu0EDBu0EE0-u0EFFu0F01-u0F17u0F1A-u0F1Fu0F2A-u0F34u0F36u0F38u0F3A-u0F3Du0F48u0F6D-u0F70u0F85u0F98u0FBD-u0FC5u0FC7-u0FFFu104A-u104Fu109Eu109Fu10C6u10C8-u10CCu10CEu10CFu10FBu1249u124Eu124Fu1257u1259u125Eu125Fu1289u128Eu128Fu12B1u12B6u12B7u12BFu12C1u12C6u12C7u12D7u1311u1316u1317u135Bu135Cu1360-u137Fu1390-u139Fu13F6u13F7u13FE-u1400u166Du166Eu1680u169B-u169Fu16EB-u16EDu16F9-u16FFu170Du1715-u171Fu1735-u173Fu1754-u175Fu176Du1771u1774-u177Fu17D4-u17D6u17D8-u17DBu17DEu17DFu17EA-u180Au180Eu180Fu181A-u181Fu1879-u187Fu18AB-u18AFu18F6-u18FFu191Fu192C-u192Fu193C-u1945u196Eu196Fu1975-u197Fu19AC-u19AFu19CA-u19CFu19DA-u19FFu1A1C-u1A1Fu1A5Fu1A7Du1A7Eu1A8A-u1A8Fu1A9A-u1AA6u1AA8-u1AAFu1AC1-u1AFFu1B4C-u1B4Fu1B5A-u1B6Au1B74-u1B7Fu1BF4-u1BFFu1C38-u1C3Fu1C4A-u1C4Cu1C7Eu1C7Fu1C89-u1C8Fu1CBBu1CBCu1CC0-u1CCFu1CD3u1CFB-u1CFFu1DFAu1F16u1F17u1F1Eu1F1Fu1F46u1F47u1F4Eu1F4Fu1F58u1F5Au1F5Cu1F5Eu1F7Eu1F7Fu1FB5u1FBDu1FBF-u1FC1u1FC5u1FCD-u1FCFu1FD4u1FD5u1FDC-u1FDFu1FED-u1FF1u1FF5u1FFD-u203Eu2041-u2053u2055-u2070u2072-u207Eu2080-u208Fu209D-u20CFu20F1-u2101u2103-u2106u2108u2109u2114u2116-u2118u211E-u2123u2125u2127u2129u212Eu213Au213Bu2140-u2144u214A-u214Du214F-u215Fu2189-u24B5u24EA-u2BFFu2C2Fu2C5Fu2CE5-u2CEAu2CF4-u2CFFu2D26u2D28-u2D2Cu2D2Eu2D2Fu2D68-u2D6Eu2D70-u2D7Eu2D97-u2D9Fu2DA7u2DAFu2DB7u2DBFu2DC7u2DCFu2DD7u2DDFu2E00-u2E2Eu2E30-u3004u3008-u3020u3030u3036u3037u303D-u3040u3097u3098u309Bu309Cu30A0u30FBu3100-u3104u3130u318F-u319Fu31C0-u31EFu3200-u33FFu4DC0-u4DFFu9FFD-u9FFFuA48D-uA4CFuA4FEuA4FFuA60D-uA60FuA62C-uA63FuA673uA67EuA6F2-uA716uA720uA721uA789uA78AuA7C0uA7C1uA7CB-uA7F4uA828-uA82BuA82D-uA83FuA874-uA87FuA8C6-uA8CFuA8DA-uA8DFuA8F8-uA8FAuA8FCuA92EuA92FuA954-uA95FuA97D-uA97FuA9C1-uA9CEuA9DA-uA9DFuA9FFuAA37-uAA3FuAA4EuAA4FuAA5A-uAA5FuAA77-uAA79uAAC3-uAADAuAADEuAADFuAAF0uAAF1uAAF7-uAB00uAB07uAB08uAB0FuAB10uAB17-uAB1FuAB27uAB2FuAB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C65uDC70-uDC7EuDCBB-uDCCFuDCE9-uDCEFuDCFA-uDCFFuDD35uDD40-uDD43uDD48-uDD4FuDD74uDD75uDD77-uDD7FuDDC5-uDDC8uDDCDuDDDBuDDDD-uDDFFuDE12uDE38-uDE3DuDE3F-uDE7FuDE87uDE89uDE8EuDE9EuDEA9-uDEAFuDEEB-uDEEFuDEFA-uDEFFuDF04uDF0DuDF0EuDF11uDF12uDF29uDF31uDF34uDF3AuDF45uDF46uDF49uDF4AuDF4EuDF4FuDF51-uDF56uDF58-uDF5CuDF64uDF65uDF6D-uDF6FuDF75-uDFFF]|uD805[uDC4B-uDC4FuDC5A-uDC5DuDC62-uDC7FuDCC6uDCC8-uDCCFuDCDA-uDD7FuDDB6uDDB7uDDC1-uDDD7uDDDE-uDDFFuDE41-uDE43uDE45-uDE4FuDE5A-uDE7FuDEB9-uDEBFuDECA-uDEFFuDF1BuDF1CuDF2C-uDF2FuDF3A-uDFFF]|uD806[uDC3B-uDC9FuDCEA-uDCFEuDD07uDD08uDD0AuDD0BuDD14uDD17uDD36uDD39uDD3AuDD44-uDD4FuDD5A-uDD9FuDDA8uDDA9uDDD8uDDD9uDDE2uDDE5-uDDFFuDE3F-uDE46uDE48-uDE4FuDE9A-uDE9CuDE9E-uDEBFuDEF9-uDFFF]|uD807[uDC09uDC37uDC41-uDC4FuDC5A-uDC71uDC90uDC91uDCA8uDCB7-uDCFFuDD07uDD0AuDD37-uDD39uDD3BuDD3EuDD48-uDD4FuDD5A-uDD5FuDD66uDD69uDD8FuDD92uDD99-uDD9FuDDAA-uDEDFuDEF7-uDFAFuDFB1-uDFFF]|uD808[uDF9A-uDFFF]|uD809[uDC6F-uDC7FuDD44-uDFFF]|[uD80AuD80BuD80E-uD810uD812-uD819uD824-uD82BuD82DuD82EuD830-uD833uD837uD839uD83DuD83FuD87B-uD87DuD87FuD885-uDB3FuDB41-uDBFF][uDC00-uDFFF]|uD80D[uDC2F-uDFFF]|uD811[uDE47-uDFFF]|uD81A[u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-uDD4FuDD6A-uDD6FuDD8A-uDFFF]|uD83E[uDC00-uDFEFuDFFA-uDFFF]|uD869[uDEDE-uDEFF]|uD86D[uDF35-uDF3F]|uD86E[uDC1EuDC1F]|uD873[uDEA2-uDEAF]|uD87A[uDFE1-uDFFF]|uD87E[uDE1E-uDFFF]|uD884[uDF4B-uDFFF]|uDB40[uDC00-uDCFFuDDF0-uDFFF]/g; function slugify(heading: string): string { const slugifiedHeading = heading.trim() .toLowerCase() .replace(githubSlugReplaceRegex, '') .replace(/s/g, '-'); // Replace whitespace with - return slugifiedHeading; } // Copied from https://github.com/markedjs/marked-gfm-heading-id/blob/main/src/index.js // Removed logic for handling duplicate header ids for now // unescape from marked helpers const unescapeTest = /&(#(?:d+)|(?:#x[0-9A-Fa-f]+)|(?:w+));?/ig; function unescape(html: string) { // explicitly match decimal, hex, and named HTML entities return html.replace(unescapeTest, (_, n) => { n = n.toLowerCase(); if (n === 'colon') { return ':'; } if (n.charAt(0) === '#') { return n.charAt(1) === 'x' ? String.fromCharCode(parseInt(n.substring(2), 16)) : String.fromCharCode(+n.substring(1)); } return ''; }); } export function markedGfmHeadingIdPlugin({ prefix = '', globalSlugs = false } = {}): marked.MarkedExtension { return { // hooks: { // 	preprocess(src: string) { // 		if (!globalSlugs) { // 			resetHeadings(); // 		} // 		return src; // 	}, // }, renderer: { heading({ tokens, depth }) { const text = this.parser.parseInline(tokens); const raw = unescape(this.parser.parseInline(tokens, this.parser.textRenderer)) .trim() .replace(/<[!/a-z].*?>/gi, ''); const level = depth; const id = `${prefix}${slugify(raw)}`; // const heading = { level, text, id, raw }; // headings.push(heading); return `<h${level} id="${id}">${text}</h${level}>n`; }, }, }; } </ins>