pict-docuserve 0.0.8 → 0.0.10

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.8",
3
+ "version": "0.0.10",
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": {
@@ -18,7 +18,7 @@
18
18
  "build-docs": "npx quack build && npx quack copy && node source/cli/Docuserve-CLI-Run.js inject ./docs && node example_applications/build-examples.js stage-docs",
19
19
  "serve-docs": "node source/cli/Docuserve-CLI-Run.js serve ./docs",
20
20
  "serve-examples": "node example_applications/build-examples.js",
21
- "test": "echo \"Error: no test specified\" && exit 0",
21
+ "test": "npx mocha -u tdd --exit -R spec",
22
22
  "tests": "npx mocha -u tdd --exit -R spec --grep",
23
23
  "coverage": "npx nyc --reporter=lcov --reporter=text-lcov npx mocha -- -u tdd -R spec"
24
24
  },
@@ -33,6 +33,8 @@
33
33
  "pict-view": "^1.0.64"
34
34
  },
35
35
  "devDependencies": {
36
+ "chai": "^6.2.2",
37
+ "mocha": "^11.7.5",
36
38
  "quackage": "^1.0.47"
37
39
  },
38
40
  "copyFilesSettings": {
@@ -994,6 +994,57 @@ class DocuserveDocumentationProvider extends libPictProvider
994
994
  return null;
995
995
  }
996
996
 
997
+ /**
998
+ * Resolve a GitHub repository URL to an internal hash route.
999
+ *
1000
+ * If the URL matches a module in the loaded catalog, returns the
1001
+ * corresponding #/doc/ route so the link navigates within docuserve
1002
+ * instead of leaving to GitHub.
1003
+ *
1004
+ * @param {string} pURL - A GitHub URL (e.g. "https://github.com/stevenvelozo/fable")
1005
+ * @returns {string|null} The hash route (e.g. "#/doc/fable/fable") or null if not a catalog module
1006
+ */
1007
+ resolveGitHubURLToRoute(pURL)
1008
+ {
1009
+ if (!this._Catalog || !this._Catalog.Groups || !pURL)
1010
+ {
1011
+ return null;
1012
+ }
1013
+
1014
+ // Match https://github.com/{org}/{repo} with optional trailing path/slash
1015
+ let tmpMatch = pURL.match(/^https?:\/\/github\.com\/([^/]+)\/([^/]+)/);
1016
+ if (!tmpMatch)
1017
+ {
1018
+ return null;
1019
+ }
1020
+
1021
+ let tmpOrg = tmpMatch[1];
1022
+ let tmpRepo = tmpMatch[2];
1023
+
1024
+ // Only resolve URLs that match the catalog's GitHub org
1025
+ if (tmpOrg !== this._Catalog.GitHubOrg)
1026
+ {
1027
+ return null;
1028
+ }
1029
+
1030
+ // Search catalog for a module with a matching Repo
1031
+ for (let i = 0; i < this._Catalog.Groups.length; i++)
1032
+ {
1033
+ let tmpGroup = this._Catalog.Groups[i];
1034
+
1035
+ for (let j = 0; j < tmpGroup.Modules.length; j++)
1036
+ {
1037
+ let tmpModule = tmpGroup.Modules[j];
1038
+ if (tmpModule.Repo === tmpRepo)
1039
+ {
1040
+ return '#/doc/' + tmpGroup.Key + '/' + tmpModule.Name;
1041
+ }
1042
+ }
1043
+ }
1044
+
1045
+ return null;
1046
+ }
1047
+
997
1048
  /**
998
1049
  * Get the module-specific sidebar entries for a given group/module.
999
1050
  *
@@ -1435,6 +1486,12 @@ class DocuserveDocumentationProvider extends libPictProvider
1435
1486
  let tmpRoute = this.convertDocLink(pHref, pCurrentGroup, pCurrentModule, pCurrentDocPath);
1436
1487
  return '<a href="' + tmpRoute + '">' + pLinkText + '</a>';
1437
1488
  }
1489
+ // Check if this is a GitHub URL that matches a catalog module
1490
+ let tmpCatalogRoute = this.resolveGitHubURLToRoute(pHref);
1491
+ if (tmpCatalogRoute)
1492
+ {
1493
+ return '<a href="' + tmpCatalogRoute + '">' + pLinkText + '</a>';
1494
+ }
1438
1495
  return '<a href="' + pHref + '" target="_blank" rel="noopener">' + pLinkText + '</a>';
1439
1496
  });
1440
1497