@oversk7/pi-web-dsh-style 1.3.1 → 1.3.2

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/web/markdown.ts CHANGED
@@ -60,7 +60,14 @@ parser.validateLink = (target) => Boolean(localFileLink(target)) || validateLink
60
60
  parser.renderer.rules.link_open = (tokens, index, options, env, renderer) => {
61
61
  const token = tokens[index];
62
62
  const target = String(token.attrGet("href") || "");
63
- const local = localFileLink(target, true);
63
+ let local = localFileLink(target, true);
64
+ if (local && typeof env?.cwd === "string" && !/^[A-Za-z]:[\\/]|^\\\\/.test(local.path)) {
65
+ const base = new URL("file:///");
66
+ base.pathname = `${env.cwd.replace(/\\/g, "/").replace(/%/g, "%25").replace(/\/+$/, "")}/`;
67
+ const relative = local.path.replace(/\\/g, "/").split("/").map(encodeURIComponent).join("/");
68
+ const resolved = new URL(relative, base);
69
+ local = localFileLink(`${resolved.href}${local.line ? `#L${local.line}` : ""}`) || local;
70
+ }
64
71
  if (local) {
65
72
  token.attrSet("href", local.href);
66
73
  token.attrJoin("class", "md-local-file");
@@ -121,6 +128,6 @@ parser.renderer.rules.task_checkbox = (tokens, index) => {
121
128
  return `<input type="checkbox" disabled${checked ? " checked" : ""} aria-label="${checked ? "已完成" : "未完成"}"/> `;
122
129
  };
123
130
 
124
- export function markdown(src: unknown): string {
125
- return parser.render(String(src ?? ""));
131
+ export function markdown(src: unknown, context: { cwd?: string } = {}): string {
132
+ return parser.render(String(src ?? ""), context);
126
133
  }