Edgewall Software

Opened 14 years ago

Last modified 7 years ago

#9055 new enhancement

Auto numbering in wiki tables

Reported by: itamarost@… Owned by:
Priority: lowest Milestone: next-major-releases
Component: wiki system Version: 0.12dev
Severity: normal Keywords: autonumbering wikidata
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Christian Boos)

It would be useful to have the ability to auto-number table rows.

Something like:

||= ID =||= Col =||
|| 1. || content of row 1 ||
|| 1. || content of row 2 ||

would result:

ID Col
1. content of row 1
2. content of row 2

Attachments (0)

Change History (6)

comment:1 by Christian Boos, 14 years ago

Description: modified (diff)
Keywords: autonumbering added
Milestone: experimental

Interesting idea… however I've no clue yet how this could be implemented.

comment:2 by Itamar O <itamarost@…>, 14 years ago

Not so sure about the implementation for the suggestion, but a possible way to do it using macros, based on definition of "labels" that auto-increment on every instance of the macro with the given label.


tbl: base=1, step=1, style=default, ...
cnt: base=2, step=2, style=alpha
||= Col1 =||= Col2 =||
|| [[l(tbl)]] || row-1 content using two counters: [[l(cnt)]], [[l(cnt)]] ||
|| [[l(tbl)]] || row-2 with another counter [[l(cnt)]] ||
|| [[l(tbl,level=2)]] || sub-row-1 of row-2 ||
|| [[l(tbl)]] || you get the idea... ||
Col1 Col2
1. row-1 content using two counters: b., d.
2. row-2 with another counter f.
2.1. sub-row-1 of row-2
3. you get the idea…

comment:3 by Christian Boos, 14 years ago

Milestone: experimentalnext-major-0.1X

Milestone experimental deleted

comment:4 by Christian Boos, 14 years ago

Keywords: wikidata added
Priority: normallowest
Version: 0.12dev

Interesting use case (a bit connected to mediawiki:Wikidata), to keep in sight.

comment:5 by Peter Suter, 7 years ago

A syntax provider could get close, for example:

from trac.util.html import tag
from trac.core import Component, implements
from trac.wiki.api import IWikiSyntaxProvider
class WikiCounters(Component):

    def __init__(self):
        self.counters = []

    def get_link_resolvers(self):
        return []

    def get_wiki_syntax(self):
        yield (r'\#\#', self._reset_counters)
        yield (r'(\#\.)+', self._format_counters)

    def _reset_counters(self, formatter, ns, match):
        self.counters = []

    def _format_counters(self, formatter, ns, match):
        current_level = len(self.counters)
        target_level = len(ns) / 2
        if target_level > current_level:
            self.counters += [1] * (target_level - current_level)
            if target_level < current_level:
                self.counters = self.counters[:target_level]
            self.counters[-1] += 1
        return tag.span(''.join('%s.' % counter for counter in self.counters))

Would turn this:

||= ID =||= Col =||
|| #. || content of row 1 ||
|| #. || content of row 2 ||
|| #.#. || content of row 2.1 ||
|| #. || content of row 3 ||


ID Col
1. content of row 1
2. content of row 2
2.1. content of row 2.1
3. content of row 3

(1. could probably be used instead of #. if preferable.)

Something like the ## would be required to start / reset the counter, or it will just continue counting up on page reloads. (Alternatively IWikiPageManipulator.prepare_wiki_page could start / reset the counter, but that won't work when the construct is used in other wiki-formatted resources like ticket descriptions etc.)

WONTFIX since this could be done in an small plugin?

in reply to:  5 comment:6 by Ryan J Ollos, 7 years ago

Replying to Peter Suter:

WONTFIX since this could be done in an small plugin?

Yeah, I think so. The has narrow applicability, maybe suitable for WikiExtrasPlugin. We can always revisit if there are more requests.

Modify Ticket

Change Properties
Set your email in Preferences
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.