gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.37k stars 7.43k forks source link

Add config setting to replace native reStructuredText table of contents with Hugo's .TableOfContents #9871

Open bzgec opened 2 years ago

bzgec commented 2 years ago

Is there a preserveTOC option for rst (as is for asciidoc)?

If not, would it be worth to implement it?

jmooring commented 2 years ago

The TOC is preserved by default.

This .rst document

.. contents::

Section 1
=========

Section 2
=========

is rendered as:

<div class="document">
  <div class="contents topic" id="contents">
    <p class="topic-title">Contents</p>
    <ul class="simple">
      <li>
        <a class="reference internal" href="#section-1" id="id1">Section 1</a>
      </li>
      <li>
        <a class="reference internal" href="#section-2" id="id2">Section 2</a>
      </li>
    </ul>
  </div>
  <div class="section" id="section-1">
    <h2><a class="toc-backref" href="#id1">Section 1</a></h2>
  </div>
  <div class="section" id="section-2">
    <h2><a class="toc-backref" href="#id2">Section 2</a></h2>
  </div>
</div>
bzgec commented 2 years ago

Yes, but I would like to set preserveTOC: false and use built-in variable .TableOfContents.