hdoc-tools 0.41.4 → 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.
Files changed (2) hide show
  1. package/hdoc-build.js +13 -8
  2. package/package.json +1 -1
package/hdoc-build.js CHANGED
@@ -98,6 +98,7 @@
98
98
  let includes_success = 0;
99
99
  let includes_failed = 0;
100
100
  let work_path_content = "";
101
+ let mermaid_images_path = "";
101
102
  let verbose = false;
102
103
 
103
104
  const pdf_path_excluded = (relative_path) => {
@@ -532,7 +533,9 @@
532
533
  if (lang === "mermaid" && process.env.GITHUB_ACTIONS !== 'true') {
533
534
  try {
534
535
  const tmpInput = tmp.fileSync({ postfix: ".mmd" });
535
- 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}`
536
539
 
537
540
  if (!str.startsWith('---')) {
538
541
  str = '---\n' + fs.readFileSync(mermaid_theme_path, {encoding: 'utf-8'}) + `\n---\n${str}`;
@@ -544,20 +547,19 @@
544
547
  if (process.platform === "win32") {
545
548
  cmd = `"${cmd}.cmd"`;
546
549
  }
547
- cmd = `${cmd} -i "${tmpInput.name}" -o "${tmpOutput.name}" --backgroundColor transparent --puppeteerConfigFile ${mermaid_puppeteer_config_path}`;
548
- 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}`);
549
554
  execSync(cmd);
550
555
 
551
- if (!fs.existsSync(tmpOutput.name)) {
556
+ if (!fs.existsSync(outputPath)) {
552
557
  throw new Error("mmdc did not generate output");
553
558
  }
554
559
 
555
- const svg = fs.readFileSync(tmpOutput.name, "utf8");
556
-
557
560
  tmpInput.removeCallback();
558
- tmpOutput.removeCallback();
559
561
 
560
- return `<div class="text-body">${svg}</div>`;
562
+ return `<img class="mermaid-diagram" src="${outputLink}" alt="Mermaid Diagram">`;
561
563
  } catch (err) {
562
564
  mermaid_failures.push({path: file_path.relativePath, error: err.message});
563
565
  return ``;
@@ -1327,6 +1329,9 @@
1327
1329
  process.exit(1);
1328
1330
  }
1329
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
+
1330
1335
  // Create MD5 hash of content before build
1331
1336
  console.log("Creating Hash...");
1332
1337
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hdoc-tools",
3
- "version": "0.41.4",
3
+ "version": "0.41.5",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {