honkit 6.0.1 → 6.0.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"annotateText.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/annotateText.ts"],"names":[],"mappings":"AAwDA;;;;;;GAMG;AACH,iBAAS,YAAY,CAAC,OAAO,KAAA,EAAE,gBAAgB,KAAA,EAAE,CAAC,KAAA,QAqBjD;AAED,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"annotateText.d.ts","sourceRoot":"","sources":["../../../src/output/modifiers/annotateText.ts"],"names":[],"mappings":"AAyDA;;;;;;GAMG;AACH,iBAAS,YAAY,CAAC,OAAO,KAAA,EAAE,gBAAgB,KAAA,EAAE,CAAC,KAAA,QA4BjD;AAED,eAAe,YAAY,CAAC"}
@@ -20,14 +20,15 @@ function replaceText($, el, search, replace, text_only) {
20
20
  // Loop over all childNodes.
21
21
  while (node) {
22
22
  // Only process text nodes.
23
- if (node.nodeType === 3) {
23
+ if (node.nodeType === 3 && node.nodeValue) {
24
24
  // The original node value.
25
25
  val = node.nodeValue;
26
26
  new_val = val.replace(search, replace);
27
27
  // Only replace text if the new value is actually different!
28
28
  if (new_val !== val) {
29
29
  if (!text_only && /</.test(new_val)) {
30
- // The new value contains HTML, set it in a slower but far more // robust way.
30
+ // The new value contains HTML, set it in a slower but far more
31
+ // robust way.
31
32
  // Don't remove the node yet, or the loop will lose its place.
32
33
  const currentTextNode = $(node);
33
34
  const newHTML = val.replace(val, new_val);
@@ -64,16 +65,21 @@ function annotateText(entries, glossaryFilePath, $) {
64
65
  entries.forEach((entry) => {
65
66
  const entryId = entry.getID();
66
67
  const name = entry.getName();
68
+ const nameLowerCase = `${name}`.toLowerCase();
69
+ const quotedName = pregQuote(nameLowerCase);
70
+ const nameCleaned = nameLowerCase.replace(/[^\w\s]/, "");
71
+ const searchRegex = nameLowerCase === nameCleaned
72
+ ? new RegExp(`\\b(${quotedName})\\b`, "gi")
73
+ : new RegExp(`(?:\\s*)(${quotedName})(?:\\s*)`, "gi");
67
74
  const description = entry.getDescription();
68
- const searchRegex = new RegExp(`\\b(${pregQuote(name.toLowerCase())})\\b`, "gi");
69
75
  $("*").each(function () {
70
76
  const $this = $(this);
71
77
  if ($this.is(ANNOTATION_IGNORE) || $this.parents(ANNOTATION_IGNORE).length > 0)
72
78
  return;
73
79
  // @ts-expect-error ts-migrate(2554) FIXME: Expected 5 arguments, but got 4.
74
- replaceText($, this, searchRegex, (match) => {
80
+ replaceText($, this, searchRegex, (match, matchedTerm) => {
75
81
  return (`<a href="/${glossaryFilePath}#${entryId}" ` +
76
- `class="glossary-term" title="${(0, escape_html_1.default)(description)}">${match}</a>`);
82
+ `class="glossary-term" title="${(0, escape_html_1.default)(description)}">${matchedTerm}</a>`);
77
83
  });
78
84
  });
79
85
  });
@@ -21,6 +21,6 @@ export declare class PluginResolver {
21
21
  * @param {string} packageName
22
22
  * @returns {string} return path to module
23
23
  */
24
- resolvePluginPackageName(packageName: any): any;
24
+ resolvePluginPackageName(packageName: any): string;
25
25
  }
26
26
  //# sourceMappingURL=PluginResolver.d.ts.map
@@ -30,7 +30,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.PluginResolver = void 0;
31
31
  const path_1 = __importDefault(require("path"));
32
32
  const util = __importStar(require("./package-name-util"));
33
- const try_resolve_1 = __importDefault(require("try-resolve"));
33
+ const path_2 = __importDefault(require("../utils/path"));
34
34
  const SPECIAL_PACKAGE_NAME = [
35
35
  "fontsettings", // → @honkit/honkit-plugin-fontsettings
36
36
  "highlight", // → @honkit/honkit-plugin-highlight
@@ -71,11 +71,11 @@ class PluginResolver {
71
71
  // e.g.) load theme-default as @honkit/honkit-plugins-theme-default
72
72
  const honkitScopePackageName = `@honkit/${honkitFullPackageName}`;
73
73
  // In sometimes, HonKit package has not main field - so search package.json
74
- const pkgPath = (0, try_resolve_1.default)(path_1.default.join(baseDir, honkitFullPackageName, "/package.json")) ||
75
- (0, try_resolve_1.default)(path_1.default.join(baseDir, gitbookFullPackageName, "/package.json")) ||
76
- (0, try_resolve_1.default)(path_1.default.join(baseDir, packageName, "/package.json")) ||
74
+ const pkgPath = path_2.default.tryResolve(path_1.default.join(baseDir, honkitFullPackageName, "/package.json")) ||
75
+ path_2.default.tryResolve(path_1.default.join(baseDir, gitbookFullPackageName, "/package.json")) ||
76
+ path_2.default.tryResolve(path_1.default.join(baseDir, packageName, "/package.json")) ||
77
77
  (SPECIAL_PACKAGE_NAME.includes(packageName) &&
78
- (0, try_resolve_1.default)(path_1.default.join(baseDir, honkitScopePackageName, "/package.json")));
78
+ path_2.default.tryResolve(path_1.default.join(baseDir, honkitScopePackageName, "/package.json")));
79
79
  if (!pkgPath) {
80
80
  throw new ReferenceError(`Failed to load HonKit's plugin module: "${packageName}" is not found.
81
81
 
@@ -3,12 +3,19 @@ declare function isInRoot(root: any, filename: any): boolean;
3
3
  declare function resolveInRoot(root: any): string;
4
4
  declare function setExtension(filename: any, ext: any): string;
5
5
  declare function isPureRelative(filename: any): boolean;
6
+ /**
7
+ * Try to resolve package name
8
+ * if `packageName` is found, return resolved absolute path.
9
+ * if `packageName` is not found, return `undefined`
10
+ **/
11
+ declare function tryResolve(packageName: string): string | undefined;
6
12
  declare const _default: {
7
13
  isInRoot: typeof isInRoot;
8
14
  resolveInRoot: typeof resolveInRoot;
9
15
  normalize: typeof normalizePath;
10
16
  setExtension: typeof setExtension;
11
17
  isPureRelative: typeof isPureRelative;
18
+ tryResolve: typeof tryResolve;
12
19
  };
13
20
  export default _default;
14
21
  //# sourceMappingURL=path.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":"AAIA,iBAAS,aAAa,CAAC,QAAQ,KAAA,UAE9B;AAGD,iBAAS,QAAQ,CAAC,IAAI,KAAA,EAAE,QAAQ,KAAA,WAY/B;AAID,iBAAS,aAAa,CAAC,IAAI,KAAA,UAkB1B;AAGD,iBAAS,YAAY,CAAC,QAAQ,KAAA,EAAE,GAAG,KAAA,UAElC;AAQD,iBAAS,cAAc,CAAC,QAAQ,KAAA,WAE/B;;;;;;;;AAED,wBAME"}
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":"AAIA,iBAAS,aAAa,CAAC,QAAQ,KAAA,UAE9B;AAGD,iBAAS,QAAQ,CAAC,IAAI,KAAA,EAAE,QAAQ,KAAA,WAY/B;AAID,iBAAS,aAAa,CAAC,IAAI,KAAA,UAkB1B;AAGD,iBAAS,YAAY,CAAC,QAAQ,KAAA,EAAE,GAAG,KAAA,UAElC;AAQD,iBAAS,cAAc,CAAC,QAAQ,KAAA,WAE/B;AAED;;;;IAII;AACJ,iBAAS,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAM3D;;;;;;;;;AAED,wBAOE"}
package/lib/utils/path.js CHANGED
@@ -40,7 +40,7 @@ function resolveInRoot(root) {
40
40
  }
41
41
  return result;
42
42
  }
43
- // Chnage extension of a file
43
+ // Change extension of a file
44
44
  function setExtension(filename, ext) {
45
45
  return path_1.default.join(path_1.default.dirname(filename), path_1.default.basename(filename, path_1.default.extname(filename)) + ext);
46
46
  }
@@ -53,10 +53,24 @@ function setExtension(filename, ext) {
53
53
  function isPureRelative(filename) {
54
54
  return filename.indexOf("./") === 0 || filename.indexOf("../") === 0;
55
55
  }
56
+ /**
57
+ * Try to resolve package name
58
+ * if `packageName` is found, return resolved absolute path.
59
+ * if `packageName` is not found, return `undefined`
60
+ **/
61
+ function tryResolve(packageName) {
62
+ try {
63
+ return require.resolve(packageName);
64
+ }
65
+ catch {
66
+ return undefined;
67
+ }
68
+ }
56
69
  exports.default = {
57
70
  isInRoot: isInRoot,
58
71
  resolveInRoot: resolveInRoot,
59
72
  normalize: normalizePath,
60
73
  setExtension: setExtension,
61
- isPureRelative: isPureRelative
74
+ isPureRelative: isPureRelative,
75
+ tryResolve: tryResolve
62
76
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "honkit",
3
- "version": "6.0.1",
3
+ "version": "6.0.3",
4
4
  "description": "HonKit is building beautiful books using Markdown.",
5
5
  "keywords": [
6
6
  "git",
@@ -37,12 +37,12 @@
37
37
  "updateSnapshot": "jest src -u"
38
38
  },
39
39
  "dependencies": {
40
- "@honkit/asciidoc": "6.0.1",
41
- "@honkit/honkit-plugin-fontsettings": "6.0.1",
42
- "@honkit/honkit-plugin-highlight": "6.0.1",
43
- "@honkit/honkit-plugin-theme-default": "6.0.1",
44
- "@honkit/html": "6.0.1",
45
- "@honkit/markdown-legacy": "6.0.1",
40
+ "@honkit/asciidoc": "6.0.3",
41
+ "@honkit/honkit-plugin-fontsettings": "6.0.3",
42
+ "@honkit/honkit-plugin-highlight": "6.0.3",
43
+ "@honkit/honkit-plugin-theme-default": "6.0.3",
44
+ "@honkit/html": "6.0.3",
45
+ "@honkit/markdown-legacy": "6.0.3",
46
46
  "bash-color": "^0.0.4",
47
47
  "cheerio": "^1.0.0",
48
48
  "chokidar": "^3.6.0",
@@ -86,11 +86,10 @@
86
86
  "send": "^0.17.2",
87
87
  "tiny-lr": "^1.1.1",
88
88
  "tmp": "0.0.28",
89
- "try-resolve": "^1.0.1",
90
89
  "urijs": "^1.19.11"
91
90
  },
92
91
  "devDependencies": {
93
- "@honkit/internal-test-utils": "6.0.1",
92
+ "@honkit/internal-test-utils": "6.0.3",
94
93
  "@relmify/jest-serializer-strip-ansi": "^1.0.2",
95
94
  "@types/jest": "^29.5.13",
96
95
  "@types/node": "^22.7.4",
@@ -101,5 +100,5 @@
101
100
  "rimraf": "^3.0.2",
102
101
  "typescript": "^5.6.2"
103
102
  },
104
- "gitHead": "8a67601b23ce480bce2bd1a8fb787f1f6f56656f"
103
+ "gitHead": "608191107875c3d613840d702b76a9888992d7bc"
105
104
  }