All files / src/markdown-it index.js

100% Statements 10/10
0% Branches 0/1
100% Functions 1/1
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78                                          1x 1x 1x                                                                       4x     4x     4x           1x     1x 1x 1x  
'use strict';
 
/**
 * Markdown-it Extensions Module Orchestrator
 * 
 * This module serves as the main entry point for all markdown-it enhancements
 * used in the spec-up system. It provides a clean interface to apply all
 * custom rendering rules and functionality to a markdown-it instance.
 * 
 * The module is organized into focused sub-modules, each handling a specific
 * aspect of markdown processing:
 * 
 * - TABLE ENHANCEMENT: Bootstrap styling and responsive wrappers
 * - TEMPLATE-TAG SYNTAX: Custom [[template-tag:args]] syntax processing
 * - DEFINITION LISTS: Advanced terminology and reference list handling
 * 
 * This modular approach makes the code more maintainable and easier to
 * understand for developers unfamiliar with the markdown-it library.
 */
 
// Import all the specialized enhancement modules
const applyTableEnhancements = require('./table-enhancement');
const applyTemplateTagSyntax = require('./template-tag-syntax');
const applyDefinitionListEnhancements = require('./definition-lists');
 
/**
 * Applies all markdown-it enhancements to a markdown-it instance
 * 
 * This is the main function that consuming code should call. It orchestrates
 * the application of all enhancement modules in the correct order.
 * 
 * @param {Object} md - The markdown-it instance to enhance
 * @param {Array} templates - Array of template-tag handler objects for custom syntax
 *                            Each template-tag handler should have:
 *                            - filter(type): function returning true if handler processes this type
 *                            - parse(token, type, ...args): optional preprocessing function
 *                            - render(token, type, ...args): function returning HTML string
 * 
 * @example
 * const MarkdownIt = require('markdown-it');
 * const applyMarkdownItExtensions = require('./markdown-it');
 * 
 * const md = new MarkdownIt();
 * const templates = [
 *   {
 *     filter: type => type === 'def',
 *     render: (token, type, term) => `<span id="term:${term}">${term}</span>`
 *   }
 * ];
 * 
 * applyMarkdownItExtensions(md, templates);
 * const html = md.render('[[def:example-term]]');
 */
function applyMarkdownItExtensions(md, templates = []) {
  
  // Apply enhancements in order of dependency
  // Some modules may depend on others being applied first
  
  // 1. Table enhancements - independent, can be applied first
  applyTableEnhancements(md);
  
  // 2. Template-tag syntax - should be applied early as other modules may depend on it
  applyTemplateTagSyntax(md, templates);
  
  // 3. Definition lists - depends on template-tag syntax for term type detection
  applyDefinitionListEnhancements(md);
  
  // The markdown-it instance is now fully enhanced and ready for use
}
 
// Export the main orchestrator function
module.exports = applyMarkdownItExtensions;
 
// Also export individual modules for fine-grained control if needed
module.exports.tableEnhancements = applyTableEnhancements;
module.exports.templateTagSyntax = applyTemplateTagSyntax;
module.exports.definitionLists = applyDefinitionListEnhancements;