Method: ActionView::Helpers::TagHelper#cdata_section
- Defined in:
- actionview/lib/action_view/helpers/tag_helper.rb
#cdata_section(content) ⇒ Object
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]]>
558 559 560 561 |
# File 'actionview/lib/action_view/helpers/tag_helper.rb', line 558 def cdata_section(content) splitted = content.to_s.gsub(/\]\]>/, "]]]]><![CDATA[>") "<![CDATA[#{splitted}]]>".html_safe end |