Class: CodeBlock

Inherits:
DocItem show all
Defined in:
lib/almirah/doc_items/code_block.rb

Constant Summary

Constants included from HtmlSafe

HtmlSafe::ALLOWED_URL_SCHEMES

Instance Attribute Summary collapse

Attributes inherited from DocItem

#parent_doc, #parent_heading

Instance Method Summary collapse

Methods inherited from DocItem

#get_url, #owner_document, #split_table_cells

Methods inherited from TextLine

#bold, #bold_and_italic, broken_links, #format_string, #inline_code, #italic, #link, link_registry, link_registry=, #literal_text, #owner_document, record_broken_link, reset_broken_links, #wiki_link

Methods included from HtmlSafe

#escape_attr, #escape_text, #safe_url

Methods inherited from TextLineBuilderContext

#bold, #bold_and_italic, #inline_code, #italic, #link, #literal_text, #wiki_link

Constructor Details

#initialize(suggested_format) ⇒ CodeBlock

Returns a new instance of CodeBlock.



6
7
8
9
# File 'lib/almirah/doc_items/code_block.rb', line 6

def initialize(suggested_format)
  @suggested_format = suggested_format
  @code_lines = []
end

Instance Attribute Details

#code_linesObject

Returns the value of attribute code_lines.



4
5
6
# File 'lib/almirah/doc_items/code_block.rb', line 4

def code_lines
  @code_lines
end

#suggested_formatObject

Returns the value of attribute suggested_format.



4
5
6
# File 'lib/almirah/doc_items/code_block.rb', line 4

def suggested_format
  @suggested_format
end

Instance Method Details

#to_htmlObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/almirah/doc_items/code_block.rb', line 11

def to_html
  s = ''

  if @@html_table_render_in_progress
    s += "</table>\n"
    @@html_table_render_in_progress = false
  end
  s += '<code>'
  @code_lines.each do |l|
    s += escape_text(l) + ' </br>' # ADR-188/SRS-096: code content is inert text
  end
  s += "</code>\n"
  s
end