Project

General

Profile

Actions

Defect #40715

closed

Wiki (markdown syntax): "Edit this section" does not extract ATX headings correctly

Added by daijiro fukuda about 1 month ago. Updated about 1 month ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Duplicate
Affected version:

Description

Abstraction

"Edit this section" in Wiki with the Markdown syntax does not extract ATX headings correctly.

ATX headings:

# Headline

## Headline

The current trunk(rev.22841) and v5.0.2 extracts it by the regexp '#+.+', but this would not be sufficient.

Especially, since it does not consider the following condition, it mishandles ticket references such as "#11111" or "##11111".

The opening sequence of # characters must be followed by a space or by the end of line.

I explain the details in "How to reproduce".

Note: the regexps about extracting ATX headings:

https://github.com/redmine/redmine/blob/c0af36b12da1d053d87735c174e7c79e97254e75/lib/redmine/wiki_formatting/section_helper.rb#L45

@text.split(/(^(?:\S+\r?\n\r?(?:\=+|\-+)|#+.+|(?:~~~|```).*)\s*$)/).each do |part|

https://github.com/redmine/redmine/blob/c0af36b12da1d053d87735c174e7c79e97254e75/lib/redmine/wiki_formatting/section_helper.rb#L55-L56

          elsif part =~ /\A(#+).+/
            level = $1.size

How to reproduce

Prepare Wiki with the Markdown syntax as follows.

# Wiki

## Section A

A

##1 : this is a ticket reference.

AA

## Section B

B

We can click each section's "Edit this section" button (surrounded by red rectangles in the image above).
However, we can't edit each section correctly since the ticket reference "##1" is wrongly detected as a level 2 section.

When clicking the button of "Section A":
(URI: "Wiki/edit?section=2")

When clicking the button of "Section B":
(URI: "Wiki/edit?section=3")

The expected result when clicking the button of "Section A":

A

##1 : this is a ticket reference.

AA

The expected result when clicking the button of "Section B":

B

Environment

$ RAILS_ENV=development bin/about

Environment:
  Redmine version                5.1.2.devel
  Ruby version                   3.2.2-p53 (2023-03-30) [x86_64-linux]
  Rails version                  7.1.2
  Environment                    development
  Database adapter               SQLite
  Mailer queue                   ActiveJob::QueueAdapters::AsyncAdapter
  Mailer delivery                smtp
Redmine settings:
  Redmine theme                  Default
SCM:
  Subversion                     1.13.0
  Git                            2.25.1
  Filesystem                     
Redmine plugins:
  no plugin installed

<!-- MarkdownTOC -->

<!-- /MarkdownTOC -->


Files


Related issues

Is duplicate of Redmine - Defect #40716: Wiki (markdown syntax): "Edit this section" does not extract ATX headings correctlyConfirmed

Actions
Actions #1

Updated by daijiro fukuda about 1 month ago

Sorry, I accidentally submitted this in the middle.
Could you please discard this ticket as I recreate this?

Actions #2

Updated by daijiro fukuda about 1 month ago

I recreate the issue:

Sorry for the trouble. please discard this ticket.

Actions #3

Updated by Marius BĂLTEANU about 1 month ago

  • Status changed from New to Closed
  • Resolution set to Duplicate
Actions #4

Updated by Marius BĂLTEANU about 1 month ago

  • Is duplicate of Defect #40716: Wiki (markdown syntax): "Edit this section" does not extract ATX headings correctly added
Actions

Also available in: Atom PDF