OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
adapt header link generation
ulferts78642fb442f9
diff --git a/lib/open_project/text_formatting/filters/table_of_contents_filter.rb b/lib/open_project/text_formatting/filters/table_of_contents_filter.rbindex e216f632207..91b4d47430d 100644--- a/lib/open_project/text_formatting/filters/table_of_contents_filter.rb+++ b/lib/open_project/text_formatting/filters/table_of_contents_filter.rb@@ -40,14 +40,9 @@ module OpenProject::TextFormatting@ids = Set.newend- def add_header_link(node, id)- link = content_tag(:a,- "",- class: "op-uc-link_permalink icon-link",- "aria-hidden": true,- href: "##{id}")+ def add_header_link_class_and_id(node, id)+ node.css("a").first["class"] = "op-uc-link_permalink icon-link"node["id"] = id- node.add_child(link)end##@@ -66,8 +61,7 @@ module OpenProject::TextFormattingend##- # Appends the header link and returns- # a toc item.+ # Adds the bem classes to the header link and returns a toc item.# The item is prefixed by a number. If there is already a number prefix provided in the text,# that prefix is used if it matches the calculated number.def process_item(node, number)@@ -75,7 +69,7 @@ module OpenProject::TextFormattingreturn "".html_safe unless text.present?id = get_unique_id(text)- add_header_link(node, id)+ add_header_link_class_and_id(node, id)content_tag(:li, class: "op-uc-toc--list-item") doanchor_tag(text, number, id)diff --git a/spec/lib/open_project/text_formatting/markdown/headings_spec.rb b/spec/lib/open_project/text_formatting/markdown/headings_spec.rbindex aa4dcbdc768..6c9daaf1385 100644--- a/spec/lib/open_project/text_formatting/markdown/headings_spec.rb+++ b/spec/lib/open_project/text_formatting/markdown/headings_spec.rb@@ -51,7 +51,10 @@ RSpec.describe OpenProject::TextFormatting,<p class="op-uc-p">Some text before</p><h#{level} class="op-uc-h#{level}" id="the-heading">the heading- <a class="op-uc-link_permalink icon-link op-uc-link" aria-hidden="true" href="#the-heading"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ aria-hidden="true"+ href="#the-heading"+ rel="noopener noreferrer"></a></h#{level}><p class="op-uc-p">more text</p>EXPECTED@@ -115,7 +118,10 @@ RSpec.describe OpenProject::TextFormatting,<<~EXPECTED<h1 class="op-uc-h1" id="20090209">2009\\02\\09- <a class="op-uc-link_permalink icon-link op-uc-link" href="#20090209" aria-hidden="true"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ href="#20090209"+ aria-hidden="true"+ rel="noopener noreferrer"></a></h1>EXPECTEDenddiff --git a/spec/lib/open_project/text_formatting/markdown/toc_macro_spec.rb b/spec/lib/open_project/text_formatting/markdown/toc_macro_spec.rbindex d3482d2299a..265398615bb 100644--- a/spec/lib/open_project/text_formatting/markdown/toc_macro_spec.rb+++ b/spec/lib/open_project/text_formatting/markdown/toc_macro_spec.rb@@ -118,32 +118,50 @@ RSpec.describe OpenProject::TextFormatting,</p><h1 class="op-uc-h1" id="the-first-h1-heading">The first h1 heading- <a class="op-uc-link_permalink icon-link op-uc-link" href="#the-first-h1-heading" aria-hidden="true"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ href="#the-first-h1-heading"+ aria-hidden="true"+ rel="noopener noreferrer"></a></h1><p class="op-uc-p">Some text after the first h1 heading</p><h2 class="op-uc-h2" id="the-first-h2-heading">The first h2 heading- <a class="op-uc-link_permalink icon-link op-uc-link" href="#the-first-h2-heading" aria-hidden="true"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ href="#the-first-h2-heading"+ aria-hidden="true"+ rel="noopener noreferrer"></a></h2><p class="op-uc-p">Some text after the first h2 heading</p><h3 class="op-uc-h3" id="the-first-h3-heading">The first h3 heading- <a class="op-uc-link_permalink icon-link op-uc-link" href="#the-first-h3-heading" aria-hidden="true"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ href="#the-first-h3-heading"+ aria-hidden="true"+ rel="noopener noreferrer"></a></h3><p class="op-uc-p">Some text after the first h3 heading</p><h1 class="op-uc-h1" id="the-second-h1-heading">The second h1 heading- <a class="op-uc-link_permalink icon-link op-uc-link" href="#the-second-h1-heading" aria-hidden="true"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ href="#the-second-h1-heading"+ aria-hidden="true"+ rel="noopener noreferrer"></a></h1><p class="op-uc-p">Some text after the second h1 heading</p><h2 class="op-uc-h2" id="the-second-h2-heading">The second h2 heading- <a class="op-uc-link_permalink icon-link op-uc-link" href="#the-second-h2-heading" aria-hidden="true"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ href="#the-second-h2-heading"+ aria-hidden="true"+ rel="noopener noreferrer"></a></h2><p class="op-uc-p">Some text after the second h2 heading</p><h3 class="op-uc-h3" id="the-second-h3-heading">The second h3 heading- <a class="op-uc-link_permalink icon-link op-uc-link" href="#the-second-h3-heading" aria-hidden="true"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ href="#the-second-h3-heading"+ aria-hidden="true"+ rel="noopener noreferrer"></a></h3><p class="op-uc-p">Some text after the second h3 heading</p>EXPECTED@@ -236,32 +254,50 @@ RSpec.describe OpenProject::TextFormatting,</p><h1 class="op-uc-h1" id="1-the-first-h1-heading">1 The first h1 heading- <a class="op-uc-link_permalink icon-link op-uc-link" href="#1-the-first-h1-heading" aria-hidden="true"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ href="#1-the-first-h1-heading"+ aria-hidden="true"+ rel="noopener noreferrer"></a></h1><p class="op-uc-p">Some text after the first h1 heading</p><h2 class="op-uc-h2" id="11-the-first-h2-heading">1.1 The first h2 heading- <a class="op-uc-link_permalink icon-link op-uc-link" href="#11-the-first-h2-heading" aria-hidden="true"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ href="#11-the-first-h2-heading"+ aria-hidden="true"+ rel="noopener noreferrer"></a></h2><p class="op-uc-p">Some text after the first h2 heading</p><h3 class="op-uc-h3" id="111-the-first-h3-heading">1.1.1. The first h3 heading- <a class="op-uc-link_permalink icon-link op-uc-link" href="#111-the-first-h3-heading" aria-hidden="true"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ href="#111-the-first-h3-heading"+ aria-hidden="true"+ rel="noopener noreferrer"></a></h3><p class="op-uc-p">Some text after the first h3 heading</p><h1 class="op-uc-h1" id="2-the-second-h1-heading">2) The second h1 heading- <a class="op-uc-link_permalink icon-link op-uc-link" href="#2-the-second-h1-heading" aria-hidden="true"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ href="#2-the-second-h1-heading"+ aria-hidden="true"+ rel="noopener noreferrer"></a></h1><p class="op-uc-p">Some text after the second h1 heading</p><h2 class="op-uc-h2" id="21-the-second-h2-heading">2.1) The second h2 heading- <a class="op-uc-link_permalink icon-link op-uc-link" href="#21-the-second-h2-heading" aria-hidden="true"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ href="#21-the-second-h2-heading"+ aria-hidden="true"+ rel="noopener noreferrer"></a></h2><p class="op-uc-p">Some text after the second h2 heading</p><h3 class="op-uc-h3" id="211---the-second-h3-heading">2.1.1 - The second h3 heading- <a class="op-uc-link_permalink icon-link op-uc-link" href="#211---the-second-h3-heading" aria-hidden="true"></a>+ <a class="op-uc-link_permalink icon-link op-uc-link"+ href="#211---the-second-h3-heading"+ aria-hidden="true"+ rel="noopener noreferrer"></a></h3><p class="op-uc-p">Some text after the second h3 heading</p>EXPECTED