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,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Metadata Export System for Legal Markdown Documents
|
|
4
|
+
*
|
|
5
|
+
* This module provides functionality for exporting document metadata to external
|
|
6
|
+
* files in various formats. It supports YAML and JSON export formats with
|
|
7
|
+
* configurable output paths and metadata filtering.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Metadata export to YAML and JSON formats
|
|
11
|
+
* - Configurable output paths and filenames
|
|
12
|
+
* - Metadata filtering and processing
|
|
13
|
+
* - Internal metadata key removal
|
|
14
|
+
* - Directory creation for output files
|
|
15
|
+
* - Error handling and logging
|
|
16
|
+
* - Support for custom export configurations
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { exportMetadata } from './metadata-exporter';
|
|
21
|
+
*
|
|
22
|
+
* // Export metadata to YAML
|
|
23
|
+
* const result = exportMetadata(metadata, 'yaml', './output');
|
|
24
|
+
* console.log('Exported files:', result.exportedFiles);
|
|
25
|
+
*
|
|
26
|
+
* // Export with custom configuration
|
|
27
|
+
* const metadata = {
|
|
28
|
+
* title: 'Legal Agreement',
|
|
29
|
+
* 'meta-yaml-output': 'custom-metadata.yaml',
|
|
30
|
+
* 'meta-json-output': 'custom-metadata.json'
|
|
31
|
+
* };
|
|
32
|
+
* const result = exportMetadata(metadata);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
36
|
+
if (k2 === undefined) k2 = k;
|
|
37
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
38
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
39
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
40
|
+
}
|
|
41
|
+
Object.defineProperty(o, k2, desc);
|
|
42
|
+
}) : (function(o, m, k, k2) {
|
|
43
|
+
if (k2 === undefined) k2 = k;
|
|
44
|
+
o[k2] = m[k];
|
|
45
|
+
}));
|
|
46
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
47
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
48
|
+
}) : function(o, v) {
|
|
49
|
+
o["default"] = v;
|
|
50
|
+
});
|
|
51
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
52
|
+
var ownKeys = function(o) {
|
|
53
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
54
|
+
var ar = [];
|
|
55
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
56
|
+
return ar;
|
|
57
|
+
};
|
|
58
|
+
return ownKeys(o);
|
|
59
|
+
};
|
|
60
|
+
return function (mod) {
|
|
61
|
+
if (mod && mod.__esModule) return mod;
|
|
62
|
+
var result = {};
|
|
63
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
64
|
+
__setModuleDefault(result, mod);
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
67
|
+
})();
|
|
68
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
69
|
+
exports.exportMetadata = exportMetadata;
|
|
70
|
+
exports.filterMetadataForExport = filterMetadataForExport;
|
|
71
|
+
const fs = __importStar(require("fs"));
|
|
72
|
+
const path = __importStar(require("path"));
|
|
73
|
+
const yaml = __importStar(require("js-yaml"));
|
|
74
|
+
/**
|
|
75
|
+
* Exports document metadata to external files
|
|
76
|
+
*
|
|
77
|
+
* Processes document metadata and exports it to specified formats (YAML/JSON)
|
|
78
|
+
* with support for custom output paths and metadata filtering. Handles directory
|
|
79
|
+
* creation and provides comprehensive error handling.
|
|
80
|
+
*
|
|
81
|
+
* @async
|
|
82
|
+
* @function exportMetadata
|
|
83
|
+
* @param {Record<string, any>} metadata - Document metadata to export
|
|
84
|
+
* @param {'yaml' | 'json'} [format] - Export format (yaml or json)
|
|
85
|
+
* @param {string} [outputPath] - Optional path for export files
|
|
86
|
+
* @returns {MetadataExportResult} Result object with list of exported files
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import { exportMetadata } from './metadata-exporter';
|
|
90
|
+
*
|
|
91
|
+
* // Basic metadata export
|
|
92
|
+
* const metadata = {
|
|
93
|
+
* title: 'Service Agreement',
|
|
94
|
+
* author: 'Legal Team',
|
|
95
|
+
* version: '1.0',
|
|
96
|
+
* date: '2023-01-01'
|
|
97
|
+
* };
|
|
98
|
+
*
|
|
99
|
+
* const result = exportMetadata(metadata, 'yaml', './output');
|
|
100
|
+
* console.log('Exported to:', result.exportedFiles);
|
|
101
|
+
*
|
|
102
|
+
* // Export with custom filenames
|
|
103
|
+
* const customMetadata = {
|
|
104
|
+
* title: 'Contract',
|
|
105
|
+
* 'meta-yaml-output': 'contract-metadata.yaml',
|
|
106
|
+
* 'meta-json-output': 'contract-metadata.json',
|
|
107
|
+
* 'meta-output-path': './custom-output'
|
|
108
|
+
* };
|
|
109
|
+
*
|
|
110
|
+
* const customResult = exportMetadata(customMetadata);
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
function exportMetadata(metadata, format, outputPath) {
|
|
114
|
+
const exportedFiles = [];
|
|
115
|
+
// Extract export configuration from metadata
|
|
116
|
+
const yamlOutput = metadata['meta-yaml-output'];
|
|
117
|
+
const jsonOutput = metadata['meta-json-output'];
|
|
118
|
+
const customOutputPath = metadata['meta-output-path'];
|
|
119
|
+
// Determine output directory (customOutputPath from metadata takes precedence)
|
|
120
|
+
const outputDir = customOutputPath || outputPath || process.cwd();
|
|
121
|
+
// Create output directory if it doesn't exist
|
|
122
|
+
if (!fs.existsSync(outputDir)) {
|
|
123
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
124
|
+
}
|
|
125
|
+
// Process metadata for export (remove internal keys)
|
|
126
|
+
const exportedMetadata = filterMetadataForExport(metadata);
|
|
127
|
+
// Process YAML output if specified
|
|
128
|
+
if (yamlOutput || format === 'yaml') {
|
|
129
|
+
const yamlPath = yamlOutput
|
|
130
|
+
? path.resolve(outputDir, yamlOutput)
|
|
131
|
+
: path.resolve(outputDir, 'metadata.yaml');
|
|
132
|
+
try {
|
|
133
|
+
const yamlContent = yaml.dump(exportedMetadata);
|
|
134
|
+
fs.writeFileSync(yamlPath, yamlContent, 'utf8');
|
|
135
|
+
exportedFiles.push(yamlPath);
|
|
136
|
+
console.log(`Exported YAML metadata to: ${yamlPath}`);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
console.error('Error exporting YAML metadata:', error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Process JSON output if specified
|
|
143
|
+
if (jsonOutput || format === 'json') {
|
|
144
|
+
const jsonPath = jsonOutput
|
|
145
|
+
? path.resolve(outputDir, jsonOutput)
|
|
146
|
+
: path.resolve(outputDir, 'metadata.json');
|
|
147
|
+
try {
|
|
148
|
+
const jsonContent = JSON.stringify(exportedMetadata, null, 2);
|
|
149
|
+
fs.writeFileSync(jsonPath, jsonContent, 'utf8');
|
|
150
|
+
exportedFiles.push(jsonPath);
|
|
151
|
+
console.log(`Exported JSON metadata to: ${jsonPath}`);
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
console.error('Error exporting JSON metadata:', error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return { exportedFiles };
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Filters metadata based on export configuration
|
|
161
|
+
*
|
|
162
|
+
* Processes metadata to remove internal configuration keys and applies filtering
|
|
163
|
+
* rules based on export settings. This ensures that only relevant metadata is
|
|
164
|
+
* included in the exported files.
|
|
165
|
+
*
|
|
166
|
+
* @function filterMetadataForExport
|
|
167
|
+
* @param {Record<string, any>} metadata - Complete metadata object to filter
|
|
168
|
+
* @returns {Record<string, any>} Filtered metadata object suitable for export
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* import { filterMetadataForExport } from './metadata-exporter';
|
|
172
|
+
*
|
|
173
|
+
* const metadata = {
|
|
174
|
+
* title: 'Legal Agreement',
|
|
175
|
+
* author: 'Legal Team',
|
|
176
|
+
* 'meta-yaml-output': 'output.yaml',
|
|
177
|
+
* 'meta-json-output': 'output.json',
|
|
178
|
+
* 'meta-output-path': './exports',
|
|
179
|
+
* 'meta-include-original': false
|
|
180
|
+
* };
|
|
181
|
+
*
|
|
182
|
+
* const filtered = filterMetadataForExport(metadata);
|
|
183
|
+
* // Result: { title: 'Legal Agreement', author: 'Legal Team' }
|
|
184
|
+
* // Internal meta-* keys are removed
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
function filterMetadataForExport(metadata) {
|
|
188
|
+
// Deep clone the metadata to avoid modifying original
|
|
189
|
+
const result = JSON.parse(JSON.stringify(metadata));
|
|
190
|
+
// Remove internal export configuration keys
|
|
191
|
+
delete result['meta-yaml-output'];
|
|
192
|
+
delete result['meta-json-output'];
|
|
193
|
+
delete result['meta-output-path'];
|
|
194
|
+
delete result['meta-include-original'];
|
|
195
|
+
// Check if we should include only keys under 'meta'
|
|
196
|
+
if (metadata['meta-include-original'] === false && metadata['meta']) {
|
|
197
|
+
return { meta: result.meta };
|
|
198
|
+
}
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
//# sourceMappingURL=metadata-exporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata-exporter.js","sourceRo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EpD,4CAA4C;IAC5C,OAAO,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAClC,OAAO,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAClC,OAAO,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAClC,OAAO,MAAM,CAAC,uBAAuB,CAAC,CAAC;IAEvC,oDAAoD;IACpD,IAAI,QAAQ,CAAC,uBAAuB,CAAC,KAAK,KAAK,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACpE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Core Legal Markdown Processing Module
|
|
3
|
+
*
|
|
4
|
+
* This module provides the core functionality for Legal Markdown processing,
|
|
5
|
+
* maintaining parity with the original legal-markdown implementation. It exports
|
|
6
|
+
* all essential parsers, processors, and exporters needed for document processing.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - YAML front matter parsing
|
|
10
|
+
* - Header processing and numbering
|
|
11
|
+
* - Optional clause conditional processing
|
|
12
|
+
* - Cross-reference resolution
|
|
13
|
+
* - Import processing for partial documents
|
|
14
|
+
* - Mixin system for reusable content
|
|
15
|
+
* - Date processing utilities
|
|
16
|
+
* - Metadata export capabilities
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import {
|
|
21
|
+
* parseYamlFrontMatter,
|
|
22
|
+
* processHeaders,
|
|
23
|
+
* processOptionalClauses,
|
|
24
|
+
* processCrossReferences
|
|
25
|
+
* } from './core';
|
|
26
|
+
*
|
|
27
|
+
* // Use core processors in a custom pipeline
|
|
28
|
+
* const { content, metadata } = parseYamlFrontMatter(rawContent);
|
|
29
|
+
* const processed = processHeaders(content, metadata);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export * from './parsers/yaml-parser';
|
|
33
|
+
export * from './processors/header-processor';
|
|
34
|
+
export * from './processors/clause-processor';
|
|
35
|
+
export * from './processors/reference-processor';
|
|
36
|
+
export * from './processors/import-processor';
|
|
37
|
+
export * from './processors/mixin-processor';
|
|
38
|
+
export * from './processors/date-processor';
|
|
39
|
+
export * from './exporters/metadata-exporter';
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,kCAAkC,CAAC;AACjD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Core Legal Markdown Processing Module
|
|
4
|
+
*
|
|
5
|
+
* This module provides the core functionality for Legal Markdown processing,
|
|
6
|
+
* maintaining parity with the original legal-markdown implementation. It exports
|
|
7
|
+
* all essential parsers, processors, and exporters needed for document processing.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - YAML front matter parsing
|
|
11
|
+
* - Header processing and numbering
|
|
12
|
+
* - Optional clause conditional processing
|
|
13
|
+
* - Cross-reference resolution
|
|
14
|
+
* - Import processing for partial documents
|
|
15
|
+
* - Mixin system for reusable content
|
|
16
|
+
* - Date processing utilities
|
|
17
|
+
* - Metadata export capabilities
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import {
|
|
22
|
+
* parseYamlFrontMatter,
|
|
23
|
+
* processHeaders,
|
|
24
|
+
* processOptionalClauses,
|
|
25
|
+
* processCrossReferences
|
|
26
|
+
* } from './core';
|
|
27
|
+
*
|
|
28
|
+
* // Use core processors in a custom pipeline
|
|
29
|
+
* const { content, metadata } = parseYamlFrontMatter(rawContent);
|
|
30
|
+
* const processed = processHeaders(content, metadata);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
34
|
+
if (k2 === undefined) k2 = k;
|
|
35
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
36
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
37
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
38
|
+
}
|
|
39
|
+
Object.defineProperty(o, k2, desc);
|
|
40
|
+
}) : (function(o, m, k, k2) {
|
|
41
|
+
if (k2 === undefined) k2 = k;
|
|
42
|
+
o[k2] = m[k];
|
|
43
|
+
}));
|
|
44
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
45
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
__exportStar(require("./parsers/yaml-parser"), exports);
|
|
49
|
+
__exportStar(require("./processors/header-processor"), exports);
|
|
50
|
+
__exportStar(require("./processors/clause-processor"), exports);
|
|
51
|
+
__exportStar(require("./processors/reference-processor"), exports);
|
|
52
|
+
__exportStar(require("./processors/import-processor"), exports);
|
|
53
|
+
__exportStar(require("./processors/mixin-processor"), exports);
|
|
54
|
+
__exportStar(require("./processors/date-processor"), exports);
|
|
55
|
+
__exportStar(require("./exporters/metadata-exporter"), exports);
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;;;;;;;;;;;;;;;;AAEH,wDAAsC;AACtC,gEAA8C;AAC9C,gEAA8C;AAC9C,mEAAiD;AACjD,gEAA8C;AAC9C,+DAA6C;AAC7C,8DAA4C;AAC5C,gEAA8C"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview YAML Front Matter Parser for Legal Markdown Documents
|
|
3
|
+
*
|
|
4
|
+
* This module provides functionality to parse YAML front matter from Legal Markdown
|
|
5
|
+
* documents, extracting metadata and configuration options for document processing.
|
|
6
|
+
* It handles both valid and invalid YAML gracefully, with options for strict error
|
|
7
|
+
* handling when needed.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - YAML front matter parsing with js-yaml library
|
|
11
|
+
* - Graceful error handling for malformed YAML
|
|
12
|
+
* - Metadata extraction and validation
|
|
13
|
+
* - Content separation from front matter
|
|
14
|
+
* - YAML serialization utilities
|
|
15
|
+
* - Metadata output configuration extraction
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { parseYamlFrontMatter } from './yaml-parser';
|
|
20
|
+
*
|
|
21
|
+
* const content = `---
|
|
22
|
+
* title: Legal Agreement
|
|
23
|
+
* date: 2024-01-01
|
|
24
|
+
* parties:
|
|
25
|
+
* - name: Company A
|
|
26
|
+
* role: Provider
|
|
27
|
+
* ---
|
|
28
|
+
* # Agreement Content
|
|
29
|
+
* This is the document content.`;
|
|
30
|
+
*
|
|
31
|
+
* const result = parseYamlFrontMatter(content);
|
|
32
|
+
* console.log(result.metadata.title); // "Legal Agreement"
|
|
33
|
+
* console.log(result.content); // "# Agreement Content\nThis is the document content."
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
import { YamlParsingResult } from '@types';
|
|
37
|
+
/**
|
|
38
|
+
* Parses YAML Front Matter from a markdown document
|
|
39
|
+
*
|
|
40
|
+
* Extracts and parses YAML metadata from the beginning of a document,
|
|
41
|
+
* separated by triple dashes (---). The parser handles malformed YAML
|
|
42
|
+
* gracefully unless strict error handling is enabled.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} content - The content of the document to parse
|
|
45
|
+
* @param {boolean} [throwOnError=false] - Whether to throw errors on invalid YAML
|
|
46
|
+
* @returns {YamlParsingResult} Object containing the content without YAML and the parsed metadata
|
|
47
|
+
* @throws {Error} When throwOnError is true and YAML parsing fails
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Basic usage with valid YAML
|
|
51
|
+
* const content = `---
|
|
52
|
+
* title: Contract
|
|
53
|
+
* version: 1.0
|
|
54
|
+
* ---
|
|
55
|
+
* # Contract Content`;
|
|
56
|
+
*
|
|
57
|
+
* const result = parseYamlFrontMatter(content);
|
|
58
|
+
* // result.metadata = { title: "Contract", version: 1.0 }
|
|
59
|
+
* // result.content = "# Contract Content"
|
|
60
|
+
*
|
|
61
|
+
* // Usage with error handling
|
|
62
|
+
* const malformedContent = `---
|
|
63
|
+
* title: Contract
|
|
64
|
+
* invalid: yaml: content
|
|
65
|
+
* ---
|
|
66
|
+
* # Content`;
|
|
67
|
+
*
|
|
68
|
+
* const safeResult = parseYamlFrontMatter(malformedContent, false);
|
|
69
|
+
* // Returns original content with empty metadata
|
|
70
|
+
*
|
|
71
|
+
* const strictResult = parseYamlFrontMatter(malformedContent, true);
|
|
72
|
+
* // Throws Error: "Invalid YAML Front Matter: ..."
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function parseYamlFrontMatter(content: string, throwOnError?: boolean): YamlParsingResult;
|
|
76
|
+
/**
|
|
77
|
+
* Serializes metadata to YAML format
|
|
78
|
+
*
|
|
79
|
+
* Converts a JavaScript object to YAML string format using js-yaml library.
|
|
80
|
+
* Handles serialization errors gracefully by returning an empty string and
|
|
81
|
+
* logging the error to the console.
|
|
82
|
+
*
|
|
83
|
+
* @param {Record<string, any>} metadata - The metadata object to serialize
|
|
84
|
+
* @returns {string} YAML string representation of the metadata
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const metadata = {
|
|
88
|
+
* title: "Legal Agreement",
|
|
89
|
+
* date: "2024-01-01",
|
|
90
|
+
* parties: [
|
|
91
|
+
* { name: "Company A", role: "Provider" },
|
|
92
|
+
* { name: "Company B", role: "Client" }
|
|
93
|
+
* ]
|
|
94
|
+
* };
|
|
95
|
+
*
|
|
96
|
+
* const yamlString = serializeToYaml(metadata);
|
|
97
|
+
* console.log(yamlString);
|
|
98
|
+
* // Output:
|
|
99
|
+
* // title: Legal Agreement
|
|
100
|
+
* // date: '2024-01-01'
|
|
101
|
+
* // parties:
|
|
102
|
+
* // - name: Company A
|
|
103
|
+
* // role: Provider
|
|
104
|
+
* // - name: Company B
|
|
105
|
+
* // role: Client
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare function serializeToYaml(metadata: Record<string, any>): string;
|
|
109
|
+
/**
|
|
110
|
+
* Extracts specific metadata output configuration
|
|
111
|
+
*
|
|
112
|
+
* Parses document metadata to extract configuration options for metadata output,
|
|
113
|
+
* including file paths, formats, and inclusion settings. This function looks for
|
|
114
|
+
* specially named metadata fields that control how processed metadata is exported.
|
|
115
|
+
*
|
|
116
|
+
* @param {Record<string, any>} metadata - The document metadata to extract configuration from
|
|
117
|
+
* @returns {Object} Configuration object for metadata output
|
|
118
|
+
* @returns {string} [returns.yamlOutput] - Path for YAML metadata output file
|
|
119
|
+
* @returns {string} [returns.jsonOutput] - Path for JSON metadata output file
|
|
120
|
+
* @returns {string} [returns.outputPath] - General output path for metadata files
|
|
121
|
+
* @returns {boolean} [returns.includeOriginal] - Whether to include original metadata in output
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const metadata = {
|
|
125
|
+
* title: "Contract",
|
|
126
|
+
* "meta-yaml-output": "contract-metadata.yml",
|
|
127
|
+
* "meta-json-output": "contract-metadata.json",
|
|
128
|
+
* "meta-output-path": "./output/",
|
|
129
|
+
* "meta-include-original": true
|
|
130
|
+
* };
|
|
131
|
+
*
|
|
132
|
+
* const config = extractMetadataOutputConfig(metadata);
|
|
133
|
+
* console.log(config);
|
|
134
|
+
* // Output:
|
|
135
|
+
* // {
|
|
136
|
+
* // yamlOutput: "contract-metadata.yml",
|
|
137
|
+
* // jsonOutput: "contract-metadata.json",
|
|
138
|
+
* // outputPath: "./output/",
|
|
139
|
+
* // includeOriginal: true
|
|
140
|
+
* // }
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare function extractMetadataOutputConfig(metadata: Record<string, any>): {
|
|
144
|
+
yamlOutput?: string;
|
|
145
|
+
jsonOutput?: string;
|
|
146
|
+
outputPath?: string;
|
|
147
|
+
includeOriginal?: boolean;
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=yaml-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml-parser.d.ts","sourceRoot":"","sources":["../../../src/core/parsers/yaml-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,YAAY,GAAE,OAAe,GAC5B,iBAAiB,CAqDnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAOrE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAOA"}
|