Opened 13 years ago
Last modified 13 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 )
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)
Change History (7)
comment:1 Changed 13 years ago by
Description: | modified (diff) |
---|
comment:2 Changed 13 years ago by
Summary: | Don't force the trailing hashes to be added → [Patch] Don't force the trailing hashes to be added |
---|
comment:3 Changed 13 years ago by
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 13 years ago by
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
tohtext
.
-
0.11/tracnumberedheadlines/plugin.py
52 52 XML_NAME = r"[\w:](?<!\d)[\w:.-]*?" # See http://www.w3.org/TR/REC-xml/#id 53 53 54 54 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_NAME55 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 58 58 59 59 outline_counters = WeakKeyDictionary() 60 60 … … 68 68 def _parse_heading(self, formatter, match, fullmatch): 69 69 shorten = False 70 70 match = match.strip() 71 72 depth = min(len(fullmatch.group('nhdepth')), 6) 71 72 hdepth = fullmatch.group('nhdepth') 73 depth = len(hdepth) 73 74 74 75 try: 75 76 formatter.close_table() … … 100 101 101 102 num = fullmatch.group('nheadnum') or '' 102 103 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 105 108 num = num.strip() 106 109 if num and num[-1] == '.': 107 110 num = num[:-1] … … 117 120 n = n + 1 118 121 counters[depth-len(numbers[n:]):] = numbers[n:] 119 122 120 if not h eading_text:123 if not htext: 121 124 return tag() 122 125 123 126 heading = format_to_oneliner(formatter.env, formatter.context, 124 h eading_text, False)127 htext, False) 125 128 126 129 if anchor: 127 130 anchor = anchor[1:] … … 144 147 while s < len(counters) and counters[s] == 0: 145 148 s = s + 1 146 149 147 oheading_text = h eading_text148 h eading_text = '.'.join(map(str, counters[s:]) + [" "]) + heading_text150 oheading_text = htext 151 htext = '.'.join(map(str, counters[s:]) + [" "]) + htext 149 152 150 153 if self.number_outline: 151 oheading_text = h eading_text154 oheading_text = htext 152 155 153 156 heading = format_to_oneliner(formatter.env, formatter.context, 154 h eading_text, False)157 htext, False) 155 158 oheading = format_to_oneliner(formatter.env, formatter.context, 156 159 oheading_text, False)
Changed 13 years ago by
Attachment: | t9696-r10976-rev2.patch added |
---|
Changed 13 years ago by
Attachment: | t9696-r10976.patch added |
---|
comment:5 Changed 13 years ago by
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.
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
(?P=nhdepth)\s*" \