instance method
cdata_section
Ruby on Rails 7.2.3
Since v2.2.3Signature
cdata_section(content)
Returns a CDATA section with the given content. CDATA sections are used to escape blocks of text containing characters which would otherwise be recognized as markup. CDATA sections begin with the string <![CDATA[ and end with (and may not contain) the string ]]>.
cdata_section("<hello world>") # => <![CDATA[<hello world>]]> cdata_section(File.read("hello_world.txt")) # => <![CDATA[<hello from a text file]]> cdata_section("hello]]>world") # => <![CDATA[hello]]]]><![CDATA[>world]]>
Parameters
-
contentreq
Source
# File actionview/lib/action_view/helpers/tag_helper.rb, line 571
def cdata_section(content)
splitted = content.to_s.gsub(/\]\]>/, "]]]]><![CDATA[>")
"<![CDATA[#{splitted}]]>".html_safe
end
Defined in actionview/lib/action_view/helpers/tag_helper.rb line 571
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Helpers::TagHelper