Skip to content

Enhance SYLink processing for improved plugin and block handling - #17843

Merged
Vanessa219 merged 6 commits into
siyuan-note:devfrom
Zuoqiu-Yingyi:fix/process-siyuan-link
Jun 22, 2026
Merged

Enhance SYLink processing for improved plugin and block handling#17843
Vanessa219 merged 6 commits into
siyuan-note:devfrom
Zuoqiu-Yingyi:fix/process-siyuan-link

Conversation

@Zuoqiu-Yingyi

@Zuoqiu-Yingyi Zuoqiu-Yingyi commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Description / 描述

English

Refactors SiYuan protocol URL handling across app/src/editor/openLink.ts and app/src/util/pathName.ts.

New utility:

  • Adds parseSiYuanUriBlockInfo(url) in pathName.ts — a single, tested parser that handles both siyuan: and web+siyuan: block URLs and returns a typed ISiYuanUriBlockInfo object (or null). Replaces the ad-hoc substring/regex extraction that was duplicated across getIdZoomInByPath and processSYLink.

Bugs fixed:

  1. Plugin name matching was too loose — the old code used startsWith(plugin.name) to find the target plugin, which would incorrectly match a plugin whose name is a prefix of another (e.g. plugin-abc matching against plugin-abcdef). The new code uses exact equality (=== plugin.name).

  2. Plugin name/tab-type segment was not URL-decoded — the pathname segment was used as-is without calling decodeURIComponent, causing matching to fail for plugin names containing percent-encoded characters. Error handling is added for malformed sequences.

  3. processSYLink rejected web+siyuan: URLs — only siyuan: was accepted. The protocol check is now unified with parseSiYuanUriBlockInfo.

  4. Circular dependencyopenByMobile was defined in protyle/util/compatibility.ts, which imported processSYLink from editor/openLink.ts (under #if MOBILE); meanwhile openLink.ts imported openByMobile back from compatibility.ts, forming a cycle:

    editor/openLink.ts
    → import "../protyle/util/compatibility" (openByMobile)
    → import "../../editor/openLink" (processSYLink)  💥
    

    The fix moves openByMobile into editor/openLink.ts and removes the processSYLink import from compatibility.ts. All downstream consumers (protyle/preview/index.ts, menus/commonMenuItem.ts, plugin/platformUtils.ts) are updated to import openByMobile from its new location.

Other improvements:

  • Extracts processSiYuanUriBlocks and processSiYuanUriPlugins as standalone exported functions.
  • Refactors getIdZoomInByPath to use parseSiYuanUriBlockInfo, removing duplicated substring-offset arithmetic.
  • Adds the ISiYuanUriBlockInfo interface to types/index.d.ts.
  • Changes import {App} to import type {App} in openLink.ts to break a type-level cycle through index.tsboot/onGetConfig.tsopenLink.ts.
中文

重构 app/src/editor/openLink.tsapp/src/util/pathName.ts 中的思源协议 URL 处理逻辑。

新增工具函数:

  • pathName.ts 中新增 parseSiYuanUriBlockInfo(url)——统一解析 siyuan:web+siyuan: 两种协议的块链接,返回类型化的 ISiYuanUriBlockInfo 对象(或 null)。替换了原先分散在 getIdZoomInByPathprocessSYLink 中重复的字符串偏移/正则提取逻辑。

缺陷修复:

  1. 插件名匹配过于宽松 — 旧代码使用 startsWith(plugin.name),当某个插件名是另一个插件名的前缀时会产生误匹配(如 plugin-abc 错误匹配 plugin-abcdef)。新代码改用精确相等(=== plugin.name)。

  2. 插件名/页签类型片段未进行 URL 解码 — 旧代码直接使用原始路径片段而未调用 decodeURIComponent,导致插件名含百分号编码字符时匹配失败。新代码增加了对畸形编码序列的错误处理。

  3. processSYLink 不支持 web+siyuan: 协议 — 旧代码只接受 siyuan:,协议校验现已与 parseSiYuanUriBlockInfo 统一。

  4. 循环依赖openByMobile 定义在 protyle/util/compatibility.ts 中,该文件在 #if MOBILE 条件下从 editor/openLink.ts 导入 processSYLink;而 openLink.ts 又从 compatibility.ts 导入 openByMobile,形成循环:

    editor/openLink.ts
    → import "../protyle/util/compatibility" (openByMobile)
    → import "../../editor/openLink" (processSYLink)  💥
    

    修复方式:将 openByMobile 移入 editor/openLink.ts,并从 compatibility.ts 中移除 processSYLink 的导入。所有下游消费方(protyle/preview/index.tsmenus/commonMenuItem.tsplugin/platformUtils.ts)均已更新为从新位置导入 openByMobile

其他改进:

  • processSiYuanUriBlocksprocessSiYuanUriPlugins 提取为独立的可导出函数。
  • 重构 getIdZoomInByPath,改用 parseSiYuanUriBlockInfo,消除了硬编码的字符串偏移量计算。
  • types/index.d.ts 中新增 ISiYuanUriBlockInfo 接口。
  • openLink.ts 中的 import {App} 改为 import type {App},打破通过 index.tsboot/onGetConfig.tsopenLink.ts 的类型级循环。

Type of change / 变更类型

  • Bug fix
    缺陷修复
  • Refactoring
    代码重构
  • New feature
    新功能
  • Text updates or new language additions
    修改文案或增加新语言

Checklist / 检查清单

  • I have performed a self-review of my own code
    我对自己的代码进行了自我审查
  • I have full rights to the submitted code and agree to license it under this project's AGPL-3.0 license
    我拥有所提交代码的完整权利,并同意其以本项目的 AGPL-3.0 许可证授权
  • PR is submitted to the dev branch and has no merge conflicts
    PR 提交到 dev 分支,并且没有合并冲突

@Zuoqiu-Yingyi
Zuoqiu-Yingyi marked this pull request as ready for review June 11, 2026 09:48
@Zuoqiu-Yingyi Zuoqiu-Yingyi changed the title 🎨 Enhance SYLink processing for improved plugin handling and bloc… Enhance SYLink processing for improved plugin and block handling Jun 11, 2026
@TCOTC

TCOTC commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

@Zuoqiu-Yingyi

Copy link
Copy Markdown
Contributor Author

@Vanessa219
这个 PR 是 #17847 的前置功能, 请尽快处理

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors processSYLink in app/src/editor/openLink.ts to improve routing/handling of siyuan:// URLs, especially for blocks and plugins hosts, and to fix correctness issues in plugin URL parsing/matching.

Changes:

  • Reorganizes protocol handling into switch (urlObj.hostname) with explicit "blocks" and "plugins" cases.
  • Tightens plugin matching for siyuan://plugins/... by using exact name equality and URL-decoding the path segment.
  • Refactors custom-tab data parsing to an IIFE and improves failure handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/src/editor/openLink.ts Outdated
@Zuoqiu-Yingyi

Copy link
Copy Markdown
Contributor Author

@Vanessa219
已修复完成 copilot 报告的问题

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

Comment thread app/src/editor/openLink.ts
Comment thread app/src/util/pathName.ts
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Zuoqiu-Yingyi

Copy link
Copy Markdown
Contributor Author

@Vanessa219
已修复报告的问题

@Zuoqiu-Yingyi
Zuoqiu-Yingyi marked this pull request as draft June 13, 2026 10:51
@Zuoqiu-Yingyi

Zuoqiu-Yingyi commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

原有实现存在循环依赖问题, 需要重构

  • editor/openLink.ts
    • import "../protyle/util/compatibility" (openByMobile)
      • import "../../editor/openLink" (processSYLink) 💥

@Zuoqiu-Yingyi
Zuoqiu-Yingyi deleted the fix/process-siyuan-link branch June 13, 2026 11:08
@Zuoqiu-Yingyi
Zuoqiu-Yingyi restored the fix/process-siyuan-link branch June 17, 2026 02:40
@Zuoqiu-Yingyi Zuoqiu-Yingyi reopened this Jun 17, 2026
@Zuoqiu-Yingyi
Zuoqiu-Yingyi marked this pull request as ready for review June 17, 2026 03:57
@Zuoqiu-Yingyi

Zuoqiu-Yingyi commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@Vanessa219
由于 App.eventBus 暂不支持, 因此 #17847 挂起, 先处理本 PR 的问题修复❤️

  • 已处理循环依赖问题
  • 已更新问题描述

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated no new comments.

@Vanessa219

Copy link
Copy Markdown
Member

这个是否需要再修改一下?

QQ_1781758189782

@Zuoqiu-Yingyi

Copy link
Copy Markdown
Contributor Author

这个是否需要再修改一下?

QQ_1781758189782

@Vanessa219
该问题是误报, 这个其实是与原有实现保持一致的

const focus = urlObj.searchParams.get("focus") === "1";

data.isZoomIn = getSearch("focus", SYURL) === "1";

@Vanessa219
Vanessa219 merged commit 129a9c2 into siyuan-note:dev Jun 22, 2026
@Vanessa219

Copy link
Copy Markdown
Member

哈哈哈哈哈
QQ_1782139495009

Vanessa219 added a commit that referenced this pull request Jun 22, 2026
Vanessa219 added a commit that referenced this pull request Jun 22, 2026
Vanessa219 added a commit that referenced this pull request Jun 22, 2026
@Vanessa219

Copy link
Copy Markdown
Member

3.7.0

Vanessa219 added a commit that referenced this pull request Jun 22, 2026
@Zuoqiu-Yingyi
Zuoqiu-Yingyi deleted the fix/process-siyuan-link branch June 23, 2026 13:24
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants