legal-markdown-js 0.1.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.
- package/LICENSE +21 -0
- package/README.md +168 -0
- package/dist/browser.d.ts +87 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +157 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli/index.d.ts +34 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +221 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/service.d.ts +128 -0
- package/dist/cli/service.d.ts.map +1 -0
- package/dist/cli/service.js +284 -0
- package/dist/cli/service.js.map +1 -0
- package/dist/constants/index.d.ts +229 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +232 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/core/exporters/metadata-exporter.d.ts +104 -0
- package/dist/core/exporters/metadata-exporter.d.ts.map +1 -0
- package/dist/core/exporters/metadata-exporter.js +201 -0
- package/dist/core/exporters/metadata-exporter.js.map +1 -0
- package/dist/core/index.d.ts +40 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +56 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/parsers/yaml-parser.d.ts +149 -0
- package/dist/core/parsers/yaml-parser.d.ts.map +1 -0
- package/dist/core/parsers/yaml-parser.js +321 -0
- package/dist/core/parsers/yaml-parser.js.map +1 -0
- package/dist/core/processors/clause-processor.d.ts +74 -0
- package/dist/core/processors/clause-processor.d.ts.map +1 -0
- package/dist/core/processors/clause-processor.js +213 -0
- package/dist/core/processors/clause-processor.js.map +1 -0
- package/dist/core/processors/date-processor.d.ts +90 -0
- package/dist/core/processors/date-processor.d.ts.map +1 -0
- package/dist/core/processors/date-processor.js +336 -0
- package/dist/core/processors/date-processor.js.map +1 -0
- package/dist/core/processors/header-processor.d.ts +104 -0
- package/dist/core/processors/header-processor.d.ts.map +1 -0
- package/dist/core/processors/header-processor.js +585 -0
- package/dist/core/processors/header-processor.js.map +1 -0
- package/dist/core/processors/import-processor.d.ts +116 -0
- package/dist/core/processors/import-processor.d.ts.map +1 -0
- package/dist/core/processors/import-processor.js +236 -0
- package/dist/core/processors/import-processor.js.map +1 -0
- package/dist/core/processors/mixin-processor.d.ts +93 -0
- package/dist/core/processors/mixin-processor.d.ts.map +1 -0
- package/dist/core/processors/mixin-processor.js +378 -0
- package/dist/core/processors/mixin-processor.js.map +1 -0
- package/dist/core/processors/reference-processor.d.ts +115 -0
- package/dist/core/processors/reference-processor.d.ts.map +1 -0
- package/dist/core/processors/reference-processor.js +273 -0
- package/dist/core/processors/reference-processor.js.map +1 -0
- package/dist/errors/index.d.ts +234 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +267 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/extensions/batch-processor.d.ts +197 -0
- package/dist/extensions/batch-processor.d.ts.map +1 -0
- package/dist/extensions/batch-processor.js +392 -0
- package/dist/extensions/batch-processor.js.map +1 -0
- package/dist/extensions/formatters/index.d.ts +99 -0
- package/dist/extensions/formatters/index.d.ts.map +1 -0
- package/dist/extensions/formatters/index.js +128 -0
- package/dist/extensions/formatters/index.js.map +1 -0
- package/dist/extensions/index.d.ts +53 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +71 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/latex-parser.d.ts +111 -0
- package/dist/extensions/latex-parser.d.ts.map +1 -0
- package/dist/extensions/latex-parser.js +563 -0
- package/dist/extensions/latex-parser.js.map +1 -0
- package/dist/extensions/rst-parser.d.ts +112 -0
- package/dist/extensions/rst-parser.d.ts.map +1 -0
- package/dist/extensions/rst-parser.js +268 -0
- package/dist/extensions/rst-parser.js.map +1 -0
- package/dist/extensions/template-loops.d.ts +61 -0
- package/dist/extensions/template-loops.d.ts.map +1 -0
- package/dist/extensions/template-loops.js +418 -0
- package/dist/extensions/template-loops.js.map +1 -0
- package/dist/extensions/utilities/index.d.ts +114 -0
- package/dist/extensions/utilities/index.d.ts.map +1 -0
- package/dist/extensions/utilities/index.js +137 -0
- package/dist/extensions/utilities/index.js.map +1 -0
- package/dist/extensions/validators/index.d.ts +65 -0
- package/dist/extensions/validators/index.d.ts.map +1 -0
- package/dist/extensions/validators/index.js +88 -0
- package/dist/extensions/validators/index.js.map +1 -0
- package/dist/generators/html-generator.d.ts +184 -0
- package/dist/generators/html-generator.d.ts.map +1 -0
- package/dist/generators/html-generator.js +361 -0
- package/dist/generators/html-generator.js.map +1 -0
- package/dist/generators/pdf-generator.d.ts +165 -0
- package/dist/generators/pdf-generator.d.ts.map +1 -0
- package/dist/generators/pdf-generator.js +275 -0
- package/dist/generators/pdf-generator.js.map +1 -0
- package/dist/helpers/date-helpers.d.ts +216 -0
- package/dist/helpers/date-helpers.d.ts.map +1 -0
- package/dist/helpers/date-helpers.js +402 -0
- package/dist/helpers/date-helpers.js.map +1 -0
- package/dist/helpers/index.d.ts +87 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +149 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/number-helpers.d.ts +269 -0
- package/dist/helpers/number-helpers.d.ts.map +1 -0
- package/dist/helpers/number-helpers.js +406 -0
- package/dist/helpers/number-helpers.js.map +1 -0
- package/dist/helpers/string-helpers.d.ts +391 -0
- package/dist/helpers/string-helpers.d.ts.map +1 -0
- package/dist/helpers/string-helpers.js +549 -0
- package/dist/helpers/string-helpers.js.map +1 -0
- package/dist/index.d.ts +229 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +384 -0
- package/dist/index.js.map +1 -0
- package/dist/legal-markdown.umd.min.js +2 -0
- package/dist/legal-markdown.umd.min.js.LICENSE.txt +14 -0
- package/dist/legal-markdown.umd.min.js.map +1 -0
- package/dist/lib/index.d.ts +150 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +265 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/parsers/content-detector.d.ts +131 -0
- package/dist/parsers/content-detector.d.ts.map +1 -0
- package/dist/parsers/content-detector.js +220 -0
- package/dist/parsers/content-detector.js.map +1 -0
- package/dist/parsers/fallback-parsers.d.ts +14 -0
- package/dist/parsers/fallback-parsers.d.ts.map +1 -0
- package/dist/parsers/fallback-parsers.js +188 -0
- package/dist/parsers/fallback-parsers.js.map +1 -0
- package/dist/parsers/implementations/pandoc-native.d.ts +13 -0
- package/dist/parsers/implementations/pandoc-native.d.ts.map +1 -0
- package/dist/parsers/implementations/pandoc-native.js +63 -0
- package/dist/parsers/implementations/pandoc-native.js.map +1 -0
- package/dist/parsers/implementations/pandoc-wasm.d.ts +14 -0
- package/dist/parsers/implementations/pandoc-wasm.d.ts.map +1 -0
- package/dist/parsers/implementations/pandoc-wasm.js +64 -0
- package/dist/parsers/implementations/pandoc-wasm.js.map +1 -0
- package/dist/parsers/pandoc-factory.d.ts +97 -0
- package/dist/parsers/pandoc-factory.d.ts.map +1 -0
- package/dist/parsers/pandoc-factory.js +146 -0
- package/dist/parsers/pandoc-factory.js.map +1 -0
- package/dist/parsers/pandoc-loader.d.ts +24 -0
- package/dist/parsers/pandoc-loader.d.ts.map +1 -0
- package/dist/parsers/pandoc-loader.js +124 -0
- package/dist/parsers/pandoc-loader.js.map +1 -0
- package/dist/parsers/pandoc-parser.d.ts +27 -0
- package/dist/parsers/pandoc-parser.d.ts.map +1 -0
- package/dist/parsers/pandoc-parser.js +3 -0
- package/dist/parsers/pandoc-parser.js.map +1 -0
- package/dist/styles/default.css +125 -0
- package/dist/styles/headers.css +146 -0
- package/dist/styles/highlight.css +171 -0
- package/dist/tracking/field-tracker.d.ts +206 -0
- package/dist/tracking/field-tracker.d.ts.map +1 -0
- package/dist/tracking/field-tracker.js +247 -0
- package/dist/tracking/field-tracker.js.map +1 -0
- package/dist/types.d.ts +186 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +33 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/logger.d.ts +107 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +122 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/web/bundle-standalone.js +28 -0
- package/dist/web/bundle.js +17 -0
- package/dist/web/index.html +1465 -0
- package/dist/web/legal-markdown.umd.min.js +2 -0
- package/dist/web/standalone.html +390 -0
- package/dist/web/styles.css +874 -0
- package/package.json +118 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Import Processing Module for Legal Markdown Documents
|
|
3
|
+
*
|
|
4
|
+
* This module provides functionality to process partial imports in Legal Markdown
|
|
5
|
+
* documents, allowing for modular document construction by including external
|
|
6
|
+
* files. It supports both absolute and relative import paths, recursive import
|
|
7
|
+
* processing, and comprehensive error handling for missing files.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Import syntax: @import filename
|
|
11
|
+
* - Relative and absolute path resolution
|
|
12
|
+
* - Recursive import processing (nested imports)
|
|
13
|
+
* - Import tracking and cycle detection
|
|
14
|
+
* - Error handling with fallback content
|
|
15
|
+
* - Base path resolution for project organization
|
|
16
|
+
* - Import validation and file existence checking
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { processPartialImports } from './import-processor';
|
|
21
|
+
*
|
|
22
|
+
* // Main document content
|
|
23
|
+
* const content = `
|
|
24
|
+
* # Service Agreement
|
|
25
|
+
*
|
|
26
|
+
* @import ./clauses/standard-terms.md
|
|
27
|
+
*
|
|
28
|
+
* ## Specific Terms
|
|
29
|
+
* @import ./clauses/payment-terms.md
|
|
30
|
+
* @import ./clauses/termination.md
|
|
31
|
+
*
|
|
32
|
+
* @import ./signatures/signature-block.md
|
|
33
|
+
* `;
|
|
34
|
+
*
|
|
35
|
+
* const result = processPartialImports(content, './contracts');
|
|
36
|
+
* console.log(result.content); // Processed content with imports resolved
|
|
37
|
+
* console.log(result.importedFiles); // Array of imported file paths
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
import { ImportProcessingResult } from '@types';
|
|
41
|
+
/**
|
|
42
|
+
* Processes partial imports in a LegalMarkdown document
|
|
43
|
+
*
|
|
44
|
+
* This is the main function that processes import statements using the @import syntax.
|
|
45
|
+
* It recursively resolves and includes external files, tracking all imported files
|
|
46
|
+
* and handling errors gracefully when files cannot be found or loaded.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} content - The document content containing import statements
|
|
49
|
+
* @param {string} [basePath] - Optional base path for resolving relative imports
|
|
50
|
+
* @returns {ImportProcessingResult} Object containing processed content and list of imported files
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // Basic import processing
|
|
54
|
+
* const content = `
|
|
55
|
+
* # Main Document
|
|
56
|
+
* @import ./introduction.md
|
|
57
|
+
* @import ./body.md
|
|
58
|
+
* @import ./conclusion.md
|
|
59
|
+
* `;
|
|
60
|
+
*
|
|
61
|
+
* const result = processPartialImports(content, './documents');
|
|
62
|
+
* console.log(result.content); // Content with imports resolved
|
|
63
|
+
* console.log(result.importedFiles); // ['./documents/introduction.md', './documents/body.md', './documents/conclusion.md']
|
|
64
|
+
*
|
|
65
|
+
* // Nested imports example
|
|
66
|
+
* // main.md: @import ./sections/terms.md
|
|
67
|
+
* // terms.md: @import ./subsections/payment.md
|
|
68
|
+
* // Result will include content from all three files
|
|
69
|
+
*
|
|
70
|
+
* // Error handling
|
|
71
|
+
* const contentWithMissingFile = `
|
|
72
|
+
* # Document
|
|
73
|
+
* @import ./existing.md
|
|
74
|
+
* @import ./missing.md
|
|
75
|
+
* `;
|
|
76
|
+
*
|
|
77
|
+
* const result2 = processPartialImports(contentWithMissingFile);
|
|
78
|
+
* // Result will include content from existing.md and error comment for missing.md
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function processPartialImports(content: string, basePath?: string): ImportProcessingResult;
|
|
82
|
+
/**
|
|
83
|
+
* Validates that all import paths in a document exist
|
|
84
|
+
*
|
|
85
|
+
* Checks all import statements in a document to ensure the referenced files exist
|
|
86
|
+
* on the filesystem. Returns an array of error messages for any missing files,
|
|
87
|
+
* or an empty array if all imports are valid.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} content - The document content containing import statements to validate
|
|
90
|
+
* @param {string} [basePath] - Optional base path for resolving relative imports
|
|
91
|
+
* @returns {string[]} Array of validation errors, empty if all imports are valid
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const content = `
|
|
95
|
+
* # Document
|
|
96
|
+
* @import ./existing-file.md
|
|
97
|
+
* @import ./missing-file.md
|
|
98
|
+
* @import /absolute/path/to/file.md
|
|
99
|
+
* `;
|
|
100
|
+
*
|
|
101
|
+
* const errors = validateImports(content, './documents');
|
|
102
|
+
* console.log(errors);
|
|
103
|
+
* // Output (if files are missing):
|
|
104
|
+
* // [
|
|
105
|
+
* // "Import file not found: ./documents/missing-file.md",
|
|
106
|
+
* // "Import file not found: /absolute/path/to/file.md"
|
|
107
|
+
* // ]
|
|
108
|
+
*
|
|
109
|
+
* // For valid imports
|
|
110
|
+
* const validContent = `@import ./existing-file.md`;
|
|
111
|
+
* const noErrors = validateImports(validContent, './documents');
|
|
112
|
+
* console.log(noErrors); // [] (empty array)
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function validateImports(content: string, basePath?: string): string[];
|
|
116
|
+
//# sourceMappingURL=import-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-processor.d.ts","sourceRoot":"","sources":["../../../src/core/processors/import-processor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAIH,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,sBAAsB,CAmChG;AAwCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAqB5E"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Import Processing Module for Legal Markdown Documents
|
|
4
|
+
*
|
|
5
|
+
* This module provides functionality to process partial imports in Legal Markdown
|
|
6
|
+
* documents, allowing for modular document construction by including external
|
|
7
|
+
* files. It supports both absolute and relative import paths, recursive import
|
|
8
|
+
* processing, and comprehensive error handling for missing files.
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Import syntax: @import filename
|
|
12
|
+
* - Relative and absolute path resolution
|
|
13
|
+
* - Recursive import processing (nested imports)
|
|
14
|
+
* - Import tracking and cycle detection
|
|
15
|
+
* - Error handling with fallback content
|
|
16
|
+
* - Base path resolution for project organization
|
|
17
|
+
* - Import validation and file existence checking
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { processPartialImports } from './import-processor';
|
|
22
|
+
*
|
|
23
|
+
* // Main document content
|
|
24
|
+
* const content = `
|
|
25
|
+
* # Service Agreement
|
|
26
|
+
*
|
|
27
|
+
* @import ./clauses/standard-terms.md
|
|
28
|
+
*
|
|
29
|
+
* ## Specific Terms
|
|
30
|
+
* @import ./clauses/payment-terms.md
|
|
31
|
+
* @import ./clauses/termination.md
|
|
32
|
+
*
|
|
33
|
+
* @import ./signatures/signature-block.md
|
|
34
|
+
* `;
|
|
35
|
+
*
|
|
36
|
+
* const result = processPartialImports(content, './contracts');
|
|
37
|
+
* console.log(result.content); // Processed content with imports resolved
|
|
38
|
+
* console.log(result.importedFiles); // Array of imported file paths
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
42
|
+
if (k2 === undefined) k2 = k;
|
|
43
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
44
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
45
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
46
|
+
}
|
|
47
|
+
Object.defineProperty(o, k2, desc);
|
|
48
|
+
}) : (function(o, m, k, k2) {
|
|
49
|
+
if (k2 === undefined) k2 = k;
|
|
50
|
+
o[k2] = m[k];
|
|
51
|
+
}));
|
|
52
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
53
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
54
|
+
}) : function(o, v) {
|
|
55
|
+
o["default"] = v;
|
|
56
|
+
});
|
|
57
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
58
|
+
var ownKeys = function(o) {
|
|
59
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
60
|
+
var ar = [];
|
|
61
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
62
|
+
return ar;
|
|
63
|
+
};
|
|
64
|
+
return ownKeys(o);
|
|
65
|
+
};
|
|
66
|
+
return function (mod) {
|
|
67
|
+
if (mod && mod.__esModule) return mod;
|
|
68
|
+
var result = {};
|
|
69
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
70
|
+
__setModuleDefault(result, mod);
|
|
71
|
+
return result;
|
|
72
|
+
};
|
|
73
|
+
})();
|
|
74
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
75
|
+
exports.processPartialImports = processPartialImports;
|
|
76
|
+
exports.validateImports = validateImports;
|
|
77
|
+
const fs = __importStar(require("fs"));
|
|
78
|
+
const path = __importStar(require("path"));
|
|
79
|
+
/**
|
|
80
|
+
* Processes partial imports in a LegalMarkdown document
|
|
81
|
+
*
|
|
82
|
+
* This is the main function that processes import statements using the @import syntax.
|
|
83
|
+
* It recursively resolves and includes external files, tracking all imported files
|
|
84
|
+
* and handling errors gracefully when files cannot be found or loaded.
|
|
85
|
+
*
|
|
86
|
+
* @param {string} content - The document content containing import statements
|
|
87
|
+
* @param {string} [basePath] - Optional base path for resolving relative imports
|
|
88
|
+
* @returns {ImportProcessingResult} Object containing processed content and list of imported files
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* // Basic import processing
|
|
92
|
+
* const content = `
|
|
93
|
+
* # Main Document
|
|
94
|
+
* @import ./introduction.md
|
|
95
|
+
* @import ./body.md
|
|
96
|
+
* @import ./conclusion.md
|
|
97
|
+
* `;
|
|
98
|
+
*
|
|
99
|
+
* const result = processPartialImports(content, './documents');
|
|
100
|
+
* console.log(result.content); // Content with imports resolved
|
|
101
|
+
* console.log(result.importedFiles); // ['./documents/introduction.md', './documents/body.md', './documents/conclusion.md']
|
|
102
|
+
*
|
|
103
|
+
* // Nested imports example
|
|
104
|
+
* // main.md: @import ./sections/terms.md
|
|
105
|
+
* // terms.md: @import ./subsections/payment.md
|
|
106
|
+
* // Result will include content from all three files
|
|
107
|
+
*
|
|
108
|
+
* // Error handling
|
|
109
|
+
* const contentWithMissingFile = `
|
|
110
|
+
* # Document
|
|
111
|
+
* @import ./existing.md
|
|
112
|
+
* @import ./missing.md
|
|
113
|
+
* `;
|
|
114
|
+
*
|
|
115
|
+
* const result2 = processPartialImports(contentWithMissingFile);
|
|
116
|
+
* // Result will include content from existing.md and error comment for missing.md
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
function processPartialImports(content, basePath) {
|
|
120
|
+
// Regular expression to match import statements
|
|
121
|
+
// Format: @import [filename]
|
|
122
|
+
const importPattern = /@import\s+(.+?)(?:\s|$)/g;
|
|
123
|
+
const importedFiles = [];
|
|
124
|
+
const processedContent = content.replace(importPattern, (match, filename) => {
|
|
125
|
+
// Clean up filename (remove quotes, etc.)
|
|
126
|
+
const cleanFilename = filename.trim().replace(/['"]/g, '');
|
|
127
|
+
try {
|
|
128
|
+
// Resolve the import path
|
|
129
|
+
const importPath = resolveImportPath(cleanFilename, basePath);
|
|
130
|
+
// Read the imported file
|
|
131
|
+
const importedContent = fs.readFileSync(importPath, 'utf8');
|
|
132
|
+
// Track imported files
|
|
133
|
+
importedFiles.push(importPath);
|
|
134
|
+
// Process nested imports
|
|
135
|
+
const nestedResult = processPartialImports(importedContent, path.dirname(importPath));
|
|
136
|
+
importedFiles.push(...nestedResult.importedFiles);
|
|
137
|
+
return nestedResult.content;
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error(`Error importing file ${cleanFilename}:`, error);
|
|
141
|
+
return `<!-- Error importing ${cleanFilename} -->`;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
content: processedContent,
|
|
146
|
+
importedFiles,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Resolves the absolute path of an import
|
|
151
|
+
*
|
|
152
|
+
* Converts relative import paths to absolute paths using the provided base path
|
|
153
|
+
* or current working directory. Handles both relative and absolute paths correctly.
|
|
154
|
+
*
|
|
155
|
+
* @private
|
|
156
|
+
* @param {string} importPath - Relative or absolute import path to resolve
|
|
157
|
+
* @param {string} [basePath] - Base path for resolving relative imports
|
|
158
|
+
* @returns {string} Absolute path to the imported file
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* // Relative path resolution
|
|
162
|
+
* const absolutePath = resolveImportPath("./clauses/terms.md", "/contracts");
|
|
163
|
+
* // Returns: "/contracts/clauses/terms.md"
|
|
164
|
+
*
|
|
165
|
+
* // Absolute path (unchanged)
|
|
166
|
+
* const absolutePath2 = resolveImportPath("/full/path/to/file.md");
|
|
167
|
+
* // Returns: "/full/path/to/file.md"
|
|
168
|
+
*
|
|
169
|
+
* // Relative to current directory
|
|
170
|
+
* const absolutePath3 = resolveImportPath("./local-file.md");
|
|
171
|
+
* // Returns: "/current/working/directory/local-file.md"
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
function resolveImportPath(importPath, basePath) {
|
|
175
|
+
// If the import path is absolute, use it directly
|
|
176
|
+
if (path.isAbsolute(importPath)) {
|
|
177
|
+
return importPath;
|
|
178
|
+
}
|
|
179
|
+
// If no base path provided, use current working directory
|
|
180
|
+
const base = basePath || process.cwd();
|
|
181
|
+
// Resolve relative to base path
|
|
182
|
+
return path.resolve(base, importPath);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Validates that all import paths in a document exist
|
|
186
|
+
*
|
|
187
|
+
* Checks all import statements in a document to ensure the referenced files exist
|
|
188
|
+
* on the filesystem. Returns an array of error messages for any missing files,
|
|
189
|
+
* or an empty array if all imports are valid.
|
|
190
|
+
*
|
|
191
|
+
* @param {string} content - The document content containing import statements to validate
|
|
192
|
+
* @param {string} [basePath] - Optional base path for resolving relative imports
|
|
193
|
+
* @returns {string[]} Array of validation errors, empty if all imports are valid
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* const content = `
|
|
197
|
+
* # Document
|
|
198
|
+
* @import ./existing-file.md
|
|
199
|
+
* @import ./missing-file.md
|
|
200
|
+
* @import /absolute/path/to/file.md
|
|
201
|
+
* `;
|
|
202
|
+
*
|
|
203
|
+
* const errors = validateImports(content, './documents');
|
|
204
|
+
* console.log(errors);
|
|
205
|
+
* // Output (if files are missing):
|
|
206
|
+
* // [
|
|
207
|
+
* // "Import file not found: ./documents/missing-file.md",
|
|
208
|
+
* // "Import file not found: /absolute/path/to/file.md"
|
|
209
|
+
* // ]
|
|
210
|
+
*
|
|
211
|
+
* // For valid imports
|
|
212
|
+
* const validContent = `@import ./existing-file.md`;
|
|
213
|
+
* const noErrors = validateImports(validContent, './documents');
|
|
214
|
+
* console.log(noErrors); // [] (empty array)
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
function validateImports(content, basePath) {
|
|
218
|
+
const importPattern = /@import\s+(.+?)(?:\s|$)/g;
|
|
219
|
+
const errors = [];
|
|
220
|
+
let match;
|
|
221
|
+
while ((match = importPattern.exec(content)) !== null) {
|
|
222
|
+
const filename = match[1].trim().replace(/['"]/g, '');
|
|
223
|
+
try {
|
|
224
|
+
const importPath = resolveImportPath(filename, basePath);
|
|
225
|
+
// Check if file exists
|
|
226
|
+
if (!fs.existsSync(importPath)) {
|
|
227
|
+
errors.push(`Import file not found: ${importPath}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
errors.push(`Error resolving import: ${filename}`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return errors;
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=import-processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-processor.js","sourceRoot":"","sources":["../../../src/core/processors/import-processor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CH,sDAmCC;AAyED,0CAqBC;AA7KD,uCAAyB;AACzB,2CAA6B;AAG7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,SAAgB,qBAAqB,CAAC,OAAe,EAAE,QAAiB;IACtE,gDAAgD;IAChD,6BAA6B;IAC7B,MAAM,aAAa,GAAG,0BAA0B,CAAC;IAEjD,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;QAC1E,0CAA0C;QAC1C,MAAM,aAAa,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAE3D,IAAI,CAAC;YACH,0BAA0B;YAC1B,MAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;YAE9D,yBAAyB;YACzB,MAAM,eAAe,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YAE5D,uBAAuB;YACvB,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAE/B,yBAAyB;YACzB,MAAM,YAAY,GAAG,qBAAqB,CAAC,eAAe,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;YACtF,aAAa,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;YAElD,OAAO,YAAY,CAAC,OAAO,CAAC;QAC9B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,wBAAwB,aAAa,GAAG,EAAE,KAAK,CAAC,CAAC;YAC/D,OAAO,wBAAwB,aAAa,MAAM,CAAC;QACrD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,OAAO,EAAE,gBAAgB;QACzB,aAAa;KACd,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAS,iBAAiB,CAAC,UAAkB,EAAE,QAAiB;IAC9D,kDAAkD;IAClD,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,0DAA0D;IAC1D,MAAM,IAAI,GAAG,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAEvC,gCAAgC;IAChC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,SAAgB,eAAe,CAAC,OAAe,EAAE,QAAiB;IAChE,MAAM,aAAa,GAAG,0BAA0B,CAAC;IACjD,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,KAAK,CAAC;IACV,OAAO,CAAC,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACtD,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAEtD,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAEzD,uBAAuB;YACvB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC/B,MAAM,CAAC,IAAI,CAAC,0BAA0B,UAAU,EAAE,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,2BAA2B,QAAQ,EAAE,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Mixin Processing Module for Legal Markdown Documents
|
|
3
|
+
*
|
|
4
|
+
* This module provides comprehensive mixin processing functionality for Legal Markdown
|
|
5
|
+
* documents, supporting variable substitution, helper functions, conditional logic,
|
|
6
|
+
* and nested value access. It integrates with the field tracking system to monitor
|
|
7
|
+
* variable usage and provides robust error handling for complex document templates.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Variable substitution syntax: {{variable}}
|
|
11
|
+
* - Helper function calls: {{helperName(arg1, arg2)}}
|
|
12
|
+
* - Conditional mixins: {{condition ? trueValue : falseValue}}
|
|
13
|
+
* - Nested metadata access with dot notation
|
|
14
|
+
* - Array access with bracket notation: {{parties[0].name}}
|
|
15
|
+
* - Recursive mixin processing for nested substitutions
|
|
16
|
+
* - Field tracking integration for highlighting and validation
|
|
17
|
+
* - Special value handling (@today, booleans, numbers, strings)
|
|
18
|
+
* - Graceful error handling and fallback behavior
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { processMixins } from './mixin-processor';
|
|
23
|
+
*
|
|
24
|
+
* const content = `
|
|
25
|
+
* This agreement is between {{client.name}} and {{provider.name}}.
|
|
26
|
+
* {{confidentiality ? "This includes confidentiality provisions." : ""}}
|
|
27
|
+
* Total amount: {{formatCurrency(contract.amount, "USD")}}
|
|
28
|
+
* Generated on: {{formatDate(@today, "long")}}
|
|
29
|
+
* `;
|
|
30
|
+
*
|
|
31
|
+
* const metadata = {
|
|
32
|
+
* client: { name: "Acme Corp" },
|
|
33
|
+
* provider: { name: "Service Ltd" },
|
|
34
|
+
* confidentiality: true,
|
|
35
|
+
* contract: { amount: 25000 }
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* const processed = processMixins(content, metadata);
|
|
39
|
+
* console.log(processed);
|
|
40
|
+
* // Output:
|
|
41
|
+
* // This agreement is between Acme Corp and Service Ltd.
|
|
42
|
+
* // This includes confidentiality provisions.
|
|
43
|
+
* // Total amount: $25,000.00
|
|
44
|
+
* // Generated on: January 15, 2024
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
import { LegalMarkdownOptions } from '@types';
|
|
48
|
+
/**
|
|
49
|
+
* Processes mixin references in legal documents
|
|
50
|
+
*
|
|
51
|
+
* This is the main function that processes mixin references using the {{variable}}
|
|
52
|
+
* syntax. It supports variable substitution, helper functions, conditional logic,
|
|
53
|
+
* and integrates with field tracking for document validation and highlighting.
|
|
54
|
+
*
|
|
55
|
+
* @param {string} content - The document content containing mixin references
|
|
56
|
+
* @param {Record<string, any>} metadata - Document metadata with variable values
|
|
57
|
+
* @param {LegalMarkdownOptions} [options={}] - Processing options
|
|
58
|
+
* @returns {string} Processed content with mixins resolved
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* // Basic variable substitution
|
|
62
|
+
* const content1 = "Hello {{user.name}}, welcome to {{company.name}}!";
|
|
63
|
+
* const metadata1 = {
|
|
64
|
+
* user: { name: "John" },
|
|
65
|
+
* company: { name: "Acme Corp" }
|
|
66
|
+
* };
|
|
67
|
+
* const result1 = processMixins(content1, metadata1);
|
|
68
|
+
* // Output: "Hello John, welcome to Acme Corp!"
|
|
69
|
+
*
|
|
70
|
+
* // Helper function usage
|
|
71
|
+
* const content2 = "Today is {{formatDate(@today, 'long')}}";
|
|
72
|
+
* const result2 = processMixins(content2, {});
|
|
73
|
+
* // Output: "Today is January 15, 2024"
|
|
74
|
+
*
|
|
75
|
+
* // Conditional mixins
|
|
76
|
+
* const content3 = "{{premium ? 'Premium features enabled' : 'Standard features'}}";
|
|
77
|
+
* const metadata3 = { premium: true };
|
|
78
|
+
* const result3 = processMixins(content3, metadata3);
|
|
79
|
+
* // Output: "Premium features enabled"
|
|
80
|
+
*
|
|
81
|
+
* // Array access
|
|
82
|
+
* const content4 = "Primary contact: {{contacts[0].name}} ({{contacts[0].email}})";
|
|
83
|
+
* const metadata4 = {
|
|
84
|
+
* contacts: [
|
|
85
|
+
* { name: "Jane Doe", email: "jane@example.com" }
|
|
86
|
+
* ]
|
|
87
|
+
* };
|
|
88
|
+
* const result4 = processMixins(content4, metadata4);
|
|
89
|
+
* // Output: "Primary contact: Jane Doe (jane@example.com)"
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function processMixins(content: string, metadata: Record<string, any>, options?: LegalMarkdownOptions): string;
|
|
93
|
+
//# sourceMappingURL=mixin-processor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixin-processor.d.ts","sourceRoot":"","sources":["../../../src/core/processors/mixin-processor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAmB9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,OAAO,GAAE,oBAAyB,GACjC,MAAM,CA8SR"}
|