Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/herb/engine/debug_visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def in_script_or_style_context?
end

def in_excluded_context?
excluded_tags = ["script", "style", "head", "textarea", "pre"]
excluded_tags = ["script", "style", "head", "textarea", "pre", "svg", "math"]
return true if excluded_tags.any? { |tag| @element_stack.include?(tag) }

return true if @erb_block_stack.any? { |node| javascript_tag?(node.content.value.strip) }
Expand Down
73 changes: 73 additions & 0 deletions test/engine/debug_mode_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,5 +402,78 @@ class DebugModeTest < Minitest::Spec

assert_compiled_snapshot(template, debug: true)
end

test "svg content erb expressions do NOT get debug spans" do
template = <<~ERB
<svg viewBox="0 0 100 100">
<circle cx="50" cy="50" r="<%= @radius %>" />
<text x="50" y="50"><%= @label %></text>
</svg>
ERB

assert_compiled_snapshot(template, debug: true)
end

test "svg with defs and style erb expressions do NOT get debug spans" do
template = <<~ERB
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 29 29">
<defs>
<style>
.cls-1 {fill:none;stroke:<%= @stroke_color %>}
</style>
</defs>
<g transform="rotate(<%= @angle %> 50 50)">
<line x1="50" y1="10" x2="50" y2="50" stroke="red" />
</g>
</svg>
ERB

assert_compiled_snapshot(template, debug: true)
end

test "nested svg inside div erb expressions do NOT get debug spans inside svg" do
template = <<~ERB
<div class="chart-container">
<h2><%= @chart_title %></h2>
<svg viewBox="0 0 100 100">
<rect width="<%= @width %>" height="<%= @height %>" />
<text><%= @value %></text>
</svg>
<p><%= @description %></p>
</div>
ERB

assert_compiled_snapshot(template, debug: true, filename: "test.html.erb")
end

test "math content erb expressions do NOT get debug spans" do
template = <<~ERB
<math>
<mrow>
<mi><%= @variable %></mi>
<mo>=</mo>
<mn><%= @value %></mn>
</mrow>
</math>
ERB

assert_compiled_snapshot(template, debug: true)
end

test "nested math inside div erb expressions do NOT get debug spans inside math" do
template = <<~ERB
<div class="equation">
<p><%= @equation_name %></p>
<math>
<msup>
<mi><%= @base %></mi>
<mn><%= @exponent %></mn>
</msup>
</math>
</div>
ERB

assert_compiled_snapshot(template, debug: true, filename: "test.html.erb")
end
end
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading