spec-up-t 1.3.0 → 1.4.0

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.
Files changed (150) hide show
  1. package/.github/copilot-instructions.md +13 -0
  2. package/assets/compiled/body.js +18 -12
  3. package/assets/compiled/head.css +8 -6
  4. package/assets/css/collapse-definitions.css +0 -1
  5. package/assets/css/counter.css +10 -22
  6. package/assets/css/create-pdf.css +4 -2
  7. package/assets/css/create-term-filter.css +4 -4
  8. package/assets/css/definition-buttons-container.css +60 -0
  9. package/assets/css/{pdf-download.css → download-pdf-docx.css} +9 -5
  10. package/assets/css/insert-trefs.css +7 -0
  11. package/assets/css/sidebar-toc.css +2 -1
  12. package/assets/css/terms-and-definitions.css +73 -22
  13. package/assets/js/add-href-to-snapshot-link.js +16 -9
  14. package/assets/js/addAnchorsToTerms.js +2 -2
  15. package/assets/js/charts.js +10 -0
  16. package/assets/js/collapse-definitions.js +13 -2
  17. package/assets/js/collapse-meta-info.js +11 -9
  18. package/assets/js/definition-button-container-utils.js +82 -0
  19. package/assets/js/download-pdf-docx.js +68 -0
  20. package/assets/js/edit-term-buttons.js +77 -20
  21. package/assets/js/github-issues.js +35 -0
  22. package/assets/js/github-repo-info.js +144 -0
  23. package/assets/js/highlight-heading-plus-sibling-nodes.test.js +18 -0
  24. package/assets/js/insert-trefs.js +62 -13
  25. package/assets/js/mermaid-diagrams.js +11 -0
  26. package/assets/js/terminology-section-utility-container/README.md +107 -0
  27. package/assets/js/terminology-section-utility-container/create-alphabet-index.js +17 -0
  28. package/assets/js/{create-term-filter.js → terminology-section-utility-container/create-term-filter.js} +11 -44
  29. package/assets/js/terminology-section-utility-container/hide-show-utility-container.js +21 -0
  30. package/assets/js/terminology-section-utility-container/search.js +203 -0
  31. package/assets/js/terminology-section-utility-container.js +203 -0
  32. package/assets/js/tooltips.js +283 -0
  33. package/config/asset-map.json +26 -18
  34. package/index.js +57 -390
  35. package/package.json +5 -2
  36. package/src/add-remove-xref-source.js +20 -21
  37. package/src/collect-external-references.js +8 -337
  38. package/src/collect-external-references.test.js +440 -33
  39. package/src/configure.js +8 -109
  40. package/src/create-docx.js +7 -6
  41. package/src/create-pdf.js +15 -14
  42. package/src/freeze-spec-data.js +46 -0
  43. package/src/git-info.test.js +76 -0
  44. package/src/health-check/destination-gitignore-checker.js +5 -3
  45. package/src/health-check/external-specs-checker.js +5 -4
  46. package/src/health-check/specs-configuration-checker.js +2 -1
  47. package/src/health-check/term-references-checker.js +5 -3
  48. package/src/health-check/terms-intro-checker.js +2 -1
  49. package/src/health-check/tref-term-checker.js +8 -7
  50. package/src/health-check.js +8 -7
  51. package/src/init.js +3 -2
  52. package/src/install-from-boilerplate/add-gitignore-entries.js +3 -2
  53. package/src/install-from-boilerplate/add-scripts-keys.js +5 -4
  54. package/src/install-from-boilerplate/boilerplate/.github/workflows/menu.yml +74 -97
  55. package/src/install-from-boilerplate/boilerplate/README.md +1 -1
  56. package/src/install-from-boilerplate/boilerplate/spec/example-markup-in-markdown.md +1 -1
  57. package/src/install-from-boilerplate/boilerplate/spec/spec-head.md +2 -2
  58. package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/composability.md +3 -0
  59. package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/compost.md +3 -0
  60. package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/fertilizer.md +3 -0
  61. package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/mulch.md +3 -0
  62. package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/pruning.md +3 -0
  63. package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/seedling.md +3 -0
  64. package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/soil.md +11 -0
  65. package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/watering.md +3 -0
  66. package/src/install-from-boilerplate/boilerplate/specs.json +24 -10
  67. package/src/install-from-boilerplate/config-scripts-keys.js +3 -3
  68. package/src/install-from-boilerplate/config-system-files.js +0 -1
  69. package/src/install-from-boilerplate/copy-boilerplate.js +2 -1
  70. package/src/install-from-boilerplate/copy-system-files.js +4 -3
  71. package/src/install-from-boilerplate/custom-update.js +12 -1
  72. package/src/install-from-boilerplate/help.txt +1 -1
  73. package/src/install-from-boilerplate/menu.sh +6 -6
  74. package/src/json-key-validator.js +17 -11
  75. package/src/markdown-it/README.md +207 -0
  76. package/src/markdown-it/definition-lists.js +397 -0
  77. package/src/markdown-it/index.js +83 -0
  78. package/src/markdown-it/link-enhancement.js +98 -0
  79. package/src/markdown-it/plugins.js +118 -0
  80. package/src/markdown-it/table-enhancement.js +97 -0
  81. package/src/markdown-it/template-tag-syntax.js +152 -0
  82. package/src/parsers/index.js +16 -0
  83. package/src/parsers/spec-parser.js +152 -0
  84. package/src/parsers/spec-parser.test.js +109 -0
  85. package/src/parsers/template-tag-parser.js +277 -0
  86. package/src/parsers/template-tag-parser.test.js +107 -0
  87. package/src/pipeline/configuration/configure-starterpack.js +200 -0
  88. package/src/{create-external-specs-list.js → pipeline/configuration/create-external-specs-list.js} +13 -12
  89. package/src/{create-term-index.js → pipeline/configuration/create-term-index.js} +19 -18
  90. package/src/{create-versions-index.js → pipeline/configuration/create-versions-index.js} +4 -3
  91. package/src/{insert-term-index.js → pipeline/configuration/insert-term-index.js} +2 -2
  92. package/src/pipeline/configuration/prepare-spec-configuration.js +70 -0
  93. package/src/pipeline/parsing/apply-markdown-it-extensions.js +35 -0
  94. package/src/pipeline/parsing/create-markdown-parser.js +94 -0
  95. package/src/pipeline/parsing/create-markdown-parser.test.js +49 -0
  96. package/src/{html-dom-processor.js → pipeline/postprocessing/definition-list-postprocessor.js} +69 -10
  97. package/src/{escape-handler.js → pipeline/preprocessing/escape-processor.js} +3 -1
  98. package/src/{fix-markdown-files.js → pipeline/preprocessing/normalize-terminology-markdown.js} +41 -31
  99. package/src/pipeline/references/collect-external-references.js +307 -0
  100. package/src/pipeline/references/external-references-service.js +231 -0
  101. package/src/pipeline/references/fetch-terms-from-index.js +198 -0
  102. package/src/pipeline/references/match-term.js +34 -0
  103. package/src/{collectExternalReferences/matchTerm.test.js → pipeline/references/match-term.test.js} +8 -2
  104. package/src/pipeline/references/process-xtrefs-data.js +94 -0
  105. package/src/pipeline/references/xtref-utils.js +166 -0
  106. package/src/pipeline/rendering/render-spec-document.js +146 -0
  107. package/src/pipeline/rendering/render-utils.js +154 -0
  108. package/src/utils/LOGGER.md +81 -0
  109. package/src/utils/{doesUrlExist.js → does-url-exist.js} +4 -3
  110. package/src/utils/fetch.js +5 -4
  111. package/src/utils/file-opener.js +3 -2
  112. package/src/utils/git-info.js +77 -0
  113. package/src/utils/logger.js +74 -0
  114. package/src/utils/regex-patterns.js +471 -0
  115. package/src/utils/regex-patterns.test.js +281 -0
  116. package/templates/template.html +56 -21
  117. package/assets/js/create-alphabet-index.js +0 -60
  118. package/assets/js/hide-show-utility-container.js +0 -16
  119. package/assets/js/index.js +0 -87
  120. package/assets/js/pdf-download.js +0 -46
  121. package/assets/js/search.js +0 -365
  122. package/src/collectExternalReferences/fetchTermsFromIndex.js +0 -284
  123. package/src/collectExternalReferences/matchTerm.js +0 -32
  124. package/src/collectExternalReferences/processXTrefsData.js +0 -108
  125. package/src/freeze.js +0 -90
  126. package/src/install-from-boilerplate/boilerplate/.github/workflows/fetch-and-push-xrefs.yml.old +0 -42
  127. package/src/install-from-boilerplate/boilerplate/.github/workflows/render-specs.yml +0 -47
  128. package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/term-1.md +0 -13
  129. package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/term-2.md +0 -3
  130. package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/term-3.md +0 -3
  131. package/src/install-from-boilerplate/boilerplate/spec/terms-definitions/term-4.md +0 -3
  132. package/src/markdown-it-extensions.js +0 -395
  133. package/src/references.js +0 -114
  134. /package/assets/css/{bootstrap.min.css → embedded-libraries/bootstrap.min.css} +0 -0
  135. /package/assets/css/{prism.css → embedded-libraries/prism.css} +0 -0
  136. /package/assets/css/{prism.dark.css → embedded-libraries/prism.dark.css} +0 -0
  137. /package/assets/css/{prism.default.css → embedded-libraries/prism.default.css} +0 -0
  138. /package/assets/js/{bootstrap.bundle.min.js → embedded-libraries/bootstrap.bundle.min.js} +0 -0
  139. /package/assets/js/{chart.js → embedded-libraries/chart.js} +0 -0
  140. /package/assets/js/{diff.min.js → embedded-libraries/diff.min.js} +0 -0
  141. /package/assets/js/{font-awesome.js → embedded-libraries/font-awesome.js} +0 -0
  142. /package/assets/js/{mermaid.js → embedded-libraries/mermaid.js} +0 -0
  143. /package/assets/js/{notyf.js → embedded-libraries/notyf.js} +0 -0
  144. /package/assets/js/{popper.js → embedded-libraries/popper.js} +0 -0
  145. /package/assets/js/{prism.dark.js → embedded-libraries/prism.dark.js} +0 -0
  146. /package/assets/js/{prism.default.js → embedded-libraries/prism.default.js} +0 -0
  147. /package/assets/js/{prism.js → embedded-libraries/prism.js} +0 -0
  148. /package/assets/js/{tippy.js → embedded-libraries/tippy.js} +0 -0
  149. /package/src/{escape-mechanism.js → pipeline/preprocessing/escape-placeholder-utils.js} +0 -0
  150. /package/src/utils/{isLineWithDefinition.js → is-line-with-definition.js} +0 -0
@@ -0,0 +1,471 @@
1
+ /**
2
+ * @fileoverview Centralized regular expressions for the spec-up-t project
3
+ *
4
+ * This module contains all regular expressions used throughout the spec-up-t codebase,
5
+ * organized by functional category. Centralizing regexes improves maintainability,
6
+ * ensures consistency, and reduces duplication.
7
+ *
8
+ * Each regex is documented with:
9
+ * - Purpose and usage context
10
+ * - Example matches
11
+ * - Flags used and their meaning
12
+ * - Related regexes in the same category
13
+ *
14
+ * @author spec-up-t contributors
15
+ * @since 1.3.2
16
+ */
17
+
18
+ /**
19
+ * Regular expressions for parsing template tag syntax like [[type:args]]
20
+ * Used primarily in markdown-it plugins and content processing
21
+ */
22
+ const templateTags = {
23
+ /**
24
+ * Matches template tag syntax [[type:args]] with optional arguments
25
+ *
26
+ * Groups:
27
+ * - Group 1: tag type (e.g., 'ref', 'tref', 'def', 'insert')
28
+ * - Group 2: arguments (everything after colon, comma-separated)
29
+ *
30
+ * Examples:
31
+ * - [[def:term1,term2]] → type: 'def', args: 'term1,term2'
32
+ * - [[tref:spec,term]] → type: 'tref', args: 'spec,term'
33
+ * - [[insert:path/file]] → type: 'insert', args: 'path/file'
34
+ *
35
+ * Flags:
36
+ * - i: case-insensitive matching
37
+ * - m: multiline mode (^ and $ match line boundaries)
38
+ * - g: global matching (find all occurrences)
39
+ */
40
+ replacer: /\[\[\s*([^\s[\]:]+):?\s*([^\]\n]+)?\]\]/img,
41
+
42
+ /**
43
+ * Splits arguments within template tags by commas and optional whitespace
44
+ *
45
+ * Used to parse comma-separated arguments in template tags
46
+ *
47
+ * Examples:
48
+ * - "arg1, arg2, arg3" → ['arg1', 'arg2', 'arg3']
49
+ * - "spec,term,alias" → ['spec', 'term', 'alias']
50
+ */
51
+ argsSeparator: /\s*,+\s*/,
52
+
53
+ /**
54
+ * Template tag content pattern for parsing the inner content of spec-up tags
55
+ * Used in markdown-it template-tag-syntax plugin
56
+ *
57
+ * Examples:
58
+ * - "def:term1,term2" → type: 'def', args: 'term1,term2'
59
+ * - "tref: spec, term" → type: 'tref', args: ' spec, term'
60
+ *
61
+ * Flags:
62
+ * - i: case-insensitive matching
63
+ */
64
+ content: /\s*([^\s\[\]:]+):?\s*([^\]\n]+)?/i,
65
+
66
+ /**
67
+ * Template variable interpolation pattern for processing ${variable} syntax
68
+ * Used in render-spec-document.js for injecting dynamic values into templates
69
+ *
70
+ * Pattern breakdown:
71
+ * - \${ → Literal ${
72
+ * - (.*?) → Capture group 1: variable name (non-greedy)
73
+ * - } → Literal }
74
+ *
75
+ * Examples:
76
+ * - "${title}" → variable: 'title'
77
+ * - "${currentDate}" → variable: 'currentDate'
78
+ * - "${spec.version}" → variable: 'spec.version'
79
+ *
80
+ * Flags:
81
+ * - g: global to replace all variables in template
82
+ */
83
+ variableInterpolation: /\${(.*?)}/g,
84
+
85
+ /**
86
+ * Matches specification name patterns for markdown-it extension filtering
87
+ * Used to determine which markdown-it extension should handle spec references
88
+ *
89
+ * Pattern breakdown:
90
+ * - ^spec$ → Exact match for "spec"
91
+ * - | → OR operator
92
+ * - ^spec-*\w+$ → "spec" followed by optional dashes and word characters
93
+ *
94
+ * Examples:
95
+ * - "spec" → matches
96
+ * - "spec-name" → matches
97
+ * - "spec-test-123" → matches
98
+ * - "myspec" → doesn't match (must start with "spec")
99
+ *
100
+ * Flags:
101
+ * - i: case-insensitive matching
102
+ */
103
+ specName: /^spec$|^spec-*\w+$/i,
104
+
105
+ /**
106
+ * Matches terminology reference patterns for markdown-it extension filtering
107
+ * Used to determine which markdown-it extension should handle term references
108
+ *
109
+ * Pattern breakdown:
110
+ * - ^def$ → Exact match for "def" (definition)
111
+ * - ^ref$ → Exact match for "ref" (reference)
112
+ * - ^xref → Starts with "xref" (external reference)
113
+ * - ^tref → Starts with "tref" (typed reference)
114
+ *
115
+ * Examples:
116
+ * - "def" → matches
117
+ * - "ref" → matches
118
+ * - "xref" → matches
119
+ * - "tref" → matches
120
+ * - "xref:spec,term" → matches (starts with xref)
121
+ *
122
+ * Flags:
123
+ * - i: case-insensitive matching
124
+ */
125
+ terminology: /^def$|^ref$|^xref|^tref$/i
126
+ };
127
+
128
+ /**
129
+ * Regular expressions for external references (xref/tref patterns)
130
+ * Used for cross-referencing terms between specifications
131
+ */
132
+ const externalReferences = {
133
+ /**
134
+ * Matches all external reference patterns: [[xref:...]] or [[tref:...]]
135
+ *
136
+ * Used to find and extract external references from markdown content
137
+ *
138
+ * Examples:
139
+ * - [[xref:spec1,term1]]
140
+ * - [[tref:spec2,term2,alias2]]
141
+ * - [[xref: spec3, term3 ]]
142
+ *
143
+ * Flags:
144
+ * - g: global matching to find all occurrences
145
+ */
146
+ allXTrefs: /\[\[(?:xref|tref):.*?\]\]/g,
147
+
148
+ /**
149
+ * Captures the reference type (xref or tref) from external reference syntax
150
+ *
151
+ * Groups:
152
+ * - Group 1: reference type ('xref' or 'tref')
153
+ *
154
+ * Examples:
155
+ * - [[xref:spec,term]] → 'xref'
156
+ * - [[tref:spec,term,alias]] → 'tref'
157
+ */
158
+ referenceType: /\[\[(xref|tref):/,
159
+
160
+ /**
161
+ * Pattern for removing opening [[xref: or [[tref: from external references
162
+ * Used in preprocessing external reference strings
163
+ *
164
+ * Examples:
165
+ * - "[[xref:spec,term]]" → "spec,term]]" (after removal)
166
+ * - "[[tref:spec,term,alias]]" → "spec,term,alias]]" (after removal)
167
+ */
168
+ openingTag: /\[\[(?:xref|tref):/,
169
+
170
+ /**
171
+ * Pattern for removing closing ]] from external references
172
+ * Used in preprocessing external reference strings
173
+ *
174
+ * Examples:
175
+ * - "spec,term]]" → "spec,term" (after removal)
176
+ * - "spec,term,alias]]" → "spec,term,alias" (after removal)
177
+ */
178
+ closingTag: /\]\]/,
179
+
180
+ /**
181
+ * Splits external reference arguments by comma
182
+ * Used to separate spec, term, and optional alias
183
+ *
184
+ * Examples:
185
+ * - "spec,term,alias" → ['spec', 'term', 'alias']
186
+ * - "spec1,term-with-dashes" → ['spec1', 'term-with-dashes']
187
+ */
188
+ argsSeparator: /,/,
189
+
190
+ /**
191
+ * Tref specification name extractor pattern
192
+ * Extracts the spec name from a tref tag (first argument before comma)
193
+ *
194
+ * Pattern breakdown:
195
+ * - \[\[tref: → Literal [[tref:
196
+ * - ([^,]+) → Capture group 1: spec name (anything except comma)
197
+ *
198
+ * Examples:
199
+ * - "[[tref:spec1,term]]" → captures "spec1"
200
+ * - "[[tref: myspec , myterm]]" → captures " myspec "
201
+ *
202
+ * Used in health-check/term-references-checker.js
203
+ */
204
+ trefSpecExtractor: /\[\[tref:([^,]+)/
205
+ };
206
+
207
+ /**
208
+ * Regular expressions for escaping special regex characters
209
+ * Used to prevent regex injection and ensure literal character matching
210
+ */
211
+ const escaping = {
212
+ /**
213
+ * Matches special regex characters that need escaping
214
+ *
215
+ * Characters matched: . * + ? ^ $ { } ( ) | [ ] \ -
216
+ * These are escaped with backslashes to treat them as literal characters
217
+ *
218
+ * Used in functions that build dynamic regex patterns from user input
219
+ *
220
+ * Examples:
221
+ * - "test.term" → "test\\.term"
222
+ * - "term-with-dashes" → "term\\-with\\-dashes"
223
+ * - "spec(v1)" → "spec\\(v1\\)"
224
+ *
225
+ * Flags:
226
+ * - g: global to escape all occurrences
227
+ */
228
+ specialChars: /[.*+?^${}()|[\]\\-]/g,
229
+
230
+ /**
231
+ * Placeholder pattern for escaped template tags
232
+ * Used in escape-processor.js to replace escaped placeholders with literal [[
233
+ *
234
+ * Flags:
235
+ * - g: global to replace all placeholders
236
+ */
237
+ placeholderRegex: /__SPEC_UP_ESCAPED_TAG__/g
238
+ };
239
+
240
+ /**
241
+ * Regular expressions for path normalization and manipulation
242
+ * Used in file system operations and URL handling
243
+ */
244
+ const paths = {
245
+ /**
246
+ * Matches trailing forward slashes at the end of paths
247
+ * Used to normalize paths by removing trailing slashes before adding them back
248
+ *
249
+ * Examples:
250
+ * - "path/to/dir/" → "path/to/dir" (after removal)
251
+ * - "path/to/dir///" → "path/to/dir" (after removal)
252
+ *
253
+ * Flags:
254
+ * - g: global to remove all trailing slashes
255
+ */
256
+ trailingSlash: /\/$/g
257
+ };
258
+
259
+ /**
260
+ * Regular expressions for version pattern matching
261
+ * Used in freeze functionality and version management
262
+ */
263
+ const versions = {
264
+ /**
265
+ * Matches version directory patterns like "v1", "v2", "v123"
266
+ *
267
+ * Groups:
268
+ * - Group 1: version number (digits only)
269
+ *
270
+ * Used to identify and parse version directories in freeze functionality
271
+ *
272
+ * Examples:
273
+ * - "v1" → version: '1'
274
+ * - "v42" → version: '42'
275
+ * - "v999" → version: '999'
276
+ *
277
+ * Non-matches:
278
+ * - "version1" (doesn't start with 'v')
279
+ * - "v1.2" (contains non-digit characters)
280
+ * - "V1" (uppercase V)
281
+ */
282
+ pattern: /^v(\d+)$/
283
+ };
284
+
285
+
286
+
287
+ /**
288
+ * Regular expressions for gitignore pattern matching
289
+ * Used in health check functionality for validating gitignore patterns
290
+ */
291
+ const gitignore = {
292
+ /**
293
+ * Template for converting gitignore glob patterns to regex
294
+ *
295
+ * Used to check if file paths match gitignore patterns with wildcards
296
+ *
297
+ * Construction:
298
+ * - Replace asterisk with dot-asterisk
299
+ * - Replace forward slash with escaped forward slash
300
+ * - Wrap with caret and dollar for exact matching
301
+ *
302
+ * This pattern is constructed dynamically at runtime
303
+ */
304
+ globToRegex: 'DYNAMIC_PATTERN' // Constructed at runtime
305
+ };
306
+
307
+ /**
308
+ * Regular expressions for whitespace handling
309
+ * Used throughout the codebase for text processing
310
+ */
311
+ const whitespace = {
312
+ /**
313
+ * Matches one or more consecutive whitespace characters
314
+ * Used for normalizing spaces in term processing
315
+ *
316
+ * Examples:
317
+ * - "term with spaces" → "term-with-spaces" (when replaced with '-')
318
+ * - "multiple spaces" → "multiple-spaces" (when replaced with '-')
319
+ *
320
+ * Flags:
321
+ * - g: global to replace all whitespace sequences
322
+ */
323
+ oneOrMore: /\s+/g
324
+ };
325
+
326
+ /**
327
+ * Regular expressions for URL and link processing
328
+ * Used in server-side URL manipulation and external references
329
+ */
330
+ const urls = {
331
+ /**
332
+ * Matches URL patterns for extracting base URL from versioned URLs
333
+ *
334
+ * Groups:
335
+ * - Group 1: base URL (protocol + domain + path up to /versions/)
336
+ *
337
+ * Used for processing versioned URLs in server-side context
338
+ *
339
+ * Examples:
340
+ * - "https://example.com/spec/versions/v1/" → base: "https://example.com/spec"
341
+ * - "http://localhost:3000/docs/versions/latest/" → base: "http://localhost:3000/docs"
342
+ */
343
+ versionsBase: /^(https?:\/\/[^\/]+(?:\/[^\/]+)*)\/versions\/(?:[^\/]+\/)?/
344
+ };
345
+
346
+ /**
347
+ * Regular expressions for parsing HTML comments and metadata
348
+ * Used in source tracking and content processing
349
+ */
350
+ const htmlComments = {
351
+ /**
352
+ * Matches HTML file tracking comments inserted by the renderer
353
+ *
354
+ * Groups:
355
+ * - Group 1: filename (path to the source file)
356
+ *
357
+ * Used to extract the source file name from HTML comments for tracking purposes
358
+ *
359
+ * Examples:
360
+ * - "<!-- file: src/example.md -->" → filename: "src/example.md"
361
+ * - "<!-- file: docs/spec.md -->" → filename: "docs/spec.md"
362
+ *
363
+ * Pattern breakdown:
364
+ * - <!-- file: → Literal HTML comment start with "file: "
365
+ * - (.+?) → Capture group 1: filename (non-greedy)
366
+ * - --> → Literal HTML comment end
367
+ */
368
+ fileTracker: /<!-- file: (.+?) -->/
369
+ };
370
+
371
+ /**
372
+ * Regular expressions for content cleaning and sanitization
373
+ * Used in tooltip generation and safe HTML output
374
+ */
375
+ const contentCleaning = {
376
+ /**
377
+ * Matches double quotes for escaping in HTML attributes
378
+ * Used to prevent HTML attribute injection and ensure safe tooltip content
379
+ *
380
+ * Examples:
381
+ * - 'text with "quotes"' → 'text with &quot;quotes&quot;'
382
+ *
383
+ * Flags:
384
+ * - g: global to replace all quotes
385
+ */
386
+ quotes: /"/g,
387
+
388
+ /**
389
+ * Matches newline characters for content normalization
390
+ * Used to convert multiline content to single line for tooltips
391
+ *
392
+ * Examples:
393
+ * - "line1\nline2\nline3" → "line1 line2 line3" (when replaced with ' ')
394
+ *
395
+ * Flags:
396
+ * - g: global to replace all newlines
397
+ */
398
+ newlines: /\n/g
399
+ };
400
+
401
+ /**
402
+ * Export object containing all regex categories
403
+ *
404
+ * Usage:
405
+ * const { templateTags, externalReferences } = require('./regex-patterns');
406
+ * const match = text.match(templateTags.replacer);
407
+ */
408
+ module.exports = {
409
+ templateTags,
410
+ externalReferences,
411
+ escaping,
412
+ paths,
413
+ versions,
414
+ gitignore,
415
+ whitespace,
416
+ urls,
417
+ htmlComments,
418
+ contentCleaning
419
+ };
420
+
421
+ /**
422
+ * Utility functions for common regex operations
423
+ * These functions encapsulate complex regex construction patterns
424
+ */
425
+ const utils = {
426
+ /**
427
+ * Escapes special regex characters in a string to treat them literally
428
+ *
429
+ * @param {string} str - String to escape
430
+ * @returns {string} String with special regex characters escaped
431
+ *
432
+ * Example:
433
+ * escapeRegexChars("test.file") → "test\\.file"
434
+ */
435
+ escapeRegexChars: function(str) {
436
+ return str.replace(escaping.specialChars, '\\$&');
437
+ },
438
+
439
+ /**
440
+ * Creates a dynamic regex for matching external references with specific spec and term
441
+ *
442
+ * @param {string} spec - External specification identifier
443
+ * @param {string} term - Term to match
444
+ * @returns {RegExp} Compiled regex for matching the specific external reference
445
+ *
446
+ * Example:
447
+ * createXTrefRegex("spec1", "term1") → /\[\[(?:x|t)ref:\s*spec1,\s*term1(?:,\s*[^\]]+)?\]\]/g
448
+ */
449
+ createXTrefRegex: function(spec, term) {
450
+ const escapedSpec = this.escapeRegexChars(spec);
451
+ const escapedTerm = this.escapeRegexChars(term);
452
+ return new RegExp(`\\[\\[(?:x|t)ref:\\s*${escapedSpec},\\s*${escapedTerm}(?:,\\s*[^\\]]+)?\\]\\]`, 'g');
453
+ },
454
+
455
+ /**
456
+ * Creates a regex for matching gitignore glob patterns
457
+ *
458
+ * @param {string} globPattern - Gitignore pattern with wildcards
459
+ * @returns {RegExp} Compiled regex for matching file paths
460
+ *
461
+ * Example:
462
+ * createGitignoreRegex("dist/*") → /^dist\/.*$/
463
+ */
464
+ createGitignoreRegex: function(globPattern) {
465
+ const pattern = '^' + globPattern.replace(/\*/g, '.*').replace(/\//g, '\\/') + '$';
466
+ return new RegExp(pattern);
467
+ }
468
+ };
469
+
470
+ // Also export utility functions
471
+ module.exports.utils = utils;