Method: MdnQuery::Section#append_text

Defined in:
lib/mdn_query/section.rb

#append_text(text) ⇒ void

This method returns an undefined value.

Appends a text segment to the section.

Spaces before and after newlines are removed. If the text segment is empty (i.e. consists of just whitespaces), it is not appended.

Parameters:

  • text (String)

    the text segment to append



50
51
52
53
54
# File 'lib/mdn_query/section.rb', line 50

def append_text(text)
  trimmed = text.gsub(/\n[[:blank:]]+|[[:blank:]]+\n/, "\n")
  escaped = escape_html_tags(trimmed)
  @text << escaped unless text_empty?(escaped)
end