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,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Utility Functions for Legal Document Analysis
|
|
4
|
+
*
|
|
5
|
+
* This module provides utility functions for analyzing and extracting information
|
|
6
|
+
* from Legal Markdown documents. These are extensions beyond the core functionality
|
|
7
|
+
* that provide insights into document structure, content, and usage patterns.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Document statistics and analysis
|
|
11
|
+
* - Reference extraction and analysis
|
|
12
|
+
* - Condition extraction from optional clauses
|
|
13
|
+
* - Word count and character count metrics
|
|
14
|
+
* - Header and structure analysis
|
|
15
|
+
* - Import usage tracking
|
|
16
|
+
* - Extensions not present in the original legal-markdown
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { analyzeDocument, extractReferences, extractConditions } from './utilities';
|
|
21
|
+
*
|
|
22
|
+
* // Analyze document statistics
|
|
23
|
+
* const stats = analyzeDocument(content);
|
|
24
|
+
* console.log(`Document contains ${stats.wordCount} words and ${stats.headerCount} headers`);
|
|
25
|
+
*
|
|
26
|
+
* // Extract references
|
|
27
|
+
* const references = extractReferences(content);
|
|
28
|
+
* console.log('References used:', references);
|
|
29
|
+
*
|
|
30
|
+
* // Extract conditions
|
|
31
|
+
* const conditions = extractConditions(content);
|
|
32
|
+
* console.log('Conditions used:', conditions);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.analyzeDocument = analyzeDocument;
|
|
37
|
+
exports.extractReferences = extractReferences;
|
|
38
|
+
exports.extractConditions = extractConditions;
|
|
39
|
+
// Utility functions - Extensions for utility functions beyond core functionality
|
|
40
|
+
/**
|
|
41
|
+
* Analyzes document statistics and structure
|
|
42
|
+
*
|
|
43
|
+
* Provides comprehensive analysis of Legal Markdown document content including
|
|
44
|
+
* word counts, structural elements, and usage patterns. This is an extension
|
|
45
|
+
* not present in the original legal-markdown specification.
|
|
46
|
+
*
|
|
47
|
+
* @function analyzeDocument
|
|
48
|
+
* @param {string} content - The legal document content to analyze
|
|
49
|
+
* @returns {Object} Object containing document statistics
|
|
50
|
+
* @returns {number} returns.wordCount - Total number of words in the document
|
|
51
|
+
* @returns {number} returns.characterCount - Total number of characters in the document
|
|
52
|
+
* @returns {number} returns.headerCount - Number of header structures (l., ll., etc.)
|
|
53
|
+
* @returns {number} returns.optionalClauseCount - Number of optional clauses found
|
|
54
|
+
* @returns {number} returns.crossReferenceCount - Number of cross-references found
|
|
55
|
+
* @returns {number} returns.importCount - Number of import statements found
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { analyzeDocument } from './utilities';
|
|
59
|
+
*
|
|
60
|
+
* const stats = analyzeDocument(documentContent);
|
|
61
|
+
* console.log(`Document Analysis:`);
|
|
62
|
+
* console.log(`- Words: ${stats.wordCount}`);
|
|
63
|
+
* console.log(`- Characters: ${stats.characterCount}`);
|
|
64
|
+
* console.log(`- Headers: ${stats.headerCount}`);
|
|
65
|
+
* console.log(`- Optional Clauses: ${stats.optionalClauseCount}`);
|
|
66
|
+
* console.log(`- Cross References: ${stats.crossReferenceCount}`);
|
|
67
|
+
* console.log(`- Imports: ${stats.importCount}`);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
function analyzeDocument(content) {
|
|
71
|
+
const words = content.split(/\s+/).filter(word => word.length > 0);
|
|
72
|
+
const headers = content.match(/^l+\./gm) || [];
|
|
73
|
+
const optionalClauses = content.match(/\[.*?\]\{.*?\}/g) || [];
|
|
74
|
+
const crossReferences = content.match(/\|.*?\|/g) || [];
|
|
75
|
+
const imports = content.match(/@import\s+/g) || [];
|
|
76
|
+
return {
|
|
77
|
+
wordCount: words.length,
|
|
78
|
+
characterCount: content.length,
|
|
79
|
+
headerCount: headers.length,
|
|
80
|
+
optionalClauseCount: optionalClauses.length,
|
|
81
|
+
crossReferenceCount: crossReferences.length,
|
|
82
|
+
importCount: imports.length,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Extracts all references used in a document
|
|
87
|
+
*
|
|
88
|
+
* Scans the document content for cross-reference patterns and returns a unique
|
|
89
|
+
* list of all references found. Useful for understanding document dependencies
|
|
90
|
+
* and reference usage patterns.
|
|
91
|
+
*
|
|
92
|
+
* @function extractReferences
|
|
93
|
+
* @param {string} content - The legal document content to analyze
|
|
94
|
+
* @returns {string[]} Array of unique reference names found in the document
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* import { extractReferences } from './utilities';
|
|
98
|
+
*
|
|
99
|
+
* const references = extractReferences(documentContent);
|
|
100
|
+
* console.log('References used in document:', references);
|
|
101
|
+
*
|
|
102
|
+
* // Example output: ['section-1', 'definitions', 'termination-clause']
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
function extractReferences(content) {
|
|
106
|
+
const references = content.match(/\|(.*?)\|/g) || [];
|
|
107
|
+
return references
|
|
108
|
+
.map(ref => ref.slice(1, -1))
|
|
109
|
+
.filter((ref, index, arr) => arr.indexOf(ref) === index);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Extracts all conditions used in optional clauses
|
|
113
|
+
*
|
|
114
|
+
* Scans the document content for conditional clause patterns and returns a unique
|
|
115
|
+
* list of all conditions found. Useful for understanding document logic and
|
|
116
|
+
* conditional content usage.
|
|
117
|
+
*
|
|
118
|
+
* @function extractConditions
|
|
119
|
+
* @param {string} content - The legal document content to analyze
|
|
120
|
+
* @returns {string[]} Array of unique condition names found in the document
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* import { extractConditions } from './utilities';
|
|
124
|
+
*
|
|
125
|
+
* const conditions = extractConditions(documentContent);
|
|
126
|
+
* console.log('Conditions used in document:', conditions);
|
|
127
|
+
*
|
|
128
|
+
* // Example output: ['include-warranty', 'corporate-client', 'international-law']
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
function extractConditions(content) {
|
|
132
|
+
const conditions = content.match(/\{(.*?)\}/g) || [];
|
|
133
|
+
return conditions
|
|
134
|
+
.map(cond => cond.slice(1, -1))
|
|
135
|
+
.filter((cond, index, arr) => arr.indexOf(cond) === index);
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/utilities/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;;AAkCH,0CAsBC;AAsBD,8CAKC;AAsBD,8CAKC;AA5GD,iFAAiF;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,SAAgB,eAAe,CAAC,OAAe;IAQ7C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnE,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;IAC/C,MAAM,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;IAC/D,MAAM,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;IACxD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC;IAEnD,OAAO;QACL,SAAS,EAAE,KAAK,CAAC,MAAM;QACvB,cAAc,EAAE,OAAO,CAAC,MAAM;QAC9B,WAAW,EAAE,OAAO,CAAC,MAAM;QAC3B,mBAAmB,EAAE,eAAe,CAAC,MAAM;QAC3C,mBAAmB,EAAE,eAAe,CAAC,MAAM;QAC3C,WAAW,EAAE,OAAO,CAAC,MAAM;KAC5B,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,iBAAiB,CAAC,OAAe;IAC/C,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IACrD,OAAO,UAAU;SACd,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SAC5B,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,CAAC;AAC7D,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,iBAAiB,CAAC,OAAe;IAC/C,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IACrD,OAAO,UAAU;SACd,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;SAC9B,MAAM,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Document Validators for Legal Markdown
|
|
3
|
+
*
|
|
4
|
+
* This module provides validation functions for Legal Markdown documents to ensure
|
|
5
|
+
* proper structure, syntax, and content integrity. These validators are extensions
|
|
6
|
+
* beyond the core functionality that help identify potential issues before processing.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Document structure validation
|
|
10
|
+
* - Syntax checking for brackets and braces
|
|
11
|
+
* - Content integrity verification
|
|
12
|
+
* - Error reporting with detailed messages
|
|
13
|
+
* - Extensions not present in the original legal-markdown
|
|
14
|
+
* - Validation rules for legal document conventions
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { validateDocumentStructure } from './validators';
|
|
19
|
+
*
|
|
20
|
+
* // Validate document structure
|
|
21
|
+
* const validation = validateDocumentStructure(content);
|
|
22
|
+
* if (!validation.isValid) {
|
|
23
|
+
* console.error('Document validation failed:');
|
|
24
|
+
* validation.errors.forEach(error => console.error(`- ${error}`));
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Validates document structure and content integrity
|
|
30
|
+
*
|
|
31
|
+
* Performs comprehensive validation of Legal Markdown document structure including
|
|
32
|
+
* syntax checking, bracket matching, and content integrity verification. This is
|
|
33
|
+
* an extension not present in the original legal-markdown specification.
|
|
34
|
+
*
|
|
35
|
+
* @function validateDocumentStructure
|
|
36
|
+
* @param {string} content - The legal document content to validate
|
|
37
|
+
* @returns {Object} Validation result object
|
|
38
|
+
* @returns {boolean} returns.isValid - Whether the document passes all validation checks
|
|
39
|
+
* @returns {string[]} returns.errors - Array of validation error messages
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { validateDocumentStructure } from './validators';
|
|
43
|
+
*
|
|
44
|
+
* const validation = validateDocumentStructure(documentContent);
|
|
45
|
+
*
|
|
46
|
+
* if (validation.isValid) {
|
|
47
|
+
* console.log('Document structure is valid');
|
|
48
|
+
* } else {
|
|
49
|
+
* console.error('Document validation failed:');
|
|
50
|
+
* validation.errors.forEach(error => {
|
|
51
|
+
* console.error(`- ${error}`);
|
|
52
|
+
* });
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* // Example validation errors:
|
|
56
|
+
* // - Document cannot be empty
|
|
57
|
+
* // - Unmatched optional clause brackets
|
|
58
|
+
* // - Unmatched conditional braces
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function validateDocumentStructure(content: string): {
|
|
62
|
+
isValid: boolean;
|
|
63
|
+
errors: string[];
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/validators/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CA0BjG"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Document Validators for Legal Markdown
|
|
4
|
+
*
|
|
5
|
+
* This module provides validation functions for Legal Markdown documents to ensure
|
|
6
|
+
* proper structure, syntax, and content integrity. These validators are extensions
|
|
7
|
+
* beyond the core functionality that help identify potential issues before processing.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Document structure validation
|
|
11
|
+
* - Syntax checking for brackets and braces
|
|
12
|
+
* - Content integrity verification
|
|
13
|
+
* - Error reporting with detailed messages
|
|
14
|
+
* - Extensions not present in the original legal-markdown
|
|
15
|
+
* - Validation rules for legal document conventions
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { validateDocumentStructure } from './validators';
|
|
20
|
+
*
|
|
21
|
+
* // Validate document structure
|
|
22
|
+
* const validation = validateDocumentStructure(content);
|
|
23
|
+
* if (!validation.isValid) {
|
|
24
|
+
* console.error('Document validation failed:');
|
|
25
|
+
* validation.errors.forEach(error => console.error(`- ${error}`));
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.validateDocumentStructure = validateDocumentStructure;
|
|
31
|
+
// Document validators - Extensions for validation beyond core functionality
|
|
32
|
+
/**
|
|
33
|
+
* Validates document structure and content integrity
|
|
34
|
+
*
|
|
35
|
+
* Performs comprehensive validation of Legal Markdown document structure including
|
|
36
|
+
* syntax checking, bracket matching, and content integrity verification. This is
|
|
37
|
+
* an extension not present in the original legal-markdown specification.
|
|
38
|
+
*
|
|
39
|
+
* @function validateDocumentStructure
|
|
40
|
+
* @param {string} content - The legal document content to validate
|
|
41
|
+
* @returns {Object} Validation result object
|
|
42
|
+
* @returns {boolean} returns.isValid - Whether the document passes all validation checks
|
|
43
|
+
* @returns {string[]} returns.errors - Array of validation error messages
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { validateDocumentStructure } from './validators';
|
|
47
|
+
*
|
|
48
|
+
* const validation = validateDocumentStructure(documentContent);
|
|
49
|
+
*
|
|
50
|
+
* if (validation.isValid) {
|
|
51
|
+
* console.log('Document structure is valid');
|
|
52
|
+
* } else {
|
|
53
|
+
* console.error('Document validation failed:');
|
|
54
|
+
* validation.errors.forEach(error => {
|
|
55
|
+
* console.error(`- ${error}`);
|
|
56
|
+
* });
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* // Example validation errors:
|
|
60
|
+
* // - Document cannot be empty
|
|
61
|
+
* // - Unmatched optional clause brackets
|
|
62
|
+
* // - Unmatched conditional braces
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
function validateDocumentStructure(content) {
|
|
66
|
+
const errors = [];
|
|
67
|
+
// Basic validation rules
|
|
68
|
+
if (!content.trim()) {
|
|
69
|
+
errors.push('Document cannot be empty');
|
|
70
|
+
}
|
|
71
|
+
// Check for unmatched optional clause brackets
|
|
72
|
+
const openBrackets = (content.match(/\[/g) || []).length;
|
|
73
|
+
const closeBrackets = (content.match(/\]/g) || []).length;
|
|
74
|
+
if (openBrackets !== closeBrackets) {
|
|
75
|
+
errors.push('Unmatched optional clause brackets');
|
|
76
|
+
}
|
|
77
|
+
// Check for unmatched conditional braces
|
|
78
|
+
const openBraces = (content.match(/\{/g) || []).length;
|
|
79
|
+
const closeBraces = (content.match(/\}/g) || []).length;
|
|
80
|
+
if (openBraces !== closeBraces) {
|
|
81
|
+
errors.push('Unmatched conditional braces');
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
isValid: errors.length === 0,
|
|
85
|
+
errors,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/validators/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;AAqCH,8DA0BC;AA7DD,4EAA4E;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,SAAgB,yBAAyB,CAAC,OAAe;IACvD,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,yBAAyB;IACzB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;IAC1C,CAAC;IAED,+CAA+C;IAC/C,MAAM,YAAY,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IACzD,MAAM,aAAa,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IAC1D,IAAI,YAAY,KAAK,aAAa,EAAE,CAAC;QACnC,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;IACpD,CAAC;IAED,yCAAyC;IACzC,MAAM,UAAU,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IACvD,MAAM,WAAW,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IACxD,IAAI,UAAU,KAAK,WAAW,EAAE,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IAC9C,CAAC;IAED,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview HTML Generation Module for Legal Markdown Documents
|
|
3
|
+
*
|
|
4
|
+
* This module provides functionality to convert processed Legal Markdown content
|
|
5
|
+
* into well-formatted HTML documents with CSS styling, accessibility features,
|
|
6
|
+
* and print optimization.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Markdown to HTML conversion using marked
|
|
10
|
+
* - DOM manipulation with cheerio for enhanced formatting
|
|
11
|
+
* - Custom CSS injection and styling
|
|
12
|
+
* - Field highlighting for document review
|
|
13
|
+
* - Print-friendly output with page break controls
|
|
14
|
+
* - Responsive table handling
|
|
15
|
+
* - Accessibility improvements
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { htmlGenerator } from './html-generator';
|
|
20
|
+
*
|
|
21
|
+
* const html = await htmlGenerator.generateHtml(markdownContent, {
|
|
22
|
+
* title: 'Legal Agreement',
|
|
23
|
+
* cssPath: './styles.css',
|
|
24
|
+
* includeHighlighting: true
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Configuration options for HTML generation
|
|
30
|
+
*
|
|
31
|
+
* @interface HtmlGeneratorOptions
|
|
32
|
+
*/
|
|
33
|
+
export interface HtmlGeneratorOptions {
|
|
34
|
+
/** Path to custom CSS file to include in the generated HTML */
|
|
35
|
+
cssPath?: string;
|
|
36
|
+
/** Path to highlighting CSS file for field highlighting */
|
|
37
|
+
highlightCssPath?: string;
|
|
38
|
+
/** Whether to include field highlighting styles */
|
|
39
|
+
includeHighlighting?: boolean;
|
|
40
|
+
/** Document title for the HTML page */
|
|
41
|
+
title?: string;
|
|
42
|
+
/** Additional metadata to include in HTML head */
|
|
43
|
+
metadata?: Record<string, string>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* HTML Generator for Legal Markdown Documents
|
|
47
|
+
*
|
|
48
|
+
* Converts processed Legal Markdown content into formatted HTML documents
|
|
49
|
+
* with professional styling, accessibility features, and print optimization.
|
|
50
|
+
*
|
|
51
|
+
* @class HtmlGenerator
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const generator = new HtmlGenerator();
|
|
55
|
+
* const html = await generator.generateHtml(content, {
|
|
56
|
+
* title: 'Contract',
|
|
57
|
+
* includeHighlighting: true
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare class HtmlGenerator {
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new HTML generator instance and configures the markdown parser
|
|
64
|
+
*
|
|
65
|
+
* @constructor
|
|
66
|
+
*/
|
|
67
|
+
constructor();
|
|
68
|
+
/**
|
|
69
|
+
* Configures the marked markdown parser with options optimized for legal documents
|
|
70
|
+
*
|
|
71
|
+
* @private
|
|
72
|
+
* @method configureMarked
|
|
73
|
+
* @returns {void}
|
|
74
|
+
*/
|
|
75
|
+
private configureMarked;
|
|
76
|
+
/**
|
|
77
|
+
* Removes YAML frontmatter from markdown content if present
|
|
78
|
+
*
|
|
79
|
+
* @private
|
|
80
|
+
* @method removeYamlFrontmatter
|
|
81
|
+
* @param {string} content - The markdown content that may contain YAML frontmatter
|
|
82
|
+
* @returns {string} Content with YAML frontmatter removed
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const content = `---
|
|
86
|
+
* title: Document
|
|
87
|
+
* ---
|
|
88
|
+
* # Content`;
|
|
89
|
+
* const clean = this.removeYamlFrontmatter(content); // "# Content"
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
private removeYamlFrontmatter;
|
|
93
|
+
/**
|
|
94
|
+
* Generates a complete HTML document from Legal Markdown content
|
|
95
|
+
*
|
|
96
|
+
* This is the main method that orchestrates the conversion process:
|
|
97
|
+
* 1. Removes YAML frontmatter
|
|
98
|
+
* 2. Converts markdown to HTML using marked
|
|
99
|
+
* 3. Applies DOM transformations for legal document formatting
|
|
100
|
+
* 4. Injects custom CSS and styling
|
|
101
|
+
* 5. Builds a complete HTML document
|
|
102
|
+
*
|
|
103
|
+
* @async
|
|
104
|
+
* @method generateHtml
|
|
105
|
+
* @param {string} markdownContent - The processed Legal Markdown content to convert
|
|
106
|
+
* @param {HtmlGeneratorOptions} [options={}] - Configuration options for HTML generation
|
|
107
|
+
* @returns {Promise<string>} A promise that resolves to the complete HTML document
|
|
108
|
+
* @throws {Error} When HTML generation fails due to parsing or file system errors
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const html = await generator.generateHtml(
|
|
112
|
+
* '# Contract\n\nThis is a {{party.name}} agreement.',
|
|
113
|
+
* {
|
|
114
|
+
* title: 'Service Agreement',
|
|
115
|
+
* cssPath: './contract-styles.css',
|
|
116
|
+
* includeHighlighting: true,
|
|
117
|
+
* metadata: {
|
|
118
|
+
* author: 'Legal Team',
|
|
119
|
+
* version: '1.0'
|
|
120
|
+
* }
|
|
121
|
+
* }
|
|
122
|
+
* );
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
generateHtml(markdownContent: string, options?: HtmlGeneratorOptions): Promise<string>;
|
|
126
|
+
/**
|
|
127
|
+
* Applies DOM transformations to enhance the HTML for legal document presentation
|
|
128
|
+
*
|
|
129
|
+
* Transformations include:
|
|
130
|
+
* - Adding no-break classes to short lists for better print layout
|
|
131
|
+
* - Wrapping tables in responsive containers
|
|
132
|
+
* - Adding alt attributes to images for accessibility
|
|
133
|
+
* - Adding print-friendly CSS classes
|
|
134
|
+
* - Cleaning up paragraph tags in list items
|
|
135
|
+
*
|
|
136
|
+
* @private
|
|
137
|
+
* @method applyDomTransformations
|
|
138
|
+
* @param {cheerio.CheerioAPI} $ - The cheerio instance with loaded HTML
|
|
139
|
+
* @returns {void}
|
|
140
|
+
*/
|
|
141
|
+
private applyDomTransformations;
|
|
142
|
+
/**
|
|
143
|
+
* Loads CSS content from a file path
|
|
144
|
+
*
|
|
145
|
+
* @private
|
|
146
|
+
* @async
|
|
147
|
+
* @method loadCss
|
|
148
|
+
* @param {string} cssPath - Path to the CSS file to load
|
|
149
|
+
* @returns {Promise<string>} A promise that resolves to the CSS content, or empty string on error
|
|
150
|
+
*/
|
|
151
|
+
private loadCss;
|
|
152
|
+
/**
|
|
153
|
+
* Builds a complete HTML document with head, body, and embedded styles
|
|
154
|
+
*
|
|
155
|
+
* Creates a well-formed HTML5 document with:
|
|
156
|
+
* - Proper DOCTYPE and meta tags
|
|
157
|
+
* - Responsive viewport configuration
|
|
158
|
+
* - Embedded CSS styles (base + custom)
|
|
159
|
+
* - SEO-friendly metadata
|
|
160
|
+
* - Print-optimized styling
|
|
161
|
+
*
|
|
162
|
+
* @private
|
|
163
|
+
* @method buildHtmlDocument
|
|
164
|
+
* @param {Object} options - Configuration for building the HTML document
|
|
165
|
+
* @param {string} options.body - The HTML body content
|
|
166
|
+
* @param {string} options.css - Custom CSS to embed
|
|
167
|
+
* @param {string} options.title - Document title
|
|
168
|
+
* @param {Record<string, string>} [options.metadata] - Additional metadata for HTML head
|
|
169
|
+
* @returns {string} Complete HTML document as string
|
|
170
|
+
*/
|
|
171
|
+
private buildHtmlDocument;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Singleton instance of HtmlGenerator for convenient importing
|
|
175
|
+
*
|
|
176
|
+
* @constant {HtmlGenerator} htmlGenerator
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* import { htmlGenerator } from './html-generator';
|
|
180
|
+
* const html = await htmlGenerator.generateHtml(content);
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export declare const htmlGenerator: HtmlGenerator;
|
|
184
|
+
//# sourceMappingURL=html-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-generator.d.ts","sourceRoot":"","sources":["../../src/generators/html-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AASH;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mDAAmD;IACnD,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAa;IACxB;;;;OAIG;;IAKH;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IASvB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,qBAAqB;IA0B7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACG,YAAY,CAAC,eAAe,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC;IAiEhG;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,uBAAuB;IAgC/B;;;;;;;;OAQG;YACW,OAAO;IAWrB;;;;;;;;;;;;;;;;;;OAkBG;YACW,iBAAiB;CAwChC;AAED;;;;;;;;;GASG;AAEH,eAAO,MAAM,aAAa,eAAsB,CAAC"}
|