定制 linkrobins/toc 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

linkrobins/toc

Composer 安装命令:

composer require linkrobins/toc

包简介

Auto-generated table of contents for Flarum posts. Builds anchors from Markdown headings (#, ##, ###) and renders an inline TOC at the top of each post that has 2+ headings.

README 文档

README

Auto-generated table of contents for Flarum posts. Builds anchors from Markdown headings (#, ##, ###) and renders an inline TOC at the top of each post that has two or more headings.

Works in two places out of the box:

  • Forum discussion posts (anywhere a .Post-body is rendered)
  • Link Robins Blog articles (.LinkRobinsBlog-post-body)

What it does

For every heading in a post, the extension:

  • Generates a stable, slugified id from the heading text
  • Inserts an invisible scroll anchor above the heading, so clicking a TOC link lands the heading at a comfortable position rather than pinned to the viewport top
  • Adds a click-to-copy affordance on the heading itself — clicking copies a deep link to the section

For each post with two or more headings, the extension prepends a compact "Contents" card listing every heading as a navigable link, indented by heading depth.

What it does NOT do

  • No BBCode for arbitrary anchors. Headings are anchors. If you want a heading-less anchor, add a heading.
  • No floating bottom-right overlay TOC. The inline-at-top-of-post TOC covers the same UX with much less DOM fragility.
  • No post-stream scroll synchronization or progress bars.

Installation

composer require linkrobins/toc
php flarum cache:clear

Enable from the admin extensions panel. No migrations.

Configuration

Two settings, both with sensible defaults:

Setting Default What
linkrobins-toc.max_depth 3 Highest heading level included in the TOC (1, 2, or 3)
linkrobins-toc.min_headings 2 TOC is hidden unless the post has at least this many headings

These currently have no admin UI — set them via the Flarum settings API or directly in the settings table. An admin panel can be added later if needed.

How heading ids are generated

Within a single post, ids are stable and predictable:

  • Heading text is lowercased, non-alphanumeric characters become dashes, repeating dashes collapse
  • Empty headings get a section fallback
  • Collisions inside the same post get -2, -3, suffixes
  • Discussion posts prefix the id with the post number (e.g. 3-introduction) so two posts on the same page don't fight over #introduction

The result is that linking to a section is just <post URL>#<id>. Hovering a heading shows a small link icon; clicking copies the URL.

License

MIT.

统计信息

  • 总下载量: 45
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: TypeScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固