Skip to content

Commit

Permalink
increase stability on shortened text and macros
Browse files Browse the repository at this point in the history
  • Loading branch information
ulferts committed Mar 28, 2024
1 parent 6c359a5 commit da2087a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
19 changes: 18 additions & 1 deletion app/components/open_project/common/attribute_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def text_color

private

def first_paragraph_content
return unless first_paragraph_ast

first_paragraph_ast
.inner_html
.html_safe # rubocop:disable Rails/OutputSafety
end

def first_paragraph
@first_paragraph ||= if body_children.any?
body_children
Expand All @@ -77,6 +85,13 @@ def first_paragraph
end
end

def first_paragraph_ast
@first_paragraph_ast ||= text_ast
.xpath("html/body")
.children
.first
end

def text_ast
@text_ast ||= Nokogiri::HTML(full_text)
end
Expand All @@ -88,7 +103,9 @@ def body_children
end

def multi_type?
first_paragraph.include?("figure") || first_paragraph.include?("macro")
@multi_type ||= (description.present? && first_paragraph_ast.nil?) ||
%w[opce-macro-embedded-table figure macro].include?(first_paragraph_ast.name) ||
first_paragraph_ast.css("figure, macro, .op-uc-toc--list, .opce-macro-embedded-table")&.any?
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@
</div>
</edit-form>
</div>

1 change: 1 addition & 0 deletions frontend/src/global_styles/content/editor/_macros.sass
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
border-color: var(--content-form-danger-zone-bg-color)
padding: $nm-box-padding
box-shadow: rem-calc(1px 2px 3px) rgba(0, 0, 0, 0.2)
display: inline-block

0 comments on commit da2087a

Please sign in to comment.