Opened 6 years ago

Closed 5 years ago

Won't edit correct section when heading equal chars are only on the left side

Reported by: Owned by: shai Ryan J Ollos normal SectionEditPlugin major heading equal characters 0.12

Description

When using equal characters ("=") only on the left side of the heading, the plugin won't edit the correct section.

Example for testing:

== Single Heading 1
Test
Test
Test
----
Test
Test
Test


comment:1 Changed 6 years ago by shai

Summary: Won't edit correct section when using equal chars are only on the left side → Won't edit correct section when heading equal chars are only on the left side

comment:2 Changed 6 years ago by shai

Trac Release: 0.11 → 0.12

comment:3 follow-up:  4 Changed 6 years ago by erny@…

The problem seems to be the regular expression in web_ui.py near line 99:

if is_code_block == False and re.match(r'^\s*(={1,5}) .+ \1(?:\s*#.+)?\s*\$', line):


The \1 expression references the matched (={1,5}) expression. I'll try to see if it works making it optional, i.e., just pust a ? behind \1.

comment:4 in reply to:  3 Changed 5 years ago by Ryan J Ollos

Owner: changed from Catalin BALAN to Ryan J Ollos new → assigned

The \1 expression references the matched (={1,5}) expression. I'll try to see if it works making it optional, i.e., just pust a ? behind \1.

Yeah, that essentially works, except that there appears to have been a separate existing issue with the regex. Trac 0.12.0 allows headings like == heading == as well as == heading==. That is, my observation with Trac 0.12.0 is that a whitespace is required between the heading markup character and the text, but not between the text and the trailing markup.

However, the relevant part of the regex was ) .+ \1(, which required a whitespace character between the leading and trailing markup characters.

Looking at the source code for Trac, I think this makes sense. If we look at Trac 0.11.0, the regex for matching a heading is:

r"(?P<heading>^\s*(?P<hdepth>=+)\s.*\s(?P=hdepth)\s*"


In 0.12.0, it is:

r"(?P<heading>^\s*(?P<hdepth>={1,6})\s(?P<htext>.*?)"


Trac 0.12 matches =\s as a heading, but not =. There must be a whitespace character after the heading character, but no other characters are required. I think we should just change the SectionEditPlugin's regex to be the same as that used for extracting a heading in Trac 0.12.

I wonder though, why we are only capturing level 1-5 headings with the SectionEditPlugin rather than levels 1-6.

comment:5 Changed 5 years ago by Ryan J Ollos

Resolution: → fixed assigned → closed

(In [11180]) Fixes #7826: Modified the regex to agree with that used for section headings in Trac 0.12.0. The  icons should now be attached to every line of markup that Trac identifies as a section heading, which the exception of a level 6 heading. The latter issue was noted in comment:4 of #7826 and it should be investigated further why SectionEditPlugin only looks at level 1-5 headings.