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,361 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview HTML Generation Module for Legal Markdown Documents
|
|
4
|
+
*
|
|
5
|
+
* This module provides functionality to convert processed Legal Markdown content
|
|
6
|
+
* into well-formatted HTML documents with CSS styling, accessibility features,
|
|
7
|
+
* and print optimization.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Markdown to HTML conversion using marked
|
|
11
|
+
* - DOM manipulation with cheerio for enhanced formatting
|
|
12
|
+
* - Custom CSS injection and styling
|
|
13
|
+
* - Field highlighting for document review
|
|
14
|
+
* - Print-friendly output with page break controls
|
|
15
|
+
* - Responsive table handling
|
|
16
|
+
* - Accessibility improvements
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { htmlGenerator } from './html-generator';
|
|
21
|
+
*
|
|
22
|
+
* const html = await htmlGenerator.generateHtml(markdownContent, {
|
|
23
|
+
* title: 'Legal Agreement',
|
|
24
|
+
* cssPath: './styles.css',
|
|
25
|
+
* includeHighlighting: true
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
30
|
+
if (k2 === undefined) k2 = k;
|
|
31
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
32
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
33
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
34
|
+
}
|
|
35
|
+
Object.defineProperty(o, k2, desc);
|
|
36
|
+
}) : (function(o, m, k, k2) {
|
|
37
|
+
if (k2 === undefined) k2 = k;
|
|
38
|
+
o[k2] = m[k];
|
|
39
|
+
}));
|
|
40
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
41
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
42
|
+
}) : function(o, v) {
|
|
43
|
+
o["default"] = v;
|
|
44
|
+
});
|
|
45
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
46
|
+
var ownKeys = function(o) {
|
|
47
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
48
|
+
var ar = [];
|
|
49
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
50
|
+
return ar;
|
|
51
|
+
};
|
|
52
|
+
return ownKeys(o);
|
|
53
|
+
};
|
|
54
|
+
return function (mod) {
|
|
55
|
+
if (mod && mod.__esModule) return mod;
|
|
56
|
+
var result = {};
|
|
57
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
58
|
+
__setModuleDefault(result, mod);
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
})();
|
|
62
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
|
+
exports.htmlGenerator = exports.HtmlGenerator = void 0;
|
|
64
|
+
const marked_1 = require("marked");
|
|
65
|
+
const cheerio = __importStar(require("cheerio"));
|
|
66
|
+
const fs = __importStar(require("fs/promises"));
|
|
67
|
+
const path = __importStar(require("path"));
|
|
68
|
+
const js_beautify_1 = require("js-beautify");
|
|
69
|
+
const logger_1 = require("../utils/logger");
|
|
70
|
+
/**
|
|
71
|
+
* HTML Generator for Legal Markdown Documents
|
|
72
|
+
*
|
|
73
|
+
* Converts processed Legal Markdown content into formatted HTML documents
|
|
74
|
+
* with professional styling, accessibility features, and print optimization.
|
|
75
|
+
*
|
|
76
|
+
* @class HtmlGenerator
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const generator = new HtmlGenerator();
|
|
80
|
+
* const html = await generator.generateHtml(content, {
|
|
81
|
+
* title: 'Contract',
|
|
82
|
+
* includeHighlighting: true
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
class HtmlGenerator {
|
|
87
|
+
/**
|
|
88
|
+
* Creates a new HTML generator instance and configures the markdown parser
|
|
89
|
+
*
|
|
90
|
+
* @constructor
|
|
91
|
+
*/
|
|
92
|
+
constructor() {
|
|
93
|
+
this.configureMarked();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Configures the marked markdown parser with options optimized for legal documents
|
|
97
|
+
*
|
|
98
|
+
* @private
|
|
99
|
+
* @method configureMarked
|
|
100
|
+
* @returns {void}
|
|
101
|
+
*/
|
|
102
|
+
configureMarked() {
|
|
103
|
+
// Configure marked options
|
|
104
|
+
marked_1.marked.setOptions({
|
|
105
|
+
gfm: true,
|
|
106
|
+
breaks: true,
|
|
107
|
+
pedantic: false,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Removes YAML frontmatter from markdown content if present
|
|
112
|
+
*
|
|
113
|
+
* @private
|
|
114
|
+
* @method removeYamlFrontmatter
|
|
115
|
+
* @param {string} content - The markdown content that may contain YAML frontmatter
|
|
116
|
+
* @returns {string} Content with YAML frontmatter removed
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const content = `---
|
|
120
|
+
* title: Document
|
|
121
|
+
* ---
|
|
122
|
+
* # Content`;
|
|
123
|
+
* const clean = this.removeYamlFrontmatter(content); // "# Content"
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
removeYamlFrontmatter(content) {
|
|
127
|
+
// Check if content starts with YAML frontmatter
|
|
128
|
+
if (content.startsWith('---')) {
|
|
129
|
+
// Find the closing --- delimiter (allowing for various line endings)
|
|
130
|
+
const lines = content.split('\n');
|
|
131
|
+
let endIndex = -1;
|
|
132
|
+
// Look for the closing --- starting from line 1 (skip the opening ---)
|
|
133
|
+
for (let i = 1; i < lines.length; i++) {
|
|
134
|
+
if (lines[i].trim() === '---') {
|
|
135
|
+
endIndex = i;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (endIndex !== -1) {
|
|
140
|
+
// Return content after the frontmatter (skip the closing --- line)
|
|
141
|
+
return lines
|
|
142
|
+
.slice(endIndex + 1)
|
|
143
|
+
.join('\n')
|
|
144
|
+
.trim();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return content;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Generates a complete HTML document from Legal Markdown content
|
|
151
|
+
*
|
|
152
|
+
* This is the main method that orchestrates the conversion process:
|
|
153
|
+
* 1. Removes YAML frontmatter
|
|
154
|
+
* 2. Converts markdown to HTML using marked
|
|
155
|
+
* 3. Applies DOM transformations for legal document formatting
|
|
156
|
+
* 4. Injects custom CSS and styling
|
|
157
|
+
* 5. Builds a complete HTML document
|
|
158
|
+
*
|
|
159
|
+
* @async
|
|
160
|
+
* @method generateHtml
|
|
161
|
+
* @param {string} markdownContent - The processed Legal Markdown content to convert
|
|
162
|
+
* @param {HtmlGeneratorOptions} [options={}] - Configuration options for HTML generation
|
|
163
|
+
* @returns {Promise<string>} A promise that resolves to the complete HTML document
|
|
164
|
+
* @throws {Error} When HTML generation fails due to parsing or file system errors
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const html = await generator.generateHtml(
|
|
168
|
+
* '# Contract\n\nThis is a {{party.name}} agreement.',
|
|
169
|
+
* {
|
|
170
|
+
* title: 'Service Agreement',
|
|
171
|
+
* cssPath: './contract-styles.css',
|
|
172
|
+
* includeHighlighting: true,
|
|
173
|
+
* metadata: {
|
|
174
|
+
* author: 'Legal Team',
|
|
175
|
+
* version: '1.0'
|
|
176
|
+
* }
|
|
177
|
+
* }
|
|
178
|
+
* );
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
async generateHtml(markdownContent, options = {}) {
|
|
182
|
+
try {
|
|
183
|
+
logger_1.logger.debug('Generating HTML from markdown', {
|
|
184
|
+
contentLength: markdownContent.length,
|
|
185
|
+
options,
|
|
186
|
+
});
|
|
187
|
+
// Remove YAML frontmatter if present
|
|
188
|
+
const contentWithoutFrontmatter = this.removeYamlFrontmatter(markdownContent);
|
|
189
|
+
// Convert markdown to HTML
|
|
190
|
+
const htmlContent = await marked_1.marked.parse(contentWithoutFrontmatter);
|
|
191
|
+
// Load and manipulate with cheerio
|
|
192
|
+
const $ = cheerio.load(htmlContent);
|
|
193
|
+
// Apply DOM transformations
|
|
194
|
+
this.applyDomTransformations($);
|
|
195
|
+
// Add CSS if provided
|
|
196
|
+
let cssContent = '';
|
|
197
|
+
if (options.cssPath) {
|
|
198
|
+
cssContent += await this.loadCss(options.cssPath);
|
|
199
|
+
}
|
|
200
|
+
if (options.includeHighlighting && options.highlightCssPath) {
|
|
201
|
+
cssContent += '\n' + (await this.loadCss(options.highlightCssPath));
|
|
202
|
+
}
|
|
203
|
+
// Build complete HTML document
|
|
204
|
+
const completeHtml = await this.buildHtmlDocument({
|
|
205
|
+
body: $.html(),
|
|
206
|
+
css: cssContent,
|
|
207
|
+
title: options.title || 'Legal Document',
|
|
208
|
+
useDefaultCss: !options.cssPath, // Only use default CSS if no custom CSS is provided
|
|
209
|
+
metadata: options.metadata,
|
|
210
|
+
});
|
|
211
|
+
// Format the HTML for consistent output
|
|
212
|
+
const formattedHtml = (0, js_beautify_1.html)(completeHtml, {
|
|
213
|
+
indent_size: 2,
|
|
214
|
+
indent_char: ' ',
|
|
215
|
+
max_preserve_newlines: 2,
|
|
216
|
+
preserve_newlines: true,
|
|
217
|
+
indent_scripts: 'normal',
|
|
218
|
+
end_with_newline: true,
|
|
219
|
+
wrap_line_length: 0,
|
|
220
|
+
indent_inner_html: true,
|
|
221
|
+
unformatted: ['pre', 'code'],
|
|
222
|
+
content_unformatted: ['pre', 'script', 'style'],
|
|
223
|
+
extra_liners: ['head', 'body', '/html'],
|
|
224
|
+
});
|
|
225
|
+
logger_1.logger.debug('HTML generation completed', {
|
|
226
|
+
htmlLength: formattedHtml.length,
|
|
227
|
+
});
|
|
228
|
+
return formattedHtml;
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
logger_1.logger.error('Error generating HTML', { error });
|
|
232
|
+
throw new Error(`Failed to generate HTML: ${error instanceof Error ? error.message : String(error)}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Applies DOM transformations to enhance the HTML for legal document presentation
|
|
237
|
+
*
|
|
238
|
+
* Transformations include:
|
|
239
|
+
* - Adding no-break classes to short lists for better print layout
|
|
240
|
+
* - Wrapping tables in responsive containers
|
|
241
|
+
* - Adding alt attributes to images for accessibility
|
|
242
|
+
* - Adding print-friendly CSS classes
|
|
243
|
+
* - Cleaning up paragraph tags in list items
|
|
244
|
+
*
|
|
245
|
+
* @private
|
|
246
|
+
* @method applyDomTransformations
|
|
247
|
+
* @param {cheerio.CheerioAPI} $ - The cheerio instance with loaded HTML
|
|
248
|
+
* @returns {void}
|
|
249
|
+
*/
|
|
250
|
+
applyDomTransformations($) {
|
|
251
|
+
// Apply list transformations (prevent page breaks in short lists)
|
|
252
|
+
const maxListItemsNoBreak = 5;
|
|
253
|
+
$('ul, ol').each((_, element) => {
|
|
254
|
+
const list = $(element);
|
|
255
|
+
if (list.children().length < maxListItemsNoBreak) {
|
|
256
|
+
list.addClass('no-break');
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
// Clean up paragraph tags in list items (unwrap single p tags)
|
|
260
|
+
$('li > p:only-child').each((_, element) => {
|
|
261
|
+
const p = $(element);
|
|
262
|
+
const li = p.parent();
|
|
263
|
+
li.html(p.html() || '');
|
|
264
|
+
});
|
|
265
|
+
// Apply table responsiveness
|
|
266
|
+
$('table').each((_, element) => {
|
|
267
|
+
const table = $(element);
|
|
268
|
+
if (!table.parent().hasClass('table-responsive')) {
|
|
269
|
+
table.wrap('<div class="table-responsive"></div>');
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
// Ensure images have alt attributes for accessibility
|
|
273
|
+
$('img:not([alt])').attr('alt', '');
|
|
274
|
+
// Add print-friendly classes
|
|
275
|
+
$('.page-break').addClass('page-break-before');
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Loads CSS content from a file path
|
|
279
|
+
*
|
|
280
|
+
* @private
|
|
281
|
+
* @async
|
|
282
|
+
* @method loadCss
|
|
283
|
+
* @param {string} cssPath - Path to the CSS file to load
|
|
284
|
+
* @returns {Promise<string>} A promise that resolves to the CSS content, or empty string on error
|
|
285
|
+
*/
|
|
286
|
+
async loadCss(cssPath) {
|
|
287
|
+
try {
|
|
288
|
+
const cssContent = await fs.readFile(cssPath, 'utf-8');
|
|
289
|
+
logger_1.logger.debug('CSS file loaded', { cssPath, size: cssContent.length });
|
|
290
|
+
return cssContent;
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
logger_1.logger.warn(`Failed to load CSS file: ${cssPath}`, { error });
|
|
294
|
+
return '';
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Builds a complete HTML document with head, body, and embedded styles
|
|
299
|
+
*
|
|
300
|
+
* Creates a well-formed HTML5 document with:
|
|
301
|
+
* - Proper DOCTYPE and meta tags
|
|
302
|
+
* - Responsive viewport configuration
|
|
303
|
+
* - Embedded CSS styles (base + custom)
|
|
304
|
+
* - SEO-friendly metadata
|
|
305
|
+
* - Print-optimized styling
|
|
306
|
+
*
|
|
307
|
+
* @private
|
|
308
|
+
* @method buildHtmlDocument
|
|
309
|
+
* @param {Object} options - Configuration for building the HTML document
|
|
310
|
+
* @param {string} options.body - The HTML body content
|
|
311
|
+
* @param {string} options.css - Custom CSS to embed
|
|
312
|
+
* @param {string} options.title - Document title
|
|
313
|
+
* @param {Record<string, string>} [options.metadata] - Additional metadata for HTML head
|
|
314
|
+
* @returns {string} Complete HTML document as string
|
|
315
|
+
*/
|
|
316
|
+
async buildHtmlDocument(options) {
|
|
317
|
+
const { body, css, title, metadata = {}, useDefaultCss = true } = options;
|
|
318
|
+
// Load default CSS only if no custom CSS is provided
|
|
319
|
+
let defaultCss = '';
|
|
320
|
+
if (useDefaultCss) {
|
|
321
|
+
const defaultCssPath = path.join(__dirname, '..', 'styles', 'default.css');
|
|
322
|
+
defaultCss = await this.loadCss(defaultCssPath);
|
|
323
|
+
}
|
|
324
|
+
// Build metadata tags
|
|
325
|
+
const metaTags = Object.entries(metadata)
|
|
326
|
+
.map(([name, content]) => ` <meta name="${name}" content="${content}">`)
|
|
327
|
+
.join('\n');
|
|
328
|
+
return `<!DOCTYPE html>
|
|
329
|
+
<html lang="en">
|
|
330
|
+
<head>
|
|
331
|
+
<meta charset="UTF-8">
|
|
332
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
333
|
+
<title>${title}</title>
|
|
334
|
+
${metaTags ? metaTags + '\n' : ''} <style>
|
|
335
|
+
/* Default CSS */
|
|
336
|
+
${defaultCss}
|
|
337
|
+
|
|
338
|
+
/* Custom CSS */
|
|
339
|
+
${css}
|
|
340
|
+
</style>
|
|
341
|
+
</head>
|
|
342
|
+
<body>
|
|
343
|
+
${body}
|
|
344
|
+
</body>
|
|
345
|
+
</html>`;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
exports.HtmlGenerator = HtmlGenerator;
|
|
349
|
+
/**
|
|
350
|
+
* Singleton instance of HtmlGenerator for convenient importing
|
|
351
|
+
*
|
|
352
|
+
* @constant {HtmlGenerator} htmlGenerator
|
|
353
|
+
* @example
|
|
354
|
+
* ```typescript
|
|
355
|
+
* import { htmlGenerator } from './html-generator';
|
|
356
|
+
* const html = await htmlGenerator.generateHtml(content);
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
// Export singleton instance
|
|
360
|
+
exports.htmlGenerator = new HtmlGenerator();
|
|
361
|
+
//# sourceMappingURL=html-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-generator.js","sourceRoot":"","sources":["../../src/generators/html-generator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,mCAAgC;AAChC,iDAAmC;AACnC,gDAAkC;AAClC,2CAA6B;AAC7B,6CAAmD;AACnD,4CAAyC;AAoBzC;;;;;;;;;;;;;;;GAeG;AACH,MAAa,aAAa;IACxB;;;;OAIG;IACH;QACE,IAAI,CAAC,eAAe,EAAE,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACK,eAAe;QACrB,2BAA2B;QAC3B,eAAM,CAAC,UAAU,CAAC;YAChB,GAAG,EAAE,IAAI;YACT,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACK,qBAAqB,CAAC,OAAe;QAC3C,gDAAgD;QAChD,IAAI,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,qEAAqE;YACrE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAClC,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC;YAElB,uEAAuE;YACvE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACtC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,KAAK,EAAE,CAAC;oBAC9B,QAAQ,GAAG,CAAC,CAAC;oBACb,MAAM;gBACR,CAAC;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QAEE,CAAC;IACP,CAAC;CACF;AAnSD,sCAmSC;AAED;;;;;;;;;GASG;AACH,4BAA4B;AACf,QAAA,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview PDF Generation Module for Legal Markdown Documents
|
|
3
|
+
*
|
|
4
|
+
* This module provides functionality to convert processed Legal Markdown content
|
|
5
|
+
* into professional PDF documents using Puppeteer for HTML-to-PDF conversion.
|
|
6
|
+
* It builds upon the HTML generator to create print-ready documents with
|
|
7
|
+
* customizable formatting, page layouts, and styling options.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - HTML-to-PDF conversion using Puppeteer
|
|
11
|
+
* - Multiple page formats (A4, Letter, Legal)
|
|
12
|
+
* - Customizable margins and page orientation
|
|
13
|
+
* - Header and footer template support
|
|
14
|
+
* - Field highlighting for document review
|
|
15
|
+
* - Temporary file management and cleanup
|
|
16
|
+
* - Error handling and logging
|
|
17
|
+
* - Dual PDF generation (normal and highlighted versions)
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { pdfGenerator } from './pdf-generator';
|
|
22
|
+
*
|
|
23
|
+
* const pdf = await pdfGenerator.generatePdf(markdownContent, './output.pdf', {
|
|
24
|
+
* format: 'A4',
|
|
25
|
+
* landscape: false,
|
|
26
|
+
* includeHighlighting: true,
|
|
27
|
+
* margin: { top: '2cm', bottom: '2cm' }
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
import { HtmlGeneratorOptions } from './html-generator';
|
|
32
|
+
/**
|
|
33
|
+
* Configuration options for PDF generation
|
|
34
|
+
*
|
|
35
|
+
* @interface PdfGeneratorOptions
|
|
36
|
+
* @extends HtmlGeneratorOptions
|
|
37
|
+
*/
|
|
38
|
+
export interface PdfGeneratorOptions extends HtmlGeneratorOptions {
|
|
39
|
+
/** Page format for the PDF */
|
|
40
|
+
format?: 'A4' | 'Letter' | 'Legal';
|
|
41
|
+
/** Whether to use landscape orientation */
|
|
42
|
+
landscape?: boolean;
|
|
43
|
+
/** Page margins configuration */
|
|
44
|
+
margin?: {
|
|
45
|
+
/** Top margin (e.g., '1cm', '0.5in') */
|
|
46
|
+
top?: string;
|
|
47
|
+
/** Right margin (e.g., '1cm', '0.5in') */
|
|
48
|
+
right?: string;
|
|
49
|
+
/** Bottom margin (e.g., '1cm', '0.5in') */
|
|
50
|
+
bottom?: string;
|
|
51
|
+
/** Left margin (e.g., '1cm', '0.5in') */
|
|
52
|
+
left?: string;
|
|
53
|
+
};
|
|
54
|
+
/** Whether to display header and footer */
|
|
55
|
+
displayHeaderFooter?: boolean;
|
|
56
|
+
/** HTML template for page headers */
|
|
57
|
+
headerTemplate?: string;
|
|
58
|
+
/** HTML template for page footers */
|
|
59
|
+
footerTemplate?: string;
|
|
60
|
+
/** Whether to print background colors and images */
|
|
61
|
+
printBackground?: boolean;
|
|
62
|
+
/** Whether to prefer CSS page size over format option */
|
|
63
|
+
preferCSSPageSize?: boolean;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* PDF Generator for Legal Markdown Documents
|
|
67
|
+
*
|
|
68
|
+
* Converts processed Legal Markdown content into PDF documents using Puppeteer
|
|
69
|
+
* for HTML-to-PDF conversion. Provides comprehensive formatting options and
|
|
70
|
+
* supports both normal and highlighted document versions.
|
|
71
|
+
*
|
|
72
|
+
* @class PdfGenerator
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const generator = new PdfGenerator();
|
|
76
|
+
* const pdf = await generator.generatePdf(content, './output.pdf', {
|
|
77
|
+
* format: 'A4',
|
|
78
|
+
* includeHighlighting: true
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare class PdfGenerator {
|
|
83
|
+
private puppeteerOptions;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a new PDF generator instance
|
|
86
|
+
*
|
|
87
|
+
* @constructor
|
|
88
|
+
*/
|
|
89
|
+
constructor();
|
|
90
|
+
/**
|
|
91
|
+
* Generates a PDF document from Legal Markdown content
|
|
92
|
+
*
|
|
93
|
+
* This method orchestrates the complete PDF generation process:
|
|
94
|
+
* 1. Converts markdown to HTML using the HTML generator
|
|
95
|
+
* 2. Creates a temporary HTML file for Puppeteer
|
|
96
|
+
* 3. Launches a headless Chrome browser
|
|
97
|
+
* 4. Loads the HTML and generates PDF with specified options
|
|
98
|
+
* 5. Cleans up temporary files and browser resources
|
|
99
|
+
*
|
|
100
|
+
* @async
|
|
101
|
+
* @param {string} markdownContent - The processed Legal Markdown content
|
|
102
|
+
* @param {string} outputPath - Path where the PDF will be saved
|
|
103
|
+
* @param {PdfGeneratorOptions} [options={}] - Configuration options for PDF generation
|
|
104
|
+
* @returns {Promise<Buffer>} A promise that resolves to the PDF buffer
|
|
105
|
+
* @throws {Error} When PDF generation fails due to browser, file system, or processing errors
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const pdf = await generator.generatePdf(
|
|
109
|
+
* markdownContent,
|
|
110
|
+
* './contract.pdf',
|
|
111
|
+
* {
|
|
112
|
+
* format: 'A4',
|
|
113
|
+
* landscape: false,
|
|
114
|
+
* includeHighlighting: true,
|
|
115
|
+
* margin: { top: '2cm', bottom: '2cm' }
|
|
116
|
+
* }
|
|
117
|
+
* );
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
generatePdf(markdownContent: string, outputPath: string, options?: PdfGeneratorOptions): Promise<Buffer>;
|
|
121
|
+
/**
|
|
122
|
+
* Generate two PDF versions: one normal and one with highlighting
|
|
123
|
+
*
|
|
124
|
+
* This method creates two PDF versions of the same document:
|
|
125
|
+
* 1. A normal version without field highlighting
|
|
126
|
+
* 2. A highlighted version with field annotations
|
|
127
|
+
*
|
|
128
|
+
* This is useful for document review processes where both clean and
|
|
129
|
+
* annotated versions are needed for different purposes.
|
|
130
|
+
*
|
|
131
|
+
* @async
|
|
132
|
+
* @param {string} markdownContent - The processed Legal Markdown content
|
|
133
|
+
* @param {string} outputPath - Base path for PDF files (will be modified for each version)
|
|
134
|
+
* @param {PdfGeneratorOptions} [options={}] - Configuration options for PDF generation
|
|
135
|
+
* @returns {Promise<Object>} A promise that resolves to both PDF buffers
|
|
136
|
+
* @returns {Buffer} returns.normal - The normal PDF without highlighting
|
|
137
|
+
* @returns {Buffer} returns.highlighted - The highlighted PDF with field annotations
|
|
138
|
+
* @throws {Error} When PDF generation fails for either version
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* const { normal, highlighted } = await generator.generatePdfVersions(
|
|
142
|
+
* markdownContent,
|
|
143
|
+
* './contract.pdf',
|
|
144
|
+
* { format: 'A4' }
|
|
145
|
+
* );
|
|
146
|
+
* // Creates: contract.normal.pdf and contract.highlighted.pdf
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
generatePdfVersions(markdownContent: string, outputPath: string, options?: PdfGeneratorOptions): Promise<{
|
|
150
|
+
normal: Buffer;
|
|
151
|
+
highlighted: Buffer;
|
|
152
|
+
}>;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Singleton instance of PdfGenerator for convenient importing
|
|
156
|
+
*
|
|
157
|
+
* @constant {PdfGenerator} pdfGenerator
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* import { pdfGenerator } from './pdf-generator';
|
|
161
|
+
* const pdf = await pdfGenerator.generatePdf(content, './output.pdf');
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export declare const pdfGenerator: PdfGenerator;
|
|
165
|
+
//# sourceMappingURL=pdf-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdf-generator.d.ts","sourceRoot":"","sources":["../../src/generators/pdf-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;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