Modify

Opened 12 years ago

Last modified 12 years ago

#9696 new enhancement

[Patch] Don't force the trailing hashes to be added

Reported by: Ryan J Ollos Owned by: Martin Scharrer
Priority: normal Component: NumberedHeadlinesPlugin
Severity: normal Keywords:
Cc: Steffen Hoffmann Trac Release: 0.12

Description (last modified by Ryan J Ollos)

As described in t:WikiFormatting#Headings, it is no longer required that trailing = be added (since 0.12.0, as far as I can tell). The same should be true for the hash symbols used by the NumberedHeadlinesPlugin.

I'm investigating whether a quick patch can be produced.

Attachments (2)

t9696-r10976-rev2.patch (2.5 KB) - added by Ryan J Ollos 12 years ago.
t9696-r10976.patch (1.1 KB) - added by Ryan J Ollos 12 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 12 years ago by Ryan J Ollos

Description: modified (diff)

comment:2 Changed 12 years ago by Ryan J Ollos

Summary: Don't force the trailing hashes to be added[Patch] Don't force the trailing hashes to be added

The patch below is based on formatter.py in 0.12.2. I'll also attach this as a patch file.

I'd propose making a 0.12 branch for the plugin. Let me know if I need to make any changes to the patch. I'll follow up quickly. In the meantime, I'll be using this on my production system and let you know if I find any issues.

  • 0.11/tracnumberedheadlines/plugin.py

     
    5353
    5454    NUM_HEADLINE = \
    5555        r"(?P<nheading>^\s*(?P<nhdepth>#+)\s" \
    56         r"(?P<nheadnum>\s*[0-9.]+\s)?.*\s(?P=nhdepth)\s*" \
     56        r"(?P<nheadnum>\s*[0-9.]+\s)?.*\s*" \
    5757        r"(?P<nhanchor>=%s)?(?:\s|$))" % XML_NAME
    5858
    5959    outline_counters = WeakKeyDictionary()
     
    6969        shorten = False
    7070        match = match.strip()
    7171
     72        hdepth = fullmatch.group('nhdepth')
    7273        depth = min(len(fullmatch.group('nhdepth')), 6)
    7374
    7475        try:
     
    100101
    101102        num    = fullmatch.group('nheadnum') or ''
    102103        anchor = fullmatch.group('nhanchor') or ''
    103         heading_text = match[depth+1+len(num):-depth-1-len(anchor)].strip()
    104 
     104        heading_text = match[depth+1+len(num):].strip()
     105        if heading_text.endswith(hdepth):
     106            heading_text = heading_text[:-depth]
     107           
    105108        num = num.strip()
    106109        if num and num[-1] == '.':
    107110          num = num[:-1]

comment:3 Changed 12 years ago by Ryan J Ollos

Cc: Steffen Hoffmann added; anonymous removed

Also, I have commit access to all of the repository, so if you approve of this change, I can push it to the repository to save you some time.

comment:4 Changed 12 years ago by Ryan J Ollos

Here is a patch that includes the previous patch and also makes some additional changes to mirror the implementation in formatter.py.

  • A level 7 heading ======= heading ======== isn't recognized by Trac. Previously, the NumberedHeadlinesPlugin would treat a level 7 numbered heading as a level 6 numbered heading. With the change below, it isn't recognized, which I think leads to more predicable behavior for the editor of a wiki page.
  • A regular expression is used to capture the heading text.
  • Renamed variable heading_text to htext.
  • 0.11/tracnumberedheadlines/plugin.py

     
    5252    XML_NAME = r"[\w:](?<!\d)[\w:.-]*?" # See http://www.w3.org/TR/REC-xml/#id
    5353
    5454    NUM_HEADLINE = \
    55         r"(?P<nheading>^\s*(?P<nhdepth>#+)\s" \
    56         r"(?P<nheadnum>\s*[0-9.]+\s)?.*\s(?P=nhdepth)\s*" \
    57         r"(?P<nhanchor>=%s)?(?:\s|$))" % XML_NAME
     55        r"(?P<nheading>^\s*(?P<nhdepth>#{1,6})\s" \
     56        r"(?P<nheadnum>\s*[0-9.]+\s)?(?P<nhtext>.*?)" \
     57        r"(?P<nhanchor>=%s)?\s*$)" % XML_NAME
    5858
    5959    outline_counters = WeakKeyDictionary()
    6060
     
    6868    def _parse_heading(self, formatter, match, fullmatch):
    6969        shorten = False
    7070        match = match.strip()
    71 
    72         depth = min(len(fullmatch.group('nhdepth')), 6)
     71       
     72        hdepth = fullmatch.group('nhdepth')
     73        depth = len(hdepth)
    7374
    7475        try:
    7576          formatter.close_table()
     
    100101
    101102        num    = fullmatch.group('nheadnum') or ''
    102103        anchor = fullmatch.group('nhanchor') or ''
    103         heading_text = match[depth+1+len(num):-depth-1-len(anchor)].strip()
    104 
     104        htext  = fullmatch.group('nhtext').strip()
     105        if htext.endswith(hdepth):
     106            htext = htext[:-depth]
     107           
    105108        num = num.strip()
    106109        if num and num[-1] == '.':
    107110          num = num[:-1]
     
    117120              n = n + 1
    118121            counters[depth-len(numbers[n:]):] = numbers[n:]
    119122
    120         if not heading_text:
     123        if not htext:
    121124          return tag()
    122125
    123126        heading = format_to_oneliner(formatter.env, formatter.context,
    124             heading_text, False)
     127            htext, False)
    125128
    126129        if anchor:
    127130            anchor = anchor[1:]
     
    144147        while s < len(counters) and counters[s] == 0:
    145148          s = s + 1
    146149
    147         oheading_text = heading_text
    148         heading_text = '.'.join(map(str, counters[s:]) + [" "]) + heading_text
     150        oheading_text = htext
     151        htext = '.'.join(map(str, counters[s:]) + [" "]) + htext
    149152
    150153        if self.number_outline:
    151           oheading_text = heading_text
     154          oheading_text = htext
    152155
    153156        heading = format_to_oneliner(formatter.env, formatter.context,
    154             heading_text, False)
     157            htext, False)
    155158        oheading = format_to_oneliner(formatter.env, formatter.context,
    156159            oheading_text, False)

Changed 12 years ago by Ryan J Ollos

Attachment: t9696-r10976-rev2.patch added

Changed 12 years ago by Ryan J Ollos

Attachment: t9696-r10976.patch added

comment:5 Changed 12 years ago by Ryan J Ollos

Just wanted to checkin and see if the author of the plugin is still around, and if there would be any objections to pushing this patch to the repository.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Martin Scharrer.

Add Comment


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

 
Note: See TracTickets for help on using tickets.