hdoc-tools 0.41.4 → 0.41.6

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
@@ -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.6",
4
4
  "description": "Hornbill HDocBook Development Support Tool",
5
5
  "main": "hdoc.js",
6
6
  "bin": {
@@ -51,16 +51,27 @@ api-param-name {
51
51
  font-style: italic;
52
52
  font-weight: 600;
53
53
  }
54
+
54
55
  api-param-optional:before {
55
56
  content: "Optional [default=";
56
57
  font-style: normal;
57
58
  font-weight: 400;
58
59
  }
60
+
59
61
  api-param-optional:after {
60
- font-style: normal;
61
62
  content: "]";
63
+ font-style: normal;
62
64
  font-weight: 400;
63
65
  }
66
+
67
+ /* If no default provided */
68
+ api-param-optional[no-default-value]:before {
69
+ content: "Optional";
70
+ }
71
+
72
+ api-param-optional[no-default-value]:after {
73
+ content: "";
74
+ }
64
75
 
65
76
  /* API parameter description block */
66
77
  api-param-desc {
package/ui/index.html CHANGED
@@ -47,6 +47,16 @@
47
47
  }
48
48
  customElements.define("api-param-name", APIParamName);
49
49
 
50
+ class ApiParamOptional extends HTMLElement {
51
+ connectedCallback() {
52
+ const text = (this.textContent || '').trim();
53
+ if (!text) {
54
+ this.innerHTML = ''; // remove content
55
+ this.setAttribute('no-default-value', '');
56
+ }
57
+ }
58
+ }
59
+ customElements.define('api-param-optional', ApiParamOptional);
50
60
 
51
61
  var ThemePreference = localStorage.getItem('hdocbook-theme-appearance') || '';
52
62
  const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
@@ -258,8 +258,12 @@ function loadContentUrl(
258
258
  fromPopState,
259
259
  fromBook = true,
260
260
  ) {
261
-
262
-
261
+ let downloadFile = false;
262
+ if (linkRef.includes('_books/')) {
263
+ downloadFile = linkRef.split('').length > 1;
264
+ console.log('downloadFile', downloadFile);
265
+ }
266
+
263
267
  //-- clear table of contents
264
268
  view.docApp.tableOfContents = [];
265
269
  let clean_linkRef = linkRef;
@@ -271,23 +275,30 @@ function loadContentUrl(
271
275
  clean_linkRef = removeTrailingSlash(clean_linkRef);
272
276
  //-- remove starting / if link starts with it
273
277
  clean_linkRef = removeStartingSlash(clean_linkRef);
274
-
275
- //-- update url in browser
276
- if (fromBook)
277
- setBrowserViewUrl(clean_linkRef, {}, fromPageRefresh, fromPopState);
278
- //-- destroy any existing content children and events properly
279
- jqContentContainer.empty();
280
- jqDocumentHeader.find(".document-title").empty();
281
-
282
- //-- for now just load whatever the href prop is (we can add actions to perform specific processing and then load content based on element atts etc)
283
- let frontmatterData = {};
278
+
284
279
  let booksLinkRef = clean_linkRef;
285
280
  if (fromBook) {
286
281
  booksLinkRef = clean_linkRef.includes("_books/")
287
282
  ? clean_linkRef
288
283
  : `_books/${clean_linkRef}`;
289
284
  }
290
- fetch(booksLinkRef)
285
+
286
+ if (downloadFile) {
287
+ //-- open in new tab to download
288
+ window.open(booksLinkRef, '_blank');
289
+ } else {
290
+ //-- update url in browser
291
+ if (fromBook) {
292
+ setBrowserViewUrl(clean_linkRef, {}, fromPageRefresh, fromPopState);
293
+ }
294
+
295
+ //-- destroy any existing content children and events properly
296
+ jqContentContainer.empty();
297
+ jqDocumentHeader.find(".document-title").empty();
298
+
299
+ //-- for now just load whatever the href prop is (we can add actions to perform specific processing and then load content based on element atts etc)
300
+ let frontmatterData = {};
301
+ fetch(booksLinkRef)
291
302
  .then((response) => {
292
303
  if (response.headers.has("X-frontmatter")) {
293
304
  frontmatterData = response.headers.get("X-frontmatter");
@@ -417,6 +428,8 @@ function loadContentUrl(
417
428
 
418
429
  listenForHrefClicks();
419
430
  });
431
+ }
432
+
420
433
  }
421
434
 
422
435
  function setGitHubBookUrl(linkRef) {
@@ -625,6 +638,7 @@ Vue.component("nav-section-component", {
625
638
  },
626
639
  });
627
640
 
641
+
628
642
  const hslDocLog = {
629
643
  _entry: [],
630
644
  log: function (strMessage, varData) {