Opened 15 years ago
Last modified 8 years ago
#9055 new enhancement
Auto numbering in wiki tables
Reported by: | 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 )
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 , 15 years ago
Description: | modified (diff) |
---|---|
Keywords: | autonumbering added |
Milestone: | → experimental |
comment:2 by , 15 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.
e.g.:
{{{ #!labels 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 , 15 years ago
Milestone: | experimental → next-major-0.1X |
---|
Milestone experimental deleted
comment:4 by , 15 years ago
Keywords: | wikidata added |
---|---|
Priority: | normal → lowest |
Version: | → 0.12dev |
Interesting use case (a bit connected to mediawiki:Wikidata), to keep in sight.
follow-up: 6 comment:5 by , 8 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): implements(IWikiSyntaxProvider) 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) else: 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 ||
Into:
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?
comment:6 by , 8 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.
Interesting idea… however I've no clue yet how this could be implemented.