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,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Utility Library for Legal Markdown Processing
|
|
3
|
+
*
|
|
4
|
+
* This module provides essential utility functions for file operations,
|
|
5
|
+
* path handling, data manipulation, and common programming patterns used
|
|
6
|
+
* throughout the Legal Markdown processing system.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - File system operations with error handling
|
|
10
|
+
* - Path resolution and manipulation utilities
|
|
11
|
+
* - Data transformation and merging functions
|
|
12
|
+
* - Input validation and sanitization
|
|
13
|
+
* - Performance optimization utilities (debounce)
|
|
14
|
+
* - URL validation and file extension handling
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import {
|
|
19
|
+
* readFileSync,
|
|
20
|
+
* writeFileSync,
|
|
21
|
+
* resolveFilePath,
|
|
22
|
+
* deepMerge,
|
|
23
|
+
* sanitizeFileName
|
|
24
|
+
* } from './lib';
|
|
25
|
+
*
|
|
26
|
+
* // Read a file safely
|
|
27
|
+
* const content = readFileSync('./document.md');
|
|
28
|
+
*
|
|
29
|
+
* // Resolve relative paths
|
|
30
|
+
* const fullPath = resolveFilePath('./docs', 'contract.md');
|
|
31
|
+
*
|
|
32
|
+
* // Merge configuration objects
|
|
33
|
+
* const config = deepMerge(defaultConfig, userConfig);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Ensures that a directory exists, creating it recursively if necessary
|
|
38
|
+
*
|
|
39
|
+
* @param {string} dirPath - The directory path to ensure exists
|
|
40
|
+
* @returns {void}
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* ensureDirectoryExists('./output/documents');
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function ensureDirectoryExists(dirPath: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Reads a file synchronously with proper error handling
|
|
49
|
+
*
|
|
50
|
+
* @param {string} filePath - The path to the file to read
|
|
51
|
+
* @returns {string} The file content as UTF-8 string
|
|
52
|
+
* @throws {FileNotFoundError} When the file does not exist
|
|
53
|
+
* @throws {Error} For other file system errors
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const content = readFileSync('./document.md');
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function readFileSync(filePath: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Writes content to a file synchronously, creating directories as needed
|
|
62
|
+
*
|
|
63
|
+
* @param {string} filePath - The path where the file will be written
|
|
64
|
+
* @param {string} content - The content to write to the file
|
|
65
|
+
* @returns {void}
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* writeFileSync('./output/document.md', processedContent);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function writeFileSync(filePath: string, content: string): void;
|
|
72
|
+
/**
|
|
73
|
+
* Resolves a file path relative to a base directory
|
|
74
|
+
*
|
|
75
|
+
* @param {string | undefined} basePath - The base directory path (defaults to cwd)
|
|
76
|
+
* @param {string} filePath - The file path to resolve
|
|
77
|
+
* @returns {string} The resolved absolute path
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const fullPath = resolveFilePath('./docs', 'contract.md');
|
|
81
|
+
* // Returns: '/path/to/docs/contract.md'
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function resolveFilePath(basePath: string | undefined, filePath: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Gets the file extension from a file path in lowercase
|
|
87
|
+
*
|
|
88
|
+
* @param {string} filePath - The file path to extract extension from
|
|
89
|
+
* @returns {string} The file extension in lowercase (including the dot)
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const ext = getFileExtension('document.MD');
|
|
93
|
+
* // Returns: '.md'
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function getFileExtension(filePath: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* Validates if a string is a valid URL
|
|
99
|
+
*
|
|
100
|
+
* @param {string} str - The string to validate
|
|
101
|
+
* @returns {boolean} True if the string is a valid URL, false otherwise
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const isValid = isValidUrl('https://example.com');
|
|
105
|
+
* // Returns: true
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare function isValidUrl(str: string): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Sanitizes a file name by replacing invalid characters with underscores
|
|
111
|
+
*
|
|
112
|
+
* @param {string} fileName - The file name to sanitize
|
|
113
|
+
* @returns {string} The sanitized file name
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const safe = sanitizeFileName('My Document!.pdf');
|
|
117
|
+
* // Returns: 'My_Document_.pdf'
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function sanitizeFileName(fileName: string): string;
|
|
121
|
+
/**
|
|
122
|
+
* Creates a debounced version of a function that delays execution
|
|
123
|
+
*
|
|
124
|
+
* @param {T} func - The function to debounce
|
|
125
|
+
* @param {number} wait - The delay in milliseconds
|
|
126
|
+
* @returns {Function} The debounced function
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const debouncedSave = debounce(saveDocument, 300);
|
|
130
|
+
* debouncedSave(content); // Will only execute after 300ms of inactivity
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function debounce<T extends (...args: any[]) => any>(func: T, wait: number): (...args: Parameters<T>) => void;
|
|
134
|
+
/**
|
|
135
|
+
* Performs a deep merge of objects, combining nested properties
|
|
136
|
+
*
|
|
137
|
+
* @param {T} target - The target object to merge into
|
|
138
|
+
* @param {...Partial<T>} sources - The source objects to merge from
|
|
139
|
+
* @returns {T} The merged object
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const merged = deepMerge(
|
|
143
|
+
* { a: { b: 1 } },
|
|
144
|
+
* { a: { c: 2 } }
|
|
145
|
+
* );
|
|
146
|
+
* // Returns: { a: { b: 1, c: 2 } }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export declare function deepMerge<T extends Record<string, any>>(target: T, ...sources: Partial<T>[]): T;
|
|
150
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAMH;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAI3D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CASrD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAIrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOtF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO/C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,MAAM,GACX,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAMlC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAgB/F"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Utility Library for Legal Markdown Processing
|
|
4
|
+
*
|
|
5
|
+
* This module provides essential utility functions for file operations,
|
|
6
|
+
* path handling, data manipulation, and common programming patterns used
|
|
7
|
+
* throughout the Legal Markdown processing system.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - File system operations with error handling
|
|
11
|
+
* - Path resolution and manipulation utilities
|
|
12
|
+
* - Data transformation and merging functions
|
|
13
|
+
* - Input validation and sanitization
|
|
14
|
+
* - Performance optimization utilities (debounce)
|
|
15
|
+
* - URL validation and file extension handling
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import {
|
|
20
|
+
* readFileSync,
|
|
21
|
+
* writeFileSync,
|
|
22
|
+
* resolveFilePath,
|
|
23
|
+
* deepMerge,
|
|
24
|
+
* sanitizeFileName
|
|
25
|
+
* } from './lib';
|
|
26
|
+
*
|
|
27
|
+
* // Read a file safely
|
|
28
|
+
* const content = readFileSync('./document.md');
|
|
29
|
+
*
|
|
30
|
+
* // Resolve relative paths
|
|
31
|
+
* const fullPath = resolveFilePath('./docs', 'contract.md');
|
|
32
|
+
*
|
|
33
|
+
* // Merge configuration objects
|
|
34
|
+
* const config = deepMerge(defaultConfig, userConfig);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
38
|
+
if (k2 === undefined) k2 = k;
|
|
39
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
40
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
41
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
42
|
+
}
|
|
43
|
+
Object.defineProperty(o, k2, desc);
|
|
44
|
+
}) : (function(o, m, k, k2) {
|
|
45
|
+
if (k2 === undefined) k2 = k;
|
|
46
|
+
o[k2] = m[k];
|
|
47
|
+
}));
|
|
48
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
49
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
50
|
+
}) : function(o, v) {
|
|
51
|
+
o["default"] = v;
|
|
52
|
+
});
|
|
53
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
54
|
+
var ownKeys = function(o) {
|
|
55
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
56
|
+
var ar = [];
|
|
57
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
58
|
+
return ar;
|
|
59
|
+
};
|
|
60
|
+
return ownKeys(o);
|
|
61
|
+
};
|
|
62
|
+
return function (mod) {
|
|
63
|
+
if (mod && mod.__esModule) return mod;
|
|
64
|
+
var result = {};
|
|
65
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
66
|
+
__setModuleDefault(result, mod);
|
|
67
|
+
return result;
|
|
68
|
+
};
|
|
69
|
+
})();
|
|
70
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
71
|
+
exports.ensureDirectoryExists = ensureDirectoryExists;
|
|
72
|
+
exports.readFileSync = readFileSync;
|
|
73
|
+
exports.writeFileSync = writeFileSync;
|
|
74
|
+
exports.resolveFilePath = resolveFilePath;
|
|
75
|
+
exports.getFileExtension = getFileExtension;
|
|
76
|
+
exports.isValidUrl = isValidUrl;
|
|
77
|
+
exports.sanitizeFileName = sanitizeFileName;
|
|
78
|
+
exports.debounce = debounce;
|
|
79
|
+
exports.deepMerge = deepMerge;
|
|
80
|
+
const fs = __importStar(require("fs"));
|
|
81
|
+
const path = __importStar(require("path"));
|
|
82
|
+
const _errors_1 = require("../errors/index.js");
|
|
83
|
+
/**
|
|
84
|
+
* Ensures that a directory exists, creating it recursively if necessary
|
|
85
|
+
*
|
|
86
|
+
* @param {string} dirPath - The directory path to ensure exists
|
|
87
|
+
* @returns {void}
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* ensureDirectoryExists('./output/documents');
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
function ensureDirectoryExists(dirPath) {
|
|
94
|
+
if (!fs.existsSync(dirPath)) {
|
|
95
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Reads a file synchronously with proper error handling
|
|
100
|
+
*
|
|
101
|
+
* @param {string} filePath - The path to the file to read
|
|
102
|
+
* @returns {string} The file content as UTF-8 string
|
|
103
|
+
* @throws {FileNotFoundError} When the file does not exist
|
|
104
|
+
* @throws {Error} For other file system errors
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const content = readFileSync('./document.md');
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
function readFileSync(filePath) {
|
|
111
|
+
try {
|
|
112
|
+
return fs.readFileSync(filePath, 'utf-8');
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
if (error.code === 'ENOENT') {
|
|
116
|
+
throw new _errors_1.FileNotFoundError(filePath);
|
|
117
|
+
}
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Writes content to a file synchronously, creating directories as needed
|
|
123
|
+
*
|
|
124
|
+
* @param {string} filePath - The path where the file will be written
|
|
125
|
+
* @param {string} content - The content to write to the file
|
|
126
|
+
* @returns {void}
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* writeFileSync('./output/document.md', processedContent);
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
function writeFileSync(filePath, content) {
|
|
133
|
+
const dir = path.dirname(filePath);
|
|
134
|
+
ensureDirectoryExists(dir);
|
|
135
|
+
fs.writeFileSync(filePath, content, 'utf-8');
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Resolves a file path relative to a base directory
|
|
139
|
+
*
|
|
140
|
+
* @param {string | undefined} basePath - The base directory path (defaults to cwd)
|
|
141
|
+
* @param {string} filePath - The file path to resolve
|
|
142
|
+
* @returns {string} The resolved absolute path
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const fullPath = resolveFilePath('./docs', 'contract.md');
|
|
146
|
+
* // Returns: '/path/to/docs/contract.md'
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
function resolveFilePath(basePath, filePath) {
|
|
150
|
+
if (path.isAbsolute(filePath)) {
|
|
151
|
+
return filePath;
|
|
152
|
+
}
|
|
153
|
+
const base = basePath || process.cwd();
|
|
154
|
+
return path.resolve(base, filePath);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Gets the file extension from a file path in lowercase
|
|
158
|
+
*
|
|
159
|
+
* @param {string} filePath - The file path to extract extension from
|
|
160
|
+
* @returns {string} The file extension in lowercase (including the dot)
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const ext = getFileExtension('document.MD');
|
|
164
|
+
* // Returns: '.md'
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
function getFileExtension(filePath) {
|
|
168
|
+
return path.extname(filePath).toLowerCase();
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Validates if a string is a valid URL
|
|
172
|
+
*
|
|
173
|
+
* @param {string} str - The string to validate
|
|
174
|
+
* @returns {boolean} True if the string is a valid URL, false otherwise
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const isValid = isValidUrl('https://example.com');
|
|
178
|
+
* // Returns: true
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
function isValidUrl(str) {
|
|
182
|
+
try {
|
|
183
|
+
new URL(str);
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Sanitizes a file name by replacing invalid characters with underscores
|
|
192
|
+
*
|
|
193
|
+
* @param {string} fileName - The file name to sanitize
|
|
194
|
+
* @returns {string} The sanitized file name
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const safe = sanitizeFileName('My Document!.pdf');
|
|
198
|
+
* // Returns: 'My_Document_.pdf'
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
function sanitizeFileName(fileName) {
|
|
202
|
+
return fileName.replace(/[^a-z0-9.-]/gi, '_');
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Creates a debounced version of a function that delays execution
|
|
206
|
+
*
|
|
207
|
+
* @param {T} func - The function to debounce
|
|
208
|
+
* @param {number} wait - The delay in milliseconds
|
|
209
|
+
* @returns {Function} The debounced function
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const debouncedSave = debounce(saveDocument, 300);
|
|
213
|
+
* debouncedSave(content); // Will only execute after 300ms of inactivity
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
function debounce(func, wait) {
|
|
217
|
+
let timeout;
|
|
218
|
+
return (...args) => {
|
|
219
|
+
clearTimeout(timeout);
|
|
220
|
+
timeout = setTimeout(() => func(...args), wait);
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Performs a deep merge of objects, combining nested properties
|
|
225
|
+
*
|
|
226
|
+
* @param {T} target - The target object to merge into
|
|
227
|
+
* @param {...Partial<T>} sources - The source objects to merge from
|
|
228
|
+
* @returns {T} The merged object
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const merged = deepMerge(
|
|
232
|
+
* { a: { b: 1 } },
|
|
233
|
+
* { a: { c: 2 } }
|
|
234
|
+
* );
|
|
235
|
+
* // Returns: { a: { b: 1, c: 2 } }
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
function deepMerge(target, ...sources) {
|
|
239
|
+
if (!sources.length)
|
|
240
|
+
return target;
|
|
241
|
+
const source = sources.shift();
|
|
242
|
+
if (isObject(target) && isObject(source)) {
|
|
243
|
+
for (const key in source) {
|
|
244
|
+
if (isObject(source[key])) {
|
|
245
|
+
if (!target[key])
|
|
246
|
+
Object.assign(target, { [key]: {} });
|
|
247
|
+
deepMerge(target[key], source[key]);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
Object.assign(target, { [key]: source[key] });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return deepMerge(target, ...sources);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Type guard to check if an item is a plain object
|
|
258
|
+
*
|
|
259
|
+
* @param {any} item - The item to check
|
|
260
|
+
* @returns {boolean} True if the item is a plain object, false otherwise
|
|
261
|
+
*/
|
|
262
|
+
function isObject(item) {
|
|
263
|
+
return item && typeof item === 'object' && !Array.isArray(item);
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=index.js.map
|
|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AAC,KAAK,EAAE,CAAC;IAE/B,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACzC,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;YACzB,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;gBAC1B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;oBAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;gBACvD,SAAS,CAAC,MAAM,CAAC,GAAG,CAAwB,EAAE,MAAM,CAAC,GAAG,CAAwB,CAAC,CAAC;YACpF,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;AACvC,CAAC;AAED;;;;;GAKG;AACH,SAAS,QAAQ,CAAC,IAAS;IACzB,OAAO,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Content Detection Module for Legal Markdown Processing
|
|
3
|
+
*
|
|
4
|
+
* This module provides intelligent content type detection for various document
|
|
5
|
+
* formats including reStructuredText (RST) and LaTeX. It uses pattern matching
|
|
6
|
+
* and heuristics to determine if content requires specific parsers for conversion
|
|
7
|
+
* to Legal Markdown format.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - reStructuredText format detection with pattern-based analysis
|
|
11
|
+
* - LaTeX document format detection with command recognition
|
|
12
|
+
* - YAML frontmatter awareness to avoid false positives
|
|
13
|
+
* - Robust pattern matching with configurable thresholds
|
|
14
|
+
* - Support for various RST directives and syntax elements
|
|
15
|
+
* - LaTeX command and environment detection
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { ContentDetector } from './content-detector';
|
|
20
|
+
*
|
|
21
|
+
* // Detect RST content
|
|
22
|
+
* const isRst = ContentDetector.needsRstParser(content);
|
|
23
|
+
* if (isRst) {
|
|
24
|
+
* content = await convertRstToLegalMarkdown(content);
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* // Detect LaTeX content
|
|
28
|
+
* const isLatex = ContentDetector.needsLatexParser(content);
|
|
29
|
+
* if (isLatex) {
|
|
30
|
+
* content = await convertLatexToLegalMarkdown(content);
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
/**
|
|
35
|
+
* Content detection utility class for identifying document formats
|
|
36
|
+
*
|
|
37
|
+
* Provides static methods to detect different document formats using pattern
|
|
38
|
+
* matching and content analysis. Designed to prevent unnecessary processing
|
|
39
|
+
* of content that doesn't require specific parsers.
|
|
40
|
+
*
|
|
41
|
+
* @class ContentDetector
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* import { ContentDetector } from './content-detector';
|
|
45
|
+
*
|
|
46
|
+
* // Check if content needs RST processing
|
|
47
|
+
* if (ContentDetector.needsRstParser(content)) {
|
|
48
|
+
* content = await processRstContent(content);
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* // Check if content needs LaTeX processing
|
|
52
|
+
* if (ContentDetector.needsLatexParser(content)) {
|
|
53
|
+
* content = await processLatexContent(content);
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare class ContentDetector {
|
|
58
|
+
/**
|
|
59
|
+
* Detects if content requires reStructuredText parsing
|
|
60
|
+
*
|
|
61
|
+
* Uses pattern matching to identify RST-specific syntax elements including
|
|
62
|
+
* directives, header underlines, reference links, code blocks, and other
|
|
63
|
+
* RST constructs. Avoids false positives with YAML frontmatter content.
|
|
64
|
+
*
|
|
65
|
+
* @static
|
|
66
|
+
* @param {string} content - The content to analyze for RST patterns
|
|
67
|
+
* @returns {boolean} True if content appears to be reStructuredText, false otherwise
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const rstContent = `
|
|
71
|
+
* Introduction
|
|
72
|
+
* ============
|
|
73
|
+
*
|
|
74
|
+
* This is a sample RST document.
|
|
75
|
+
*
|
|
76
|
+
* .. note::
|
|
77
|
+
* This is an RST directive.
|
|
78
|
+
* `;
|
|
79
|
+
*
|
|
80
|
+
* const isRst = ContentDetector.needsRstParser(rstContent);
|
|
81
|
+
* console.log(isRst); // true
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
static needsRstParser(content: string): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Detects if content requires LaTeX parsing
|
|
87
|
+
*
|
|
88
|
+
* Uses pattern matching to identify LaTeX-specific commands, environments,
|
|
89
|
+
* and syntax elements including document classes, sections, text formatting
|
|
90
|
+
* commands, and environments. Requires multiple pattern matches to avoid
|
|
91
|
+
* false positives.
|
|
92
|
+
*
|
|
93
|
+
* @static
|
|
94
|
+
* @param {string} content - The content to analyze for LaTeX patterns
|
|
95
|
+
* @returns {boolean} True if content appears to be LaTeX, false otherwise
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const latexContent = `
|
|
99
|
+
* \\documentclass{article}
|
|
100
|
+
* \\begin{document}
|
|
101
|
+
* \\section{Introduction}
|
|
102
|
+
* This is \\textbf{bold} text in LaTeX.
|
|
103
|
+
* \\end{document}
|
|
104
|
+
* `;
|
|
105
|
+
*
|
|
106
|
+
* const isLatex = ContentDetector.needsLatexParser(latexContent);
|
|
107
|
+
* console.log(isLatex); // true
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
static needsLatexParser(content: string): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Detects if content requires Pandoc processing
|
|
113
|
+
*
|
|
114
|
+
* This is a convenience method that combines RST and LaTeX detection to
|
|
115
|
+
* determine if content needs any form of Pandoc processing for conversion
|
|
116
|
+
* to Legal Markdown format.
|
|
117
|
+
*
|
|
118
|
+
* @static
|
|
119
|
+
* @param {string} content - The content to analyze for format patterns
|
|
120
|
+
* @returns {boolean} True if content needs Pandoc processing, false otherwise
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const needsProcessing = ContentDetector.needsPandoc(content);
|
|
124
|
+
* if (needsProcessing) {
|
|
125
|
+
* content = await processThroughPandoc(content);
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
static needsPandoc(content: string): boolean;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=content-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-detector.d.ts","sourceRoot":"","sources":["../../src/parsers/content-detector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,eAAe;IAC1B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IA6C/C;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAoDjD;;;;;;;;;;;;;;;;;OAiBG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;CAG7C"}
|