Skip to content

Use github-slugger in place of slug - #373

Open
LanHikari22 wants to merge 3 commits into
zoni:mainfrom
LanHikari22:fix-370-github-header-id-compliance
Open

LanHikari22 wants to merge 3 commits into
zoni:mainfrom
LanHikari22:fix-370-github-header-id-compliance

Conversation

@LanHikari22

Copy link
Copy Markdown

As explained in #370, if there are periods used in the heading and it is referenced, then obsidian-export generates invalid links.

Added gfm-heading-ids-compliance test to reproduce the issue in #370.

Cargo.lock is also added to .gitignore as it is autogenerated.

Closes #370.

This passes all pre-commit hook checks.

Please let me know if there is a use-case for using slug that I may be missing. Replacing it with github-slugger passes all tests, as is.

You can find my notes for this here.

As explained in zoni#370, if there are periods used in the heading and
it is referenced, then obsidian-export generates invalid links.

Added gfm-heading-ids-compliance test to reproduce the issue in zoni#370.

Cargo.lock is also added to .gitignore as it is autogenerated.

Closes zoni#370.
When adding a new changelog fragment, uv [1] is required to be
installed, but this is not mentioned in the document.

[1]: https://github.com/astral-sh/uv
@LanHikari22

Copy link
Copy Markdown
Author

I learned that in the cargo-toml-vs-cargo-lock docs that in general Cargo.lock should be tracked, so I am reverting adding it to .gitignore here.

ONEGAYI added a commit to ONEGAYI/obsidian-export-desktop that referenced this pull request Aug 24, 2026
format_anchor 弃用手写 slug 实现,改委托 github-slugger crate(与上游
PR zoni#373 同款路线),修复四处与 GitHub/VS Code 预览行为的偏差:

- 全角标点(:,)此前原样保留进锚点,链接在 GitHub/VS Code 上断裂;
  现无痕剔除([[note#总纲:三份形态,两个断口]] → #总纲三份形态两个断口)
- 标点剔除不再误产连字符(1.1.1 C → zoni#111-c 而非 #1-1-1-c,
  即上游 zoni#370 的 Number Headings 场景)
- 连续连字符不再折叠(this--or-that 保持原样)
- 首尾连字符不再修剪(-dashed- 保持原样)

行为向量取自 2026-08 对 GitHub 网页渲染的实测(secret gist 抓取
SSR anchor href,与 VS Code 官方包源码、github-slugger 本地计算三方
一致);封装层对 section 先 trim,对齐 VS Code 预览的首尾空白处理。
链接显示文本不受影响,仅 #anchor 部分变化。

契约测试:lib 内 test_format_anchor_matches_github_slugger 锁定全部
实测向量;chinese-anchor fixture 扩展全角标点标题的端到端断言。
已知限制:GitHub 对同文档重复标题的 -1/-2 去重后缀需要文档级状态,
本实现无状态、不做去重。

Close zoni#370(上游)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Links to numbered headers don't work in github view

1 participant