spec-up-t 1.2.0 → 1.2.1

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 (2) hide show
  1. package/index.js +84 -53
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -189,6 +189,14 @@ module.exports = async function (options = {}) {
189
189
  return fs.readFileSync(path, 'utf8');
190
190
  }
191
191
  },
192
+ {
193
+ test: 'spec',
194
+ transform: function (originalMatch, type, name) {
195
+ // Simply return an empty string or special marker that won't be treated as a definition term
196
+ // The actual rendering will be handled by the markdown-it extension
197
+ return `<span class="spec-marker" data-spec="${name}"></span>`;
198
+ }
199
+ },
192
200
  /**
193
201
  * Custom replacer for tref tags that converts them directly to HTML definition term elements.
194
202
  *
@@ -392,70 +400,93 @@ module.exports = async function (options = {}) {
392
400
  return dl.classList && dl.classList.contains('terms-and-definitions-list');
393
401
  });
394
402
 
395
- // First special case - handle transcluded-xref-term dt that comes BEFORE the main dl
396
- const transcludedTermsBeforeMainDl = document.querySelectorAll('dt.transcluded-xref-term');
403
+ // Find any transcluded term dt elements anywhere in the document
404
+ const transcludedTerms = document.querySelectorAll('dt.transcluded-xref-term');
405
+
397
406
  let mainDl = null;
398
407
 
399
- if (dlElements.length > 0) {
408
+ // If we have transcluded terms but no main dl, we need to create one
409
+ if (transcludedTerms.length > 0 && dlElements.length === 0) {
410
+ // Create a new dl element with the right class
411
+ mainDl = document.createElement('dl');
412
+ mainDl.className = 'terms-and-definitions-list';
413
+
414
+ // Find a good location to insert it - use the first transcluded term's parent as reference
415
+ const firstTerm = transcludedTerms[0];
416
+ const insertPoint = firstTerm.parentNode;
417
+ insertPoint.parentNode.insertBefore(mainDl, insertPoint);
418
+ } else if (dlElements.length > 0) {
400
419
  // Use the first terms-and-definitions-list as our main container
401
420
  mainDl = dlElements[0];
421
+ } else {
422
+ // No dl and no transcluded terms, nothing to fix
423
+ return html;
424
+ }
402
425
 
403
- // Special handling for transcluded terms that appear BEFORE the main dl
404
- transcludedTermsBeforeMainDl.forEach(dt => {
405
- // Check if this dt is not already inside a dl.terms-and-definitions-list
406
- if (!dt.parentElement.classList.contains('terms-and-definitions-list')) {
407
- // This is a dt outside our main list - move it into the main dl at the beginning
408
- const dtClone = dt.cloneNode(true);
409
- mainDl.insertBefore(dtClone, mainDl.firstChild);
410
- dt.parentNode.removeChild(dt);
411
- }
412
- });
426
+ // Now process all transcluded terms and other dt elements
427
+ transcludedTerms.forEach(dt => {
428
+ // Check if this dt is not already inside our main dl
429
+ if (dt.parentElement !== mainDl) {
430
+ // Move it into the main dl
431
+ const dtClone = dt.cloneNode(true);
432
+ mainDl.appendChild(dtClone);
433
+ dt.parentNode.removeChild(dt);
434
+ }
435
+ });
413
436
 
414
- // Remove any empty dt elements that may exist
415
- const emptyDts = mainDl.querySelectorAll('dt:empty');
416
- emptyDts.forEach(emptyDt => {
417
- emptyDt.parentNode.removeChild(emptyDt);
418
- });
437
+ // First special case - handle transcluded-xref-term dt that comes BEFORE the main dl
438
+ const transcludedTermsBeforeMainDl = document.querySelectorAll('dt.transcluded-xref-term');
419
439
 
420
- // Process all subsequent content after the main dl
421
- let currentNode = mainDl.nextSibling;
422
-
423
- // Process all subsequent content
424
- while (currentNode) {
425
- // Save the next node before potentially modifying the DOM
426
- // (This is important because modifying the DOM can invalidate our references)
427
- const nextNode = currentNode.nextSibling;
428
-
429
- // Handle different node types
430
- if (currentNode.nodeType === 1) { // 1 = Element node
431
- if (currentNode.tagName === 'DL') {
432
- // Found another definition list - move all its children to the main dl
433
- // This effectively merges the two lists into one
434
- while (currentNode.firstChild) {
435
- mainDl.appendChild(currentNode.firstChild);
436
- }
440
+ // Special handling for transcluded terms that appear BEFORE the main dl
441
+ transcludedTermsBeforeMainDl.forEach(dt => {
442
+ // Check if this dt is not already inside our main list
443
+ if (dt.parentElement !== mainDl) {
444
+ // This is a dt outside our main list - move it into the main dl
445
+ const dtClone = dt.cloneNode(true);
446
+ mainDl.appendChild(dtClone);
447
+ dt.parentNode.removeChild(dt);
448
+ }
449
+ });
437
450
 
438
- // Remove the now-empty dl element
439
- currentNode.parentNode.removeChild(currentNode);
440
- }
441
- else if (currentNode.tagName === 'DT') {
442
- // Found a standalone dt (like our transcluded tref terms)
443
- // Move it into the main dl to maintain continuity
444
- const dtClone = currentNode.cloneNode(true);
445
- mainDl.appendChild(dtClone);
446
- currentNode.parentNode.removeChild(currentNode);
447
- }
448
- else if (currentNode.tagName === 'P' &&
449
- (!currentNode.textContent || currentNode.textContent.trim() === '')) {
450
- // Remove empty paragraphs - these break the list structure
451
- // Empty <p></p> tags often appear between dl elements
452
- currentNode.parentNode.removeChild(currentNode);
451
+ // Remove any empty dt elements that may exist
452
+ const emptyDts = mainDl.querySelectorAll('dt:empty');
453
+ emptyDts.forEach(emptyDt => {
454
+ emptyDt.parentNode.removeChild(emptyDt);
455
+ });
456
+
457
+ // Process all subsequent content after the main dl
458
+ let currentNode = mainDl.nextSibling;
459
+
460
+ // Process all subsequent content
461
+ while (currentNode) {
462
+ // Save the next node before potentially modifying the DOM
463
+ const nextNode = currentNode.nextSibling;
464
+
465
+ // Handle different node types
466
+ if (currentNode.nodeType === 1) { // 1 = Element node
467
+ if (currentNode.tagName === 'DL') {
468
+ // Found another definition list - move all its children to the main dl
469
+ while (currentNode.firstChild) {
470
+ mainDl.appendChild(currentNode.firstChild);
453
471
  }
472
+ // Remove the now-empty dl element
473
+ currentNode.parentNode.removeChild(currentNode);
474
+ }
475
+ else if (currentNode.tagName === 'DT') {
476
+ // Found a standalone dt - move it into the main dl
477
+ const dtClone = currentNode.cloneNode(true);
478
+ mainDl.appendChild(dtClone);
479
+ currentNode.parentNode.removeChild(currentNode);
480
+ }
481
+ else if (currentNode.tagName === 'P' &&
482
+ (!currentNode.textContent || currentNode.textContent.trim() === '')) {
483
+ // Remove empty paragraphs - these break the list structure
484
+ currentNode.parentNode.removeChild(currentNode);
454
485
  }
455
-
456
- // Move to the next node we saved earlier
457
- currentNode = nextNode;
458
486
  }
487
+
488
+ // Move to the next node we saved earlier
489
+ currentNode = nextNode;
459
490
  }
460
491
 
461
492
  // Return the fixed HTML
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spec-up-t",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Technical specification drafting tool that generates rich specification documents from markdown. Forked from https://github.com/decentralized-identity/spec-up by Daniel Buchner (https://github.com/csuwildcat)",
5
5
  "main": "./index",
6
6
  "repository": {