pict-docuserve 0.0.28 → 0.0.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pict-docuserve",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "description": "Pict Documentation Server - A single-page documentation viewer built on Pict",
5
5
  "main": "source/Pict-Application-Docuserve.js",
6
6
  "bin": {
@@ -34,7 +34,7 @@
34
34
  "pict-view": "^1.0.67"
35
35
  },
36
36
  "devDependencies": {
37
- "quackage": "^1.0.58"
37
+ "quackage": "^1.0.59"
38
38
  },
39
39
  "copyFilesSettings": {
40
40
  "whenFileExists": "overwrite"
@@ -56,6 +56,42 @@ class DocuserveDocumentationProvider extends libPictProvider
56
56
  };
57
57
  }
58
58
 
59
+ /**
60
+ * Create an image resolver closure for the content provider.
61
+ *
62
+ * Resolves relative image URLs against the directory of the document
63
+ * being rendered, so that images referenced with relative paths in
64
+ * markdown (e.g. `![graph](diagram.svg)`) resolve correctly even
65
+ * when the page uses hash-based routing.
66
+ *
67
+ * @param {string} pDocURL - The URL the markdown document was fetched from
68
+ * @returns {Function} An image resolver callback: (pSrc, pAlt) => resolvedSrc
69
+ */
70
+ _createImageResolver(pDocURL)
71
+ {
72
+ // Extract the directory portion of the document URL
73
+ let tmpBaseDir = '';
74
+ if (pDocURL)
75
+ {
76
+ let tmpLastSlash = pDocURL.lastIndexOf('/');
77
+ if (tmpLastSlash >= 0)
78
+ {
79
+ tmpBaseDir = pDocURL.substring(0, tmpLastSlash + 1);
80
+ }
81
+ }
82
+
83
+ return (pSrc, pAlt) =>
84
+ {
85
+ // Leave absolute URLs, data URIs, and root-relative paths unchanged
86
+ if (pSrc.match(/^https?:\/\//) || pSrc.match(/^data:/) || pSrc.match(/^\//))
87
+ {
88
+ return pSrc;
89
+ }
90
+ // Prepend the document's directory to make relative paths work
91
+ return tmpBaseDir + pSrc;
92
+ };
93
+ }
94
+
59
95
  /**
60
96
  * Load all documentation data sources: catalog, _cover.md, _sidebar.md.
61
97
  *
@@ -1286,7 +1322,7 @@ class DocuserveDocumentationProvider extends libPictProvider
1286
1322
  return tmpCallback('Document not found', this.getErrorPageHTML(pURL));
1287
1323
  }
1288
1324
 
1289
- let tmpHTML = this._ContentProvider.parseMarkdown(pMarkdown, this._createLinkResolver(pCurrentGroup, pCurrentModule, pCurrentDocPath));
1325
+ let tmpHTML = this._ContentProvider.parseMarkdown(pMarkdown, this._createLinkResolver(pCurrentGroup, pCurrentModule, pCurrentDocPath), this._createImageResolver(pURL));
1290
1326
  this._ContentCache[pURL] = tmpHTML;
1291
1327
  return tmpCallback(null, tmpHTML);
1292
1328
  })