hdoc-tools 0.41.3 → 0.41.5

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/hdoc-build.js CHANGED
@@ -18,33 +18,41 @@
18
18
 
19
19
  const h_tags_to_search = ["h1", "h2", "h3"];
20
20
  const image_extensions = ["png", "svg", "jpg"];
21
- const doc_header_template_path = path.join(
21
+
22
+ const templates_path = path.join(
22
23
  __dirname,
23
- "templates",
24
+ "templates"
25
+ );
26
+ const doc_header_template_path = path.join(
27
+ templates_path,
24
28
  "doc-header.html",
25
29
  );
26
30
  const non_git_doc_header_template_path = path.join(
27
- __dirname,
28
- "templates",
31
+ templates_path,
29
32
  "doc-header-non-git.html",
30
33
  );
31
34
  const pdf_header_template_path = path.join(
32
- __dirname,
33
- "templates",
35
+ templates_path,
34
36
  "pdf-header.html",
35
37
  );
36
38
  const non_git_pdf_header_template_path = path.join(
37
- __dirname,
38
- "templates",
39
+ templates_path,
39
40
  "pdf-header-non-git.html",
40
41
  );
41
42
 
42
43
  const mermaid_theme_path = path.resolve(
43
- __dirname,
44
- "templates",
44
+ templates_path,
45
45
  "mermaid-theme.yaml",
46
46
  );
47
47
 
48
+ let mermaid_puppeteer_config_path = path.resolve(
49
+ templates_path,
50
+ "mermaid-puppeteer-config.json",
51
+ );
52
+ if (process.platform === "win32") {
53
+ mermaid_puppeteer_config_path = `"${mermaid_puppeteer_config_path}"`
54
+ }
55
+
48
56
  const pdf_template_path = path.join(__dirname, "templates", "pdf");
49
57
  const ui_css_path = path.join(__dirname, "ui", "css");
50
58
  const pdf_template_file_path = path.join(pdf_template_path, "template.html");
@@ -90,6 +98,7 @@
90
98
  let includes_success = 0;
91
99
  let includes_failed = 0;
92
100
  let work_path_content = "";
101
+ let mermaid_images_path = "";
93
102
  let verbose = false;
94
103
 
95
104
  const pdf_path_excluded = (relative_path) => {
@@ -524,34 +533,33 @@
524
533
  if (lang === "mermaid" && process.env.GITHUB_ACTIONS !== 'true') {
525
534
  try {
526
535
  const tmpInput = tmp.fileSync({ postfix: ".mmd" });
527
- const tmpOutput = tmp.fileSync({ postfix: ".svg" });
536
+ const outputFileName = `mermaid-${crypto.createHash("sha256").update(str).digest("hex").slice(0, 16)}.svg`;
537
+ const outputPath = path.join(mermaid_images_path, outputFileName);
538
+ const outputLink = `/_books/${doc_id}/mermaid-images/${outputFileName}`
528
539
 
529
- /*
530
540
  if (!str.startsWith('---')) {
531
541
  str = '---\n' + fs.readFileSync(mermaid_theme_path, {encoding: 'utf-8'}) + `\n---\n${str}`;
532
542
  }
533
- */
534
543
 
535
544
  fs.writeFileSync(tmpInput.name, str);
536
545
  let cmd = `${__dirname}/node_modules/.bin/mmdc`;
537
546
 
538
547
  if (process.platform === "win32") {
539
- cmd = `"${cmd}"`;
548
+ cmd = `"${cmd}.cmd"`;
540
549
  }
541
- cmd = `${cmd} -i "${tmpInput.name}" -o "${tmpOutput.name}" --quiet --backgroundColor transparent`;
542
- console.log(`Generating Inline Mermaid SVG found in: ${file_path.relativePath}`);
550
+
551
+
552
+ cmd = `${cmd} -i "${tmpInput.name}" -o "${outputPath}" --backgroundColor transparent --puppeteerConfigFile ${mermaid_puppeteer_config_path}`;
553
+ console.log(`Generating Mermaid SVG found in ${file_path.relativePath} - ${outputPath}`);
543
554
  execSync(cmd);
544
555
 
545
- if (!fs.existsSync(tmpOutput.name)) {
556
+ if (!fs.existsSync(outputPath)) {
546
557
  throw new Error("mmdc did not generate output");
547
558
  }
548
559
 
549
- const svg = fs.readFileSync(tmpOutput.name, "utf8");
550
-
551
560
  tmpInput.removeCallback();
552
- tmpOutput.removeCallback();
553
561
 
554
- return `<div class="text-body">${svg}</div>`;
562
+ return `<img class="mermaid-diagram" src="${outputLink}" alt="Mermaid Diagram">`;
555
563
  } catch (err) {
556
564
  mermaid_failures.push({path: file_path.relativePath, error: err.message});
557
565
  return ``;
@@ -1321,6 +1329,9 @@
1321
1329
  process.exit(1);
1322
1330
  }
1323
1331
 
1332
+ mermaid_images_path = path.join(work_path_content, 'mermaid-images');
1333
+ if (!fs.existsSync(mermaid_images_path)) fs.mkdirSync(mermaid_images_path);
1334
+
1324
1335
  // Create MD5 hash of content before build
1325
1336
  console.log("Creating Hash...");
1326
1337
 
package/hdoc-serve.js CHANGED
@@ -137,11 +137,9 @@
137
137
  const tmpInput = tmp.fileSync({ postfix: ".mmd" });
138
138
  const tmpOutput = tmp.fileSync({ postfix: ".svg" });
139
139
 
140
- /*
141
140
  if (!str.startsWith('---')) {
142
141
  str = '---\n' + fs.readFileSync(mermaid_theme_path, {encoding: 'utf-8'}) + `\n---\n${str}`;
143
142
  }
144
- */
145
143
 
146
144
  fs.writeFileSync(tmpInput.name, str);
147
145
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.41.3",
3
+ "version": "0.41.5",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {
@@ -0,0 +1,6 @@
1
+ {
2
+ "args": [
3
+ "--no-sandbox",
4
+ "--disable-gpu"
5
+ ]
6
+ }