php-textile icon indicating copy to clipboard operation
php-textile copied to clipboard

TOC

Open jsoo opened this issue 14 years ago • 6 comments

The addition of notelist. suggests doing something similar for a table of contents based on header IDs. Rather than trying to make a proper nested list out of it, an expedient hack would be to give each item in the TOC a class based on the header level:

<li class="h1"><a href="#foo">Foo</a></li>
<li class="h2"><a href="#bar">Bar</a></li>

jsoo avatar Jan 21 '11 15:01 jsoo

Should be possible to do fairly easily.

Might this be extend to lists of other types too? Lists of tables perhaps (using table captions in place of Foo and Bar from your example above. Or maybe HTML5 sections or figures?

netcarver avatar Jan 23 '11 16:01 netcarver

I would support this idea. To illustrate how useful this feature is, here is a simple example of the TOC syntax in reStructuredText that shows how it works there:

.. contents::

Markup languages
===================

Textile
----------
Very advanced shorthand syntax for HTML

Markdown
-------------
Simple, but less powerful then Textile

reStructuredText
------------------
Mainly used for Python software documentation

And instead of

.. contents::

you may also write

.. contents::  Lightweight markup languages

to replace the default title "Contents". This can be tried in a reST sandbox, and there are other options also.

So what about using:

toc. 

to generate a TOC in Textile, for example? Alternatively toc1. , toc2. , and so on could be used for different depths.

eliph avatar Jan 23 '11 16:01 eliph

Excellent possibilities here.

So as a Textplug, you would need to be able to parse the whole document. I guess that won't work with the current block-level callback?

jsoo avatar Jan 23 '11 17:01 jsoo

Nope. Currently they only get a callback as the blocks are parsed, in order. This would require a two pass approach, as taken by notelists. First pass collates the data, second pass sorts it and inserts it. Doesn't mean it's impossible -- just not with the current block-level callbacks.

netcarver avatar Jan 23 '11 17:01 netcarver

Don’t know what the state of callbacks is these days but a more dynamic Handling of ToCs would be sweet, so it wasn’t so tedious to edit a static one when sections change.

wion avatar Nov 25 '18 11:11 wion

Just remembered there's the soo_toc plugin for Txp, and it works perfectly with only minor extra fuss to ensure id selectors are in headers. I'm happy.

wion avatar Dec 10 '18 13:12 wion