| 138 | } |
| 139 | |
| 140 | export function hrefToRef(href: string): WikiRef | null { |
| 141 | if (!href.startsWith("#kbref:")) return null; |
| 142 | try { |
| 143 | const json = decodeURIComponent(href.slice("#kbref:".length)); |
| 144 | const obj = JSON.parse(json); |
| 145 | if (typeof obj !== "object" || !obj || typeof obj.path !== "string") return null; |
| 146 | return { |
| 147 | path: obj.path, |
| 148 | anchor: typeof obj.anchor === "string" ? obj.anchor : null, |
| 149 | isBlock: obj.isBlock === true, |
| 150 | alias: typeof obj.alias === "string" ? obj.alias : null, |
| 151 | }; |
| 152 | } catch { |
| 153 | return null; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * 把 markdown 文本里的 [[wiki/...]] 替换成标准 markdown 链接 `[text](#kbref:...)`, |