Modify

Opened 15 years ago

Closed 8 years ago

#6907 closed enhancement (fixed)

An option to turn off numbering

Reported by: anonymous Owned by: Ryan J Ollos
Priority: normal Component: TocMacro
Severity: normal Keywords:
Cc: Christian Boos Trac Release: 0.11

Description

It should be useful to have An option to turn off the section numbering. The numbering is always on when 'inline' option is active.

Attachments (0)

Change History (20)

comment:1 Changed 14 years ago by anonymous

The same request lie partially in ticket #8674.
Could you please provide us some feedback?
Cheers,
M

comment:2 Changed 14 years ago by anonymous

All the more it seems necessary for people using the NumberedHeadlinesPlugin.

The numbering being redundant when one calls the "inline TOC":

= main title =
## title1 ##
### title11 ###
### title12 ###
## title2 ##

gives the following inline TOC

1. 1. title1
  1. 1.1. title11
  2. 1.2. title12
2. 2. title2

Cheers,
M

Last edited 8 years ago by Ryan J Ollos (previous) (diff)

comment:3 Changed 14 years ago by anonymous

An "easy way" to do this would be to replace the <ol> and <li> tags generated by :

  • the <dl> and <dd> tags respectively (indentation conserved)

or by

  • the <dl> and <dt> tags respectively, if no indentation is desired (see ticket #8674)

Dear developpers, please...
Cheers,
M

comment:4 Changed 14 years ago by anonymous

Hi, Is there anyone there? Cheers, M

comment:6 Changed 14 years ago by anonymous

Knock knock...
Still no one here?
Cheers,
M

comment:7 Changed 13 years ago by anonymous

Another try... Cheers, M

comment:8 Changed 13 years ago by anonymous

Come on...
Please!
M

comment:9 Changed 13 years ago by anonymous

Is there anyone here?
Cheers,
M

comment:10 Changed 13 years ago by anonymous

The 4th month of expectation is about to begin.
An answer would be so great...
Cheers,
M

comment:11 Changed 13 years ago by Christian Boos

Cc: Christian Boos added; anonymous removed

Hello Mathieu,

As Noah told you via PM, if there's no one on CC:, chances are that no one will notice your comments ;-)

Now to the topic itself, it seems a trivial matter of changing the tag.ol() in source:tocmacro/0.11/tractoc/macro.py#L42 to something configurable (i.e. tag.ol() or tag.ul() depending on a macro parameter.

I could try to find a moment to do it, but your best bet is to try by yourself ;-)

comment:12 in reply to:  11 ; Changed 13 years ago by mathieu trocmé

Thanks Christian :-)

Actually another tag.ol() should also be replaced (see line 181).

What I'd like to get in the end is a bullet free list.
This can easily be achieved replacing

  • all tag.ol() by tag.dl()
  • all tag.li() by tag.dd()

Could you please implement this feature through the use of a new control argument (e.g. "nonumbering")?

Cheers,
Mathieu

comment:13 in reply to:  12 ; Changed 13 years ago by Christian Boos

Replying to mtrocme:

Thanks Christian :-)

Actually another tag.ol() should also be replaced (see line 181).

Feel free to attach your macro.py here... or rather a patch! But first have a look at Trac:TracDev/SubmittingPatches ;-)

In particular, pay attention to whitespace issues (don't use tabs).

What I'd like to get in the end is a bullet free list.
This can easily be achieved replacing

  • all tag.ol() by tag.dl()
  • all tag.li() by tag.dd()

Could you please implement this feature through the use of a new control argument (e.g. "nonumbering")?

Hm, no, a description list is no good substitute here, as you don't "define" anything. This should rather be achieved with ul/li + some css (e.g. ul.nonumbers li { list-style-type: none }).

comment:14 in reply to:  13 ; Changed 13 years ago by mathieu trocmé

Ok, let's have a try...
Here's what I would do (sorry for any clumsiness, first patch ever and first python contact).
This is just a first (working) shot using tag.dd() instead of css-tuned tag.li():

23c23,24
< def outline_tree(env, ol, outline, context, active, min_depth, max_depth):
---
> def outline_tree(env, ol, outline, context, active, min_depth, max_depth, 
>                  nonumbering):
39c40,43
<                     li = tag.li()
---
>                     if nonumbering:
>                         li = tag.dd()
>                     else:
>                         li = tag.li()
42c46,50
<                 new_ol = tag.ol()
---
>                 new_ol = tag.dl()
>                 if nonumbering:
> 	                  new_ol = tag.dl()
>                 else:
>                       new_ol = tag.ol()
50,51c58,63
<             li = tag.li(tag.a(Markup(heading), href=href),
<                         class_=active and 'active' or None)
---
>             if nonumbering:
>                 li = tag.dd(tag.a(Markup(heading), href=href), 
>                             class_=active and 'active' or None)
>             else:
>                 li = tag.li(tag.a(Markup(heading), href=href), 
>                             class_=active and 'active' or None)
88a101
>     || {{{nonumbering}}} || Inhibate automatic numbering (useful for compatibility with the NumberedHeadlines plugin). ||
119a133
>         nonumbering = False
128a143,144
>             elif arg == 'nonumbering':
>                 nonumbering = True
181c197,201
<         ol = tag.ol()
---
>         ol = tag.dl()
>         if nonumbering:
>             ol = tag.dl()
>         else:
>             ol = tag.ol()
191,193c211,214
<                 self._render_title_index(formatter, ol, page_resource,
<                             active and pagename == current_page,
<                             params['min_depth'] < 2)
---
>                 self._render_title_index(formatter, ol, page_resource, 
>                             active and pagename == current_page, 
>                             params['min_depth'] < 2, 
>                             nonumbering)
195,196c216,218
<                 self._render_page_outline(formatter, ol, page_resource,
<                                                         active, params)
---
>                 self._render_page_outline(formatter, ol, page_resource, 
>                                                         active, params, 
>                                                         nonumbering)
207c229,230
<     def _render_title_index(self, formatter, ol, page_resource, active, show_title):
---
>     def _render_title_index(self, formatter, ol, page_resource, active, show_title, 
>                             nonumbering):
219,222c242,251
<         ol.append((tag.li(tag.a(page_resource.id,
<                       href=get_resource_url(self.env, page_resource, ctx.href)),
<                       Markup(title),
<                       class_= active and 'active' or None)))
---
>         if nonumbering:
>             ol.append((tag.dd(tag.a(page_resource.id, 
>                           href=get_resource_url(self.env, page_resource, ctx.href)), 
>                           Markup(title), 
>                           class_= active and 'active' or None)))
>         else:
>             ol.append((tag.li(tag.a(page_resource.id, 
>                           href=get_resource_url(self.env, page_resource, ctx.href)), 
>                           Markup(title), 
>                           class_= active and 'active' or None)))
224c253,254
<     def _render_page_outline(self, formatter, ol, page_resource, active, params):
---
>     def _render_page_outline(self, formatter, ol, page_resource, active, params, 
>                              nonumbering):
231,233c261,264
<             outline_tree(self.env, ol, fmt.outline, ctx,
<                     active and page_resource.id == formatter.context.resource.id,
<                     params['min_depth'], params['max_depth'])
---
>             outline_tree(self.env, ol, fmt.outline, ctx, 
>                     active and page_resource.id == formatter.context.resource.id, 
>                     params['min_depth'], params['max_depth'], 
>                     nonumbering)

I'll look at the css thing tomorrow.
In the meanwhile, feel free to share any comments.

Cheers,
Mathieu

comment:15 in reply to:  14 ; Changed 13 years ago by mathieu trocmé

Hi there,

Here's a second temporary patch that prevents from using dl/dd markups.

23c23,24
< def outline_tree(env, ol, outline, context, active, min_depth, max_depth):
---
> def outline_tree(env, ol, outline, context, active, min_depth, max_depth, 
>                  nonumbering):
42c43,46
<                 new_ol = tag.ol()
---
>                 if nonumbering:
>                     new_ol = tag.ul(class_='nonumbers')
>                 else:
>                     new_ol = tag.ol()
88a93
>     || {{{nonumbering}}} || Inhibate automatic numbering (useful for compatibility with the NumberedHeadlines plugin). ||
119a125
>         nonumbering = False
128a135,136
>             elif arg == 'nonumbering':
>                 nonumbering = True
181c189,192
<         ol = tag.ol()
---
>         if nonumbering:
>             ol = tag.ul(class_='nonumbers')
>         else:
>             ol = tag.ol()
195,196c206,208
<                 self._render_page_outline(formatter, ol, page_resource,
<                                                         active, params)
---
>                 self._render_page_outline(formatter, ol, page_resource, 
>                                                         active, params, 
>                                                         nonumbering)
224c236,237
<     def _render_page_outline(self, formatter, ol, page_resource, active, params):
---
>     def _render_page_outline(self, formatter, ol, page_resource, active, params, 
>                              nonumbering):
231,233c244,247
<             outline_tree(self.env, ol, fmt.outline, ctx,
<                     active and page_resource.id == formatter.context.resource.id,
<                     params['min_depth'], params['max_depth'])
---
>             outline_tree(self.env, ol, fmt.outline, ctx, 
>                     active and page_resource.id == formatter.context.resource.id, 
>                     params['min_depth'], params['max_depth'], 
>                     nonumbering)

Adding the following lines at the end of wiki.css

/* TocMacro hack */
ul.nonumbers { list-style-type: none; }

does the trick (same rendering as the previous patch).

Nevertheless I don't think making a hard change in wiki.css is the right thing to do, especially for people who don't have access to wiki.css.
How could one cope with that?

Adding

<style type="text/css">ul.nonumbers { list-style-type: none; }</style>

within the header markups of all pages?
That does not seem really smarter...

Christian, any clue?

Cheers,
Mathieu

comment:16 in reply to:  15 Changed 13 years ago by mathieu trocmé

Hi again,

Here's a way (the way?) to avoid any style sheet:

23c23,24
< def outline_tree(env, ol, outline, context, active, min_depth, max_depth):
---
> def outline_tree(env, ol, outline, context, active, min_depth, max_depth, 
>                  nonumbering):
42c43,46
<                 new_ol = tag.ol()
---
>                 if nonumbering:
>                     new_ol = tag.ul(style='list-style-type:none')
>                 else:
>                     new_ol = tag.ol()
88a93
>     || {{{nonumbering}}} || Inhibate automatic numbering (useful for compatibility with the NumberedHeadlines plugin). ||
119a125
>         nonumbering = False
128a135,136
>             elif arg == 'nonumbering':
>                 nonumbering = True
181c189,192
<         ol = tag.ol()
---
>         if nonumbering:
>             ol = tag.ul(style='list-style-type:none')
>         else:
>             ol = tag.ol()
195,196c206,208
<                 self._render_page_outline(formatter, ol, page_resource,
<                                                         active, params)
---
>                 self._render_page_outline(formatter, ol, page_resource, 
>                                                         active, params, 
>                                                         nonumbering)
224c236,237
<     def _render_page_outline(self, formatter, ol, page_resource, active, params):
---
>     def _render_page_outline(self, formatter, ol, page_resource, active, params, 
>                              nonumbering):
231,233c244,247
<             outline_tree(self.env, ol, fmt.outline, ctx,
<                     active and page_resource.id == formatter.context.resource.id,
<                     params['min_depth'], params['max_depth'])
---
>             outline_tree(self.env, ol, fmt.outline, ctx, 
>                     active and page_resource.id == formatter.context.resource.id, 
>                     params['min_depth'], params['max_depth'], 
>                     nonumbering)

What do you guys reckon?

Cheers,
M

comment:17 Changed 10 years ago by Ryan J Ollos

Owner: Noah Kantrowitz deleted

comment:18 Changed 8 years ago by ntmlod

This is exactly what I'm looking for to avoid duplicate numbering from already numbered headings.
I have just added the previous code to the current revision of the plugin

Is there any reason why this patch has not been committed ?

  • tractoc/macro.py

     
    3434    def write(self, *args): pass
    3535
    3636
    37 def outline_tree(env, ol, outline, context, active, min_depth, max_depth):
     37def outline_tree(env, ol, outline, context, active, min_depth, max_depth, nonumbering):
    3838    if min_depth > max_depth:
    3939        min_depth, max_depth = max_depth, min_depth
    4040    max_depth = min(6, max_depth)
     
    5353                    li = tag.li()
    5454                    ol.append(li)
    5555                    stack[d] = (li, ol)
    56                 new_ol = tag.ol()
     56                if nonumbering:
     57                    new_ol = tag.ul(style='list-style-type:none')
     58                else:
     59                    new_ol = tag.ol()
    5760                li.append(new_ol)
    5861                stack[d+1] = (None, new_ol)
    5962            href = get_resource_url(env, context.resource, context.href)
     
    103106    || `notitle`      || Supress display of page title. ||
    104107    || `reverse`      || Display TOC sorted in reversed order.  ''(Since 11.0.0.4)'' ||
    105108    || `from=page`|| Obtain the list of pages to show from the content (one page name per line) of another wiki page.  ||
     109    || `nonumbering` || Inhibate automatic numbering ||
    106110    For `titleindex` argument, an empty pagelist will evaluate to all pages:
    107111    {{{
    108112    [[TOC(titleindex, notitle, heading=All pages)]]
     
    157161        inline = False
    158162        pagenames = []
    159163        reverse = False
     164        nonumbering = False
    160165
    161166        default_heading = 'Table of Contents'
    162167        params = {'min_depth': 1, 'max_depth': 6}
     
    179184                reverse = True
    180185            elif arg == 'nofloat':
    181186                return ''
     187            elif arg == 'nonumbering':
     188                nonumbering = True
    182189            elif arg != '':
    183190                pagenames.append(arg)
    184191        heading = kw.pop('heading', '') or default_heading
     
    223230        pagenames = temp_pagenames
    224231
    225232        base = tag.div(class_=inline and 'wiki-toc-inline' or 'wiki-toc')
    226         ol = tag.ol()
     233        if nonumbering:
     234            ol = tag.ul(style='list-style-type:none')
     235        else:
     236            ol = tag.ol()
    227237        base.append([heading and tag.h4(heading), ol])
    228238
    229239        active = len(pagenames) > 1
     
    239249                            params['min_depth'] < 2)
    240250            else:
    241251                self._render_page_outline(formatter, ol, page_resource,
    242                                                         active, params)
     252                                                        active, params, nonumbering)
    243253        return base
    244254
    245255    def get_page_text(self, formatter, page_resource):
     
    283293                                class_= active and 'active' or None)))
    284294
    285295    def _render_page_outline(self, formatter, ol, page_resource, active,
    286                              params):
     296                             params, nonumbering):
    287297        page_text, page_exists = self.get_page_text(formatter, page_resource)
    288298        if page_exists:
    289299            ctx = formatter.context(page_resource)
     
    291301            fmt.format(page_text, NullOut())
    292302            outline_tree(self.env, ol, fmt.outline, ctx,
    293303                    active and page_resource.id == formatter.context.resource.id,
    294                     params['min_depth'], params['max_depth'])
     304                    params['min_depth'], params['max_depth'], nonumbering)
    295305        else:
    296306            ol.append(system_message('Error: Page %s does not exist' %
    297307                                     page_resource.id))
Last edited 8 years ago by ntmlod (previous) (diff)

comment:19 in reply to:  18 Changed 8 years ago by Ryan J Ollos

Replying to ntmlod:

Is there any reason why this patch has not been committed ?

Yes, the plugin has no maintainer.

comment:20 Changed 8 years ago by Ryan J Ollos

Owner: set to Ryan J Ollos
Status: newaccepted

comment:21 Changed 8 years ago by Ryan J Ollos

Resolution: fixed
Status: acceptedclosed

In 16590:

TocMacro 11.0.0.7: Add option to disable numbering for inline TOC

Fixes #6907.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.