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
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Main Entry Point for Legal Markdown Processing Library
|
|
3
|
+
*
|
|
4
|
+
* This module provides the primary API for processing Legal Markdown documents
|
|
5
|
+
* with support for YAML front matter, cross-references, optional clauses, mixins,
|
|
6
|
+
* header processing, and multi-format output generation (HTML, PDF).
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - YAML front matter parsing and metadata extraction
|
|
10
|
+
* - Cross-reference processing and resolution
|
|
11
|
+
* - Optional clause conditional rendering
|
|
12
|
+
* - Mixin system for reusable content blocks
|
|
13
|
+
* - Header numbering and formatting
|
|
14
|
+
* - Field tracking for document highlighting
|
|
15
|
+
* - HTML and PDF generation with styling
|
|
16
|
+
* - RST and LaTeX preprocessing support
|
|
17
|
+
* - Metadata export capabilities
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { processLegalMarkdown, generateHtml, generatePdf } from 'legal-markdown-js';
|
|
22
|
+
*
|
|
23
|
+
* // Basic document processing
|
|
24
|
+
* const result = processLegalMarkdown(content, {
|
|
25
|
+
* enableFieldTracking: true,
|
|
26
|
+
* basePath: './documents'
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Generate HTML output
|
|
30
|
+
* const html = await generateHtml(content, {
|
|
31
|
+
* title: 'Legal Agreement',
|
|
32
|
+
* includeHighlighting: true
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // Generate PDF output
|
|
36
|
+
* const pdf = await generatePdf(content, './output.pdf', {
|
|
37
|
+
* format: 'A4',
|
|
38
|
+
* includeHighlighting: true
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
import { fieldTracker } from './tracking/field-tracker';
|
|
43
|
+
import { LegalMarkdownOptions } from '@types';
|
|
44
|
+
/**
|
|
45
|
+
* Main function to process a Legal Markdown document (async version)
|
|
46
|
+
*
|
|
47
|
+
* This function orchestrates the complete processing pipeline for Legal Markdown
|
|
48
|
+
* documents, including YAML parsing, content preprocessing, clause processing,
|
|
49
|
+
* cross-reference resolution, mixin expansion, header formatting, and metadata export.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} content - The raw Legal Markdown content to process
|
|
52
|
+
* @param {LegalMarkdownOptions} [options={}] - Configuration options for processing
|
|
53
|
+
* @returns {Promise<Object>} Processing result containing processed content, metadata, and reports
|
|
54
|
+
* @returns {string} returns.content - The processed document content
|
|
55
|
+
* @returns {Record<string, any>} [returns.metadata] - Extracted YAML metadata
|
|
56
|
+
* @returns {string[]} [returns.exportedFiles] - Array of exported metadata files
|
|
57
|
+
* @returns {Object} [returns.fieldReport] - Field tracking report if enabled
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const result = await processLegalMarkdownAsync(content, {
|
|
61
|
+
* enableFieldTracking: true,
|
|
62
|
+
* basePath: './documents',
|
|
63
|
+
* noClauses: false,
|
|
64
|
+
* noReferences: false
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* console.log(result.content); // Processed markdown
|
|
68
|
+
* console.log(result.metadata); // YAML front matter
|
|
69
|
+
* console.log(result.fieldReport); // Field usage report
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function processLegalMarkdownAsync(content: string, options?: LegalMarkdownOptions): Promise<{
|
|
73
|
+
content: string;
|
|
74
|
+
metadata?: Record<string, any>;
|
|
75
|
+
exportedFiles?: string[];
|
|
76
|
+
fieldReport?: ReturnType<typeof fieldTracker.generateReport>;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Main function to process a Legal Markdown document (sync version with fallback)
|
|
80
|
+
*
|
|
81
|
+
* This function uses fallback parsers for RST/LaTeX to maintain backward compatibility
|
|
82
|
+
* and ensure the library works without pandoc dependencies.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} content - The raw Legal Markdown content to process
|
|
85
|
+
* @param {LegalMarkdownOptions} [options={}] - Configuration options for processing
|
|
86
|
+
* @returns {Object} Processing result containing processed content, metadata, and reports
|
|
87
|
+
* @returns {string} returns.content - The processed document content
|
|
88
|
+
* @returns {Record<string, any>} [returns.metadata] - Extracted YAML metadata
|
|
89
|
+
* @returns {string[]} [returns.exportedFiles] - Array of exported metadata files
|
|
90
|
+
* @returns {Object} [returns.fieldReport] - Field tracking report if enabled
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const result = processLegalMarkdown(content, {
|
|
94
|
+
* enableFieldTracking: true,
|
|
95
|
+
* basePath: './documents',
|
|
96
|
+
* noClauses: false,
|
|
97
|
+
* noReferences: false
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* console.log(result.content); // Processed markdown
|
|
101
|
+
* console.log(result.metadata); // YAML front matter
|
|
102
|
+
* console.log(result.fieldReport); // Field usage report
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function processLegalMarkdown(content: string, options?: LegalMarkdownOptions): {
|
|
106
|
+
content: string;
|
|
107
|
+
metadata?: Record<string, any>;
|
|
108
|
+
exportedFiles?: string[];
|
|
109
|
+
fieldReport?: ReturnType<typeof fieldTracker.generateReport>;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Generate HTML from Legal Markdown content
|
|
113
|
+
*
|
|
114
|
+
* This function processes Legal Markdown content and generates a complete HTML
|
|
115
|
+
* document with styling, field highlighting, and responsive design features.
|
|
116
|
+
* It combines the Legal Markdown processing pipeline with HTML generation.
|
|
117
|
+
*
|
|
118
|
+
* @async
|
|
119
|
+
* @param {string} content - The raw Legal Markdown content to convert
|
|
120
|
+
* @param {LegalMarkdownOptions & Object} [options={}] - Configuration options
|
|
121
|
+
* @param {string} [options.cssPath] - Path to custom CSS file
|
|
122
|
+
* @param {string} [options.highlightCssPath] - Path to field highlighting CSS
|
|
123
|
+
* @param {boolean} [options.includeHighlighting] - Whether to include field highlighting
|
|
124
|
+
* @param {string} [options.title] - Document title for HTML
|
|
125
|
+
* @returns {Promise<string>} A promise that resolves to the complete HTML document
|
|
126
|
+
* @throws {Error} When HTML generation fails
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const html = await generateHtml(content, {
|
|
130
|
+
* title: 'Service Agreement',
|
|
131
|
+
* cssPath: './custom-styles.css',
|
|
132
|
+
* includeHighlighting: true,
|
|
133
|
+
* enableFieldTracking: true
|
|
134
|
+
* });
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare function generateHtml(content: string, options?: LegalMarkdownOptions & {
|
|
138
|
+
cssPath?: string;
|
|
139
|
+
highlightCssPath?: string;
|
|
140
|
+
includeHighlighting?: boolean;
|
|
141
|
+
title?: string;
|
|
142
|
+
}): Promise<string>;
|
|
143
|
+
/**
|
|
144
|
+
* Generate PDF from Legal Markdown content
|
|
145
|
+
*
|
|
146
|
+
* This function processes Legal Markdown content and generates a PDF document
|
|
147
|
+
* with professional styling, field highlighting, and customizable page formatting.
|
|
148
|
+
* It combines the Legal Markdown processing pipeline with PDF generation.
|
|
149
|
+
*
|
|
150
|
+
* @async
|
|
151
|
+
* @param {string} content - The raw Legal Markdown content to convert
|
|
152
|
+
* @param {string} outputPath - File path where the PDF will be saved
|
|
153
|
+
* @param {LegalMarkdownOptions & Object} [options={}] - Configuration options
|
|
154
|
+
* @param {string} [options.cssPath] - Path to custom CSS file
|
|
155
|
+
* @param {string} [options.highlightCssPath] - Path to field highlighting CSS
|
|
156
|
+
* @param {boolean} [options.includeHighlighting] - Whether to include field highlighting
|
|
157
|
+
* @param {string} [options.title] - Document title for PDF
|
|
158
|
+
* @param {'A4' | 'Letter' | 'Legal'} [options.format] - Page format
|
|
159
|
+
* @param {boolean} [options.landscape] - Whether to use landscape orientation
|
|
160
|
+
* @returns {Promise<Buffer>} A promise that resolves to the PDF buffer
|
|
161
|
+
* @throws {Error} When PDF generation fails
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const pdf = await generatePdf(content, './contract.pdf', {
|
|
165
|
+
* title: 'Service Agreement',
|
|
166
|
+
* format: 'A4',
|
|
167
|
+
* includeHighlighting: true,
|
|
168
|
+
* enableFieldTracking: true
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export declare function generatePdf(content: string, outputPath: string, options?: LegalMarkdownOptions & {
|
|
173
|
+
cssPath?: string;
|
|
174
|
+
highlightCssPath?: string;
|
|
175
|
+
includeHighlighting?: boolean;
|
|
176
|
+
title?: string;
|
|
177
|
+
format?: 'A4' | 'Letter' | 'Legal';
|
|
178
|
+
landscape?: boolean;
|
|
179
|
+
}): Promise<Buffer>;
|
|
180
|
+
/**
|
|
181
|
+
* Generate both normal and highlighted PDF versions
|
|
182
|
+
*
|
|
183
|
+
* This function creates two PDF versions of the same Legal Markdown document:
|
|
184
|
+
* one with standard formatting and another with field highlighting enabled.
|
|
185
|
+
* This is useful for document review processes where both clean and annotated
|
|
186
|
+
* versions are needed.
|
|
187
|
+
*
|
|
188
|
+
* @async
|
|
189
|
+
* @param {string} content - The raw Legal Markdown content to convert
|
|
190
|
+
* @param {string} outputPath - Base file path for PDFs (will be modified for each version)
|
|
191
|
+
* @param {LegalMarkdownOptions & Object} [options={}] - Configuration options
|
|
192
|
+
* @param {string} [options.cssPath] - Path to custom CSS file
|
|
193
|
+
* @param {string} [options.highlightCssPath] - Path to field highlighting CSS
|
|
194
|
+
* @param {string} [options.title] - Document title for PDFs
|
|
195
|
+
* @param {'A4' | 'Letter' | 'Legal'} [options.format] - Page format
|
|
196
|
+
* @param {boolean} [options.landscape] - Whether to use landscape orientation
|
|
197
|
+
* @returns {Promise<Object>} A promise that resolves to both PDF buffers
|
|
198
|
+
* @returns {Buffer} returns.normal - The normal PDF without highlighting
|
|
199
|
+
* @returns {Buffer} returns.highlighted - The highlighted PDF with field annotations
|
|
200
|
+
* @throws {Error} When PDF generation fails
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const { normal, highlighted } = await generatePdfVersions(content, './contract.pdf', {
|
|
204
|
+
* title: 'Service Agreement',
|
|
205
|
+
* format: 'A4'
|
|
206
|
+
* });
|
|
207
|
+
* // Creates: contract.pdf and contract.HIGHLIGHT.pdf
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
export declare function generatePdfVersions(content: string, outputPath: string, options?: LegalMarkdownOptions & {
|
|
211
|
+
cssPath?: string;
|
|
212
|
+
highlightCssPath?: string;
|
|
213
|
+
title?: string;
|
|
214
|
+
format?: 'A4' | 'Letter' | 'Legal';
|
|
215
|
+
landscape?: boolean;
|
|
216
|
+
}): Promise<{
|
|
217
|
+
normal: Buffer;
|
|
218
|
+
highlighted: Buffer;
|
|
219
|
+
}>;
|
|
220
|
+
export * from '@types';
|
|
221
|
+
export * from '@core';
|
|
222
|
+
export * from '@errors';
|
|
223
|
+
export * from '@constants';
|
|
224
|
+
export * from '@lib';
|
|
225
|
+
export * from '@extensions';
|
|
226
|
+
export { fieldTracker } from './tracking/field-tracker';
|
|
227
|
+
export { htmlGenerator } from './generators/html-generator';
|
|
228
|
+
export { pdfGenerator } from './generators/pdf-generator';
|
|
229
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAcH,OAAO,EA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,GAAE,oBAAoB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,OAAO,CAAC;IACnC,SAAS,CAAC,EAAE,OAAO,CAAC;CAChB,GACL,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,oBAAoB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,IAAI,GAAG,QAAQ,GAAG,OAAO,CAAC;IACnC,SAAS,CAAC,EAAE,OAAO,CAAC;CAChB,GACL,OAAO,CAAC;IACT,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CAUD;AAGD,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,MAAM,CAAC;AACrB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Main Entry Point for Legal Markdown Processing Library
|
|
4
|
+
*
|
|
5
|
+
* This module provides the primary API for processing Legal Markdown documents
|
|
6
|
+
* with support for YAML front matter, cross-references, optional clauses, mixins,
|
|
7
|
+
* header processing, and multi-format output generation (HTML, PDF).
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - YAML front matter parsing and metadata extraction
|
|
11
|
+
* - Cross-reference processing and resolution
|
|
12
|
+
* - Optional clause conditional rendering
|
|
13
|
+
* - Mixin system for reusable content blocks
|
|
14
|
+
* - Header numbering and formatting
|
|
15
|
+
* - Field tracking for document highlighting
|
|
16
|
+
* - HTML and PDF generation with styling
|
|
17
|
+
* - RST and LaTeX preprocessing support
|
|
18
|
+
* - Metadata export capabilities
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { processLegalMarkdown, generateHtml, generatePdf } from 'legal-markdown-js';
|
|
23
|
+
*
|
|
24
|
+
* // Basic document processing
|
|
25
|
+
* const result = processLegalMarkdown(content, {
|
|
26
|
+
* enableFieldTracking: true,
|
|
27
|
+
* basePath: './documents'
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Generate HTML output
|
|
31
|
+
* const html = await generateHtml(content, {
|
|
32
|
+
* title: 'Legal Agreement',
|
|
33
|
+
* includeHighlighting: true
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // Generate PDF output
|
|
37
|
+
* const pdf = await generatePdf(content, './output.pdf', {
|
|
38
|
+
* format: 'A4',
|
|
39
|
+
* includeHighlighting: true
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
44
|
+
if (k2 === undefined) k2 = k;
|
|
45
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
46
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
47
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
48
|
+
}
|
|
49
|
+
Object.defineProperty(o, k2, desc);
|
|
50
|
+
}) : (function(o, m, k, k2) {
|
|
51
|
+
if (k2 === undefined) k2 = k;
|
|
52
|
+
o[k2] = m[k];
|
|
53
|
+
}));
|
|
54
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
55
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
56
|
+
};
|
|
57
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
58
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
59
|
+
};
|
|
60
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
+
exports.pdfGenerator = exports.htmlGenerator = exports.fieldTracker = void 0;
|
|
62
|
+
exports.processLegalMarkdownAsync = processLegalMarkdownAsync;
|
|
63
|
+
exports.processLegalMarkdown = processLegalMarkdown;
|
|
64
|
+
exports.generateHtml = generateHtml;
|
|
65
|
+
exports.generatePdf = generatePdf;
|
|
66
|
+
exports.generatePdfVersions = generatePdfVersions;
|
|
67
|
+
const yaml_parser_1 = require("./core/parsers/yaml-parser");
|
|
68
|
+
const header_processor_1 = require("./core/processors/header-processor");
|
|
69
|
+
const clause_processor_1 = require("./core/processors/clause-processor");
|
|
70
|
+
const reference_processor_1 = require("./core/processors/reference-processor");
|
|
71
|
+
const import_processor_1 = require("./core/processors/import-processor");
|
|
72
|
+
const mixin_processor_1 = require("./core/processors/mixin-processor");
|
|
73
|
+
const metadata_exporter_1 = require("./core/exporters/metadata-exporter");
|
|
74
|
+
const rst_parser_1 = require("./extensions/rst-parser");
|
|
75
|
+
const latex_parser_1 = require("./extensions/latex-parser");
|
|
76
|
+
const field_tracker_1 = require("./tracking/field-tracker");
|
|
77
|
+
const html_generator_1 = require("./generators/html-generator");
|
|
78
|
+
const pdf_generator_1 = require("./generators/pdf-generator");
|
|
79
|
+
const path_1 = __importDefault(require("path"));
|
|
80
|
+
/**
|
|
81
|
+
* Main function to process a Legal Markdown document (async version)
|
|
82
|
+
*
|
|
83
|
+
* This function orchestrates the complete processing pipeline for Legal Markdown
|
|
84
|
+
* documents, including YAML parsing, content preprocessing, clause processing,
|
|
85
|
+
* cross-reference resolution, mixin expansion, header formatting, and metadata export.
|
|
86
|
+
*
|
|
87
|
+
* @param {string} content - The raw Legal Markdown content to process
|
|
88
|
+
* @param {LegalMarkdownOptions} [options={}] - Configuration options for processing
|
|
89
|
+
* @returns {Promise<Object>} Processing result containing processed content, metadata, and reports
|
|
90
|
+
* @returns {string} returns.content - The processed document content
|
|
91
|
+
* @returns {Record<string, any>} [returns.metadata] - Extracted YAML metadata
|
|
92
|
+
* @returns {string[]} [returns.exportedFiles] - Array of exported metadata files
|
|
93
|
+
* @returns {Object} [returns.fieldReport] - Field tracking report if enabled
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const result = await processLegalMarkdownAsync(content, {
|
|
97
|
+
* enableFieldTracking: true,
|
|
98
|
+
* basePath: './documents',
|
|
99
|
+
* noClauses: false,
|
|
100
|
+
* noReferences: false
|
|
101
|
+
* });
|
|
102
|
+
*
|
|
103
|
+
* console.log(result.content); // Processed markdown
|
|
104
|
+
* console.log(result.metadata); // YAML front matter
|
|
105
|
+
* console.log(result.fieldReport); // Field usage report
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
async function processLegalMarkdownAsync(content, options = {}) {
|
|
109
|
+
// Clear field tracker for new document
|
|
110
|
+
field_tracker_1.fieldTracker.clear();
|
|
111
|
+
// Convert RST or LaTeX to legal markdown if needed (before YAML parsing)
|
|
112
|
+
let preprocessedContent = await (0, rst_parser_1.convertRstToLegalMarkdown)(content);
|
|
113
|
+
preprocessedContent = await (0, latex_parser_1.convertLatexToLegalMarkdown)(preprocessedContent);
|
|
114
|
+
// Parse YAML Front Matter
|
|
115
|
+
const { content: contentWithoutYaml, metadata } = (0, yaml_parser_1.parseYamlFrontMatter)(preprocessedContent, options.throwOnYamlError);
|
|
116
|
+
// If only processing YAML, return early
|
|
117
|
+
if (options.yamlOnly) {
|
|
118
|
+
return { content: contentWithoutYaml, metadata };
|
|
119
|
+
}
|
|
120
|
+
// Process partial imports (must be done early)
|
|
121
|
+
let processedContent = contentWithoutYaml;
|
|
122
|
+
let exportedFiles = [];
|
|
123
|
+
if (!options.noImports) {
|
|
124
|
+
const importResult = (0, import_processor_1.processPartialImports)(processedContent, options.basePath);
|
|
125
|
+
processedContent = importResult.content;
|
|
126
|
+
exportedFiles = importResult.importedFiles;
|
|
127
|
+
}
|
|
128
|
+
// Process optional clauses
|
|
129
|
+
if (!options.noClauses) {
|
|
130
|
+
processedContent = (0, clause_processor_1.processOptionalClauses)(processedContent, metadata);
|
|
131
|
+
}
|
|
132
|
+
// Process cross references
|
|
133
|
+
if (!options.noReferences) {
|
|
134
|
+
processedContent = (0, reference_processor_1.processCrossReferences)(processedContent, metadata);
|
|
135
|
+
}
|
|
136
|
+
// Process mixins
|
|
137
|
+
if (!options.noMixins) {
|
|
138
|
+
processedContent = (0, mixin_processor_1.processMixins)(processedContent, metadata, options);
|
|
139
|
+
}
|
|
140
|
+
// Process headers (numbering, etc)
|
|
141
|
+
if (!options.noHeaders) {
|
|
142
|
+
processedContent = (0, header_processor_1.processHeaders)(processedContent, metadata, {
|
|
143
|
+
noReset: options.noReset,
|
|
144
|
+
noIndent: options.noIndent,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// Export metadata if requested or specified in metadata
|
|
148
|
+
if (options.exportMetadata || metadata['meta-yaml-output'] || metadata['meta-json-output']) {
|
|
149
|
+
const exportResult = (0, metadata_exporter_1.exportMetadata)(metadata, options.exportFormat, options.exportPath);
|
|
150
|
+
exportedFiles = [...exportedFiles, ...exportResult.exportedFiles];
|
|
151
|
+
}
|
|
152
|
+
// Apply field tracking to content if highlighting is enabled
|
|
153
|
+
if (options.enableFieldTracking) {
|
|
154
|
+
processedContent = field_tracker_1.fieldTracker.applyFieldTracking(processedContent);
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
content: processedContent,
|
|
158
|
+
metadata,
|
|
159
|
+
exportedFiles,
|
|
160
|
+
fieldReport: options.enableFieldTracking ? field_tracker_1.fieldTracker.generateReport() : undefined,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Main function to process a Legal Markdown document (sync version with fallback)
|
|
165
|
+
*
|
|
166
|
+
* This function uses fallback parsers for RST/LaTeX to maintain backward compatibility
|
|
167
|
+
* and ensure the library works without pandoc dependencies.
|
|
168
|
+
*
|
|
169
|
+
* @param {string} content - The raw Legal Markdown content to process
|
|
170
|
+
* @param {LegalMarkdownOptions} [options={}] - Configuration options for processing
|
|
171
|
+
* @returns {Object} Processing result containing processed content, metadata, and reports
|
|
172
|
+
* @returns {string} returns.content - The processed document content
|
|
173
|
+
* @returns {Record<string, any>} [returns.metadata] - Extracted YAML metadata
|
|
174
|
+
* @returns {string[]} [returns.exportedFiles] - Array of exported metadata files
|
|
175
|
+
* @returns {Object} [returns.fieldReport] - Field tracking report if enabled
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* const result = processLegalMarkdown(content, {
|
|
179
|
+
* enableFieldTracking: true,
|
|
180
|
+
* basePath: './documents',
|
|
181
|
+
* noClauses: false,
|
|
182
|
+
* noReferences: false
|
|
183
|
+
* });
|
|
184
|
+
*
|
|
185
|
+
* console.log(result.content); // Processed markdown
|
|
186
|
+
* console.log(result.metadata); // YAML front matter
|
|
187
|
+
* console.log(result.fieldReport); // Field usage report
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
function processLegalMarkdown(content, options = {}) {
|
|
191
|
+
// Clear field tracker for new document
|
|
192
|
+
field_tracker_1.fieldTracker.clear();
|
|
193
|
+
// Convert RST or LaTeX to legal markdown if needed (before YAML parsing)
|
|
194
|
+
let preprocessedContent = (0, rst_parser_1.convertRstToLegalMarkdownSync)(content);
|
|
195
|
+
preprocessedContent = (0, latex_parser_1.convertLatexToLegalMarkdownSync)(preprocessedContent);
|
|
196
|
+
// Parse YAML Front Matter
|
|
197
|
+
const { content: contentWithoutYaml, metadata } = (0, yaml_parser_1.parseYamlFrontMatter)(preprocessedContent, options.throwOnYamlError);
|
|
198
|
+
// If only processing YAML, return early
|
|
199
|
+
if (options.yamlOnly) {
|
|
200
|
+
return { content: contentWithoutYaml, metadata };
|
|
201
|
+
}
|
|
202
|
+
// Process partial imports (must be done early)
|
|
203
|
+
let processedContent = contentWithoutYaml;
|
|
204
|
+
let exportedFiles = [];
|
|
205
|
+
if (!options.noImports) {
|
|
206
|
+
const importResult = (0, import_processor_1.processPartialImports)(processedContent, options.basePath);
|
|
207
|
+
processedContent = importResult.content;
|
|
208
|
+
exportedFiles = importResult.importedFiles;
|
|
209
|
+
}
|
|
210
|
+
// Process optional clauses
|
|
211
|
+
if (!options.noClauses) {
|
|
212
|
+
processedContent = (0, clause_processor_1.processOptionalClauses)(processedContent, metadata);
|
|
213
|
+
}
|
|
214
|
+
// Process cross references
|
|
215
|
+
if (!options.noReferences) {
|
|
216
|
+
processedContent = (0, reference_processor_1.processCrossReferences)(processedContent, metadata);
|
|
217
|
+
}
|
|
218
|
+
// Process mixins
|
|
219
|
+
if (!options.noMixins) {
|
|
220
|
+
processedContent = (0, mixin_processor_1.processMixins)(processedContent, metadata, options);
|
|
221
|
+
}
|
|
222
|
+
// Process headers (numbering, etc)
|
|
223
|
+
if (!options.noHeaders) {
|
|
224
|
+
processedContent = (0, header_processor_1.processHeaders)(processedContent, metadata, {
|
|
225
|
+
noReset: options.noReset,
|
|
226
|
+
noIndent: options.noIndent,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
// Export metadata if requested or specified in metadata
|
|
230
|
+
if (options.exportMetadata || metadata['meta-yaml-output'] || metadata['meta-json-output']) {
|
|
231
|
+
const exportResult = (0, metadata_exporter_1.exportMetadata)(metadata, options.exportFormat, options.exportPath);
|
|
232
|
+
exportedFiles = [...exportedFiles, ...exportResult.exportedFiles];
|
|
233
|
+
}
|
|
234
|
+
// Apply field tracking to content if highlighting is enabled
|
|
235
|
+
if (options.enableFieldTracking) {
|
|
236
|
+
processedContent = field_tracker_1.fieldTracker.applyFieldTracking(processedContent);
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
content: processedContent,
|
|
240
|
+
metadata,
|
|
241
|
+
exportedFiles,
|
|
242
|
+
fieldReport: options.enableFieldTracking ? field_tracker_1.fieldTracker.generateReport() : undefined,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Generate HTML from Legal Markdown content
|
|
247
|
+
*
|
|
248
|
+
* This function processes Legal Markdown content and generates a complete HTML
|
|
249
|
+
* document with styling, field highlighting, and responsive design features.
|
|
250
|
+
* It combines the Legal Markdown processing pipeline with HTML generation.
|
|
251
|
+
*
|
|
252
|
+
* @async
|
|
253
|
+
* @param {string} content - The raw Legal Markdown content to convert
|
|
254
|
+
* @param {LegalMarkdownOptions & Object} [options={}] - Configuration options
|
|
255
|
+
* @param {string} [options.cssPath] - Path to custom CSS file
|
|
256
|
+
* @param {string} [options.highlightCssPath] - Path to field highlighting CSS
|
|
257
|
+
* @param {boolean} [options.includeHighlighting] - Whether to include field highlighting
|
|
258
|
+
* @param {string} [options.title] - Document title for HTML
|
|
259
|
+
* @returns {Promise<string>} A promise that resolves to the complete HTML document
|
|
260
|
+
* @throws {Error} When HTML generation fails
|
|
261
|
+
* @example
|
|
262
|
+
* ```typescript
|
|
263
|
+
* const html = await generateHtml(content, {
|
|
264
|
+
* title: 'Service Agreement',
|
|
265
|
+
* cssPath: './custom-styles.css',
|
|
266
|
+
* includeHighlighting: true,
|
|
267
|
+
* enableFieldTracking: true
|
|
268
|
+
* });
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
async function generateHtml(content, options = {}) {
|
|
272
|
+
// Process the legal markdown first (use async version for better RST/LaTeX support)
|
|
273
|
+
const processed = await processLegalMarkdownAsync(content, {
|
|
274
|
+
...options,
|
|
275
|
+
enableFieldTracking: options.includeHighlighting,
|
|
276
|
+
});
|
|
277
|
+
// Generate HTML
|
|
278
|
+
return html_generator_1.htmlGenerator.generateHtml(processed.content, {
|
|
279
|
+
cssPath: options.cssPath,
|
|
280
|
+
highlightCssPath: options.highlightCssPath || path_1.default.join(__dirname, '../styles/highlight.css'),
|
|
281
|
+
includeHighlighting: options.includeHighlighting,
|
|
282
|
+
title: options.title,
|
|
283
|
+
metadata: processed.metadata,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Generate PDF from Legal Markdown content
|
|
288
|
+
*
|
|
289
|
+
* This function processes Legal Markdown content and generates a PDF document
|
|
290
|
+
* with professional styling, field highlighting, and customizable page formatting.
|
|
291
|
+
* It combines the Legal Markdown processing pipeline with PDF generation.
|
|
292
|
+
*
|
|
293
|
+
* @async
|
|
294
|
+
* @param {string} content - The raw Legal Markdown content to convert
|
|
295
|
+
* @param {string} outputPath - File path where the PDF will be saved
|
|
296
|
+
* @param {LegalMarkdownOptions & Object} [options={}] - Configuration options
|
|
297
|
+
* @param {string} [options.cssPath] - Path to custom CSS file
|
|
298
|
+
* @param {string} [options.highlightCssPath] - Path to field highlighting CSS
|
|
299
|
+
* @param {boolean} [options.includeHighlighting] - Whether to include field highlighting
|
|
300
|
+
* @param {string} [options.title] - Document title for PDF
|
|
301
|
+
* @param {'A4' | 'Letter' | 'Legal'} [options.format] - Page format
|
|
302
|
+
* @param {boolean} [options.landscape] - Whether to use landscape orientation
|
|
303
|
+
* @returns {Promise<Buffer>} A promise that resolves to the PDF buffer
|
|
304
|
+
* @throws {Error} When PDF generation fails
|
|
305
|
+
* @example
|
|
306
|
+
* ```typescript
|
|
307
|
+
* const pdf = await generatePdf(content, './contract.pdf', {
|
|
308
|
+
* title: 'Service Agreement',
|
|
309
|
+
* format: 'A4',
|
|
310
|
+
* includeHighlighting: true,
|
|
311
|
+
* enableFieldTracking: true
|
|
312
|
+
* });
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
async function generatePdf(content, outputPath, options = {}) {
|
|
316
|
+
// Process the legal markdown first (use async version for better RST/LaTeX support)
|
|
317
|
+
const processed = await processLegalMarkdownAsync(content, {
|
|
318
|
+
...options,
|
|
319
|
+
enableFieldTracking: options.includeHighlighting,
|
|
320
|
+
});
|
|
321
|
+
// Generate PDF
|
|
322
|
+
return pdf_generator_1.pdfGenerator.generatePdf(processed.content, outputPath, {
|
|
323
|
+
cssPath: options.cssPath,
|
|
324
|
+
highlightCssPath: options.highlightCssPath || path_1.default.join(__dirname, '../styles/highlight.css'),
|
|
325
|
+
includeHighlighting: options.includeHighlighting,
|
|
326
|
+
title: options.title,
|
|
327
|
+
metadata: processed.metadata,
|
|
328
|
+
format: options.format,
|
|
329
|
+
landscape: options.landscape,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Generate both normal and highlighted PDF versions
|
|
334
|
+
*
|
|
335
|
+
* This function creates two PDF versions of the same Legal Markdown document:
|
|
336
|
+
* one with standard formatting and another with field highlighting enabled.
|
|
337
|
+
* This is useful for document review processes where both clean and annotated
|
|
338
|
+
* versions are needed.
|
|
339
|
+
*
|
|
340
|
+
* @async
|
|
341
|
+
* @param {string} content - The raw Legal Markdown content to convert
|
|
342
|
+
* @param {string} outputPath - Base file path for PDFs (will be modified for each version)
|
|
343
|
+
* @param {LegalMarkdownOptions & Object} [options={}] - Configuration options
|
|
344
|
+
* @param {string} [options.cssPath] - Path to custom CSS file
|
|
345
|
+
* @param {string} [options.highlightCssPath] - Path to field highlighting CSS
|
|
346
|
+
* @param {string} [options.title] - Document title for PDFs
|
|
347
|
+
* @param {'A4' | 'Letter' | 'Legal'} [options.format] - Page format
|
|
348
|
+
* @param {boolean} [options.landscape] - Whether to use landscape orientation
|
|
349
|
+
* @returns {Promise<Object>} A promise that resolves to both PDF buffers
|
|
350
|
+
* @returns {Buffer} returns.normal - The normal PDF without highlighting
|
|
351
|
+
* @returns {Buffer} returns.highlighted - The highlighted PDF with field annotations
|
|
352
|
+
* @throws {Error} When PDF generation fails
|
|
353
|
+
* @example
|
|
354
|
+
* ```typescript
|
|
355
|
+
* const { normal, highlighted } = await generatePdfVersions(content, './contract.pdf', {
|
|
356
|
+
* title: 'Service Agreement',
|
|
357
|
+
* format: 'A4'
|
|
358
|
+
* });
|
|
359
|
+
* // Creates: contract.pdf and contract.HIGHLIGHT.pdf
|
|
360
|
+
* ```
|
|
361
|
+
*/
|
|
362
|
+
async function generatePdfVersions(content, outputPath, options = {}) {
|
|
363
|
+
const normalPath = outputPath;
|
|
364
|
+
const highlightedPath = outputPath.replace('.pdf', '.HIGHLIGHT.pdf');
|
|
365
|
+
const [normal, highlighted] = await Promise.all([
|
|
366
|
+
generatePdf(content, normalPath, { ...options, includeHighlighting: false }),
|
|
367
|
+
generatePdf(content, highlightedPath, { ...options, includeHighlighting: true }),
|
|
368
|
+
]);
|
|
369
|
+
return { normal, highlighted };
|
|
370
|
+
}
|
|
371
|
+
// Export all sub-modules
|
|
372
|
+
__exportStar(require("./types.js"), exports);
|
|
373
|
+
__exportStar(require("./core/index.js"), exports);
|
|
374
|
+
__exportStar(require("./errors/index.js"), exports);
|
|
375
|
+
__exportStar(require("./constants/index.js"), exports);
|
|
376
|
+
__exportStar(require("./lib/index.js"), exports);
|
|
377
|
+
__exportStar(require("./extensions/index.js"), exports);
|
|
378
|
+
var field_tracker_2 = require("./tracking/field-tracker");
|
|
379
|
+
Object.defineProperty(exports, "fieldTracker", { enumerable: true, get: function () { return field_tracker_2.fieldTracker; } });
|
|
380
|
+
var html_generator_2 = require("./generators/html-generator");
|
|
381
|
+
Object.defineProperty(exports, "htmlGenerator", { enumerable: true, get: function () { return html_generator_2.htmlGenerator; } });
|
|
382
|
+
var pdf_generator_2 = require("./generators/pdf-generator");
|
|
383
|
+
Object.defineProperty(exports, "pdfGenerator", { enumerable: true, get: function () { return pdf_generator_2.pdfGenerator; } });
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