简体   繁体   English

如何在 GitLab wiki 中创建目录?

[英]How can I create a table of content in GitLab wiki?

I am a big fan of the __TOC__ that creates a table of content on a Wikimedia page.我是在维基媒体页面上创建目录的__TOC__的忠实粉丝。

Whenever you write things like this on a Wikimedia page:每当您在维基媒体页面上写下这样的内容时:

This is a page for my project

## Credits ##

bla bla

## License ##

bla bla

__TOC_ automagically creates a table of content that allows you to navigate through inner links of the page. __TOC_自动创建一个目录,允许您浏览页面的内部链接。

I noticed that this is somehow possible in GitHub wiki pages: How do I create some kind of table of content in GitHub wiki?我注意到这在 GitHub wiki 页面中是可能的:如何在 GitHub wiki 中创建某种目录? by using different tricks.通过使用不同的技巧。

However, I miss this feature in GitLab wiki pages.但是,我想念 GitLab wiki 页面中的这个功能。 Does it provide such functionality?它提供这样的功能吗?

So this exists!所以这个存在! I finally found a Merge Request in in the GitLab Community Edition: Replace Gollum [[_TOC_]] tag with result of TableOfContentsFilter我终于在 GitLab 社区版中找到了一个合并请求:用 TableOfContentsFilter 的结果替换 Gollum [[_TOC_]] 标签

As its name describes, to have a table of contents you need to write the following:顾名思义,要拥有目录,您需要编写以下内容:

[[_TOC_]]

All together, you can write something like:总之,您可以编写如下内容:

This is a page for my project

[[_TOC_]]

## Credits

bla bla

## License

bla bla

and will show like this:并将显示如下:

在此处输入图片说明

This is available from the GitLab 8.6 release as described in its milestone .这可以从GitLab 8.6 版本中获得,如其里程碑中所述

Try using {{< toc >}} on top of the document.尝试在文档顶部使用{{< toc >}} It should automatically generate the TOC for you.它应该会自动为您生成 TOC。

You can use either [TOC] or aforementioned [[_TOC_]] as described onthe link .您可以使用[TOC]或前面提到的[[_TOC_]] ,如链接中所述。

This should be easier with GitLab 15.3 (August 2022):使用GitLab 15.3 (2022 年 8 月)应该会更容易:

Visualize table of contents in the WYSIWYG wiki editor在 WYSIWYG wiki 编辑器中可视化目录

When you're editing a wiki page in the rich text WYSIWYG editor, you expect to see an accurate representation of the content as it will appear after it's published.当您在富文本 WYSIWYG 编辑器中编辑 wiki 页面时,您希望看到内容的准确表示,就像它在发布后出现的那样。
Some elements are too complex for plain text formatting, and require short codes or macros that generate content when the page is built.有些元素对于纯文本格式来说过于复杂,并且需要在构建页面时生成内容的短代码或宏。

A wiki's table of contents is one example: it generates a list from your page's subheadings, simplifying navigation of very long pages. wiki 的目录就是一个例子:它从页面的子标题生成一个列表,简化了很长页面的导航。
However, WYSIWYG page editing displayed a table of contents as a static placeholder block.但是,所见即所得页面编辑将目录显示为 static 占位符块。

GitLab 15.3 shows a visual representation of the Table of Contents in the WYSIWYG wiki editor . GitLab 15.3 显示了 WYSIWYG wiki 编辑器中目录的可视化表示

To add a table of contents while editing a page, select the plus (+) icon in the toolbar, then select Table of Contents .要在编辑页面时添加目录,请 select 工具栏中的加号 (+) 图标,然后 select Table of Contents
The table of contents updates in real time as you create and edit subheadings on the page, helping you monitor the outline of your longer wiki pages.当您在页面上创建和编辑子标题时,目录会实时更新,帮助您监控较长 wiki 页面的大纲。

See Documentation and Issue .请参阅文档问题

Should be something like this应该是这样的

 ##### Table of Contents  
[1.-First Topic](#first-topic)
[2.-Second Topic](#second-topic) 
[3.-Third Topic](#third_topic)

And then you will reference each on the same page by using然后您将通过使用在同一页面上引用每个

 <a name="first-topic"/>
 <a name="second-topic"/>
 <a name="third-topic"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM