# markdown_preview: Support anchor link for headings \(\#53184\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/b150663d45171d3a43b0b97f747ba65434b0eb0d)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: b150663d45171d3a43b0b97f747ba65434b0eb0d

Requested commit: b150663d45171d3a43b0b97f747ba65434b0eb0d

Commit: b150663d45171d3a43b0b97f747ba65434b0eb0d

Tree: f70c06e5fab1175b313ecad9fe39a652ec35f4f1

Author: Dong

Committer: GitHub

## Message

```
markdown_preview: Support anchor link for headings (#53184)

## What does this PR did

- Generate [GitHub-flavored heading
slugs](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#section-links)
for markdown headings
- Handle `[label](#heading)` same-document anchor links that scroll the
preview and editor to the target heading
- Handle `[label](./file.md#heading)` cross-file anchor links that open
the file, scroll the preview, and move the editor cursor to the heading


https://github.com/user-attachments/assets/ecc468bf-bed0-4543-a988-703025a61bf8

## What to test

- [ ] Create a markdown file with `[Go to section](#section-name)`
links, verify clicking scrolls preview and editor
- [ ] Create two markdown files with cross-file links like `[See
other](./other.md#heading)`, verify file opens and preview scrolls to
heading
- [ ] Verify duplicate headings produce correct slugs (`heading`,
`heading-1`)
- [ ] Verify external URLs (`https://...`) are unaffected

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [ ] Performance impact has been considered and is acceptable

Closes #18699

Release Notes:

- Added support for anchor links for headings in Markdown Preview.

---------

Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
```

## Parents

- [55c02b45b336e49c72b1f49837f455228c66916f](https://git.cafe/gitcafe/zed/commit/55c02b45b336e49c72b1f49837f455228c66916f?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/b150663d45171d3a43b0b97f747ba65434b0eb0d?format=markdown)
