Module: Banzai::Filter::Concerns::HtmlWriter
- Extended by:
- ActiveSupport::Concern
- Included in:
- References::ReferenceFilter
- Defined in:
- lib/banzai/filter/concerns/html_writer.rb
Instance Method Summary collapse
-
#write_opening_tag(tag_name, attributes) ⇒ Object
Write an opening tag with the given tag name and attributes.
Instance Method Details
#write_opening_tag(tag_name, attributes) ⇒ Object
Write an opening tag with the given tag name and attributes.
The tag name and attribute names must not be user-specified; they are not validated.
The attribute values are always escaped in the appropriate manner; the contract is that whatever value goes in is the logical DOM value of the attribute that comes out.
i.e.:
“‘ruby html = write_opening_tag(tag, attrs) doc = Nokogiri::HTML.fragment(html) element = doc.child expect(element.to_h).to match(attrs) “`
This function should *never be changed*.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/banzai/filter/concerns/html_writer.rb', line 26 def write_opening_tag(tag_name, attributes) s = +"<" << tag_name attributes.each do |attr_name, attr_value| next if attr_value.nil? s << " " << attr_name << "=" s << '"' << CGI.escapeHTML(attr_value.to_s) << '"' end s << ">" end |