Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能加个markdown toc的导航菜单实现吗 #48

Open
islongshiyu opened this issue Jan 28, 2021 · 6 comments
Open

能加个markdown toc的导航菜单实现吗 #48

islongshiyu opened this issue Jan 28, 2021 · 6 comments

Comments

@islongshiyu
Copy link

No description provided.

@yihui
Copy link
Owner

yihui commented Jan 28, 2021

技术上能,但我不能。不到 150 行代码的主题(天下可能仅此一家),意思是用户要么是极简主义者,要么是自己动手型。请二选一吧。

@islongshiyu
Copy link
Author

好的 感谢回复 我有一篇6W字的MD 滚动条很长 实在无奈

@yihui
Copy link
Owner

yihui commented Jan 28, 2021

这个功能我在 hugo-prose 主题中实现过:https://github.com/yihui/hugo-prose 但我主要是用 JavaScript 实现的,你要是不怕晕,可以从那边抄代码。预览:https://prose.yihui.org/about/

@jiacai2050
Copy link

节制是一件很难做到的事情,对 xmin 的现状比较满意,不满意的 DIY 就好了,不要破坏上游的简洁性。

@jiacai2050
Copy link

goodroot#25

这里有个方案,原来 hugo 已经把 TOC 都解析好了。没几行代码

@yihui
Copy link
Owner

yihui commented Sep 23, 2023

理论上就是一行代码,但 Hugo 自己的 .TableOfContents 变量有些小坑,主要是 goldmark 在生成目录上不够只能,比如默认从 h1 开始生成,而如果文中没有一级标题的话,它就会生成一个空的 <ul>;或者标题中含有链接的话,它在自动生成 ID 之前竟然不去掉 HTML 标签。这些坑要么用 JS 事后去填:https://github.com/yihui/misc.js/blob/main/js/fix-toc.js 要么自行全盘重写目录:https://github.com/yihui/misc.js/blob/main/js/toc.js

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

No branches or pull requests

3 participants