class MarkdownExec::FCB
such as body, call, headings, and more.
It allows for setting and getting attributes related to the code block,
This class represents a fenced code block in a markdown document.
Fenced Code Block (FCB)
def derive_title_from_body
-
(String)- The derived title.
Parameters:
-
fcb(Object) -- The FCB object whose title is to be derived.
def derive_title_from_body unless (body_content = @attrs[:body]) # empty body -> empty title @attrs[:title] = '' return end # body -> title @attrs[:title] = if body_content.count == 1 body_content.first else format_multiline_body_as_title(body_content) end end
def format_multiline_body_as_title(body_lines)
-
(String)- Formatted title.
Parameters:
-
body_lines(Array) -- The lines of body content.
def format_multiline_body_as_title(body_lines) body_lines.map.with_index do |line, index| index.zero? ? line : " #{line}" end.join("\n") << "\n" end
def initialize(options = {})
def initialize(options = {}) @attrs = { body: nil, call: nil, headings: [], dname: nil, indent: '', name: nil, nickname: nil, oname: nil, reqs: [], shell: '', title: '', random: Random.new.rand, text: nil # displayable in menu }.merge(options) end
def method_missing(method, *args, &block)
def method_missing(method, *args, &block) method_name = method.to_s if @attrs.respond_to?(method_name) @attrs.send(method_name, *args, &block) elsif method_name[-1] == '=' @attrs[method_name.chop.to_sym] = args[0] else @attrs[method_name.to_sym] end rescue StandardError => err warn("ERROR ** FCB.method_missing(method: #{method_name}," \ " *args: #{args.inspect}, &block)") warn err.inspect warn(caller[0..4]) # raise StandardError, error raise err # Here, we simply propagate the original error instead of wrapping it in a StandardError. end
def respond_to_missing?(method_name, include_private = false)
def respond_to_missing?(method_name, include_private = false) @attrs.key?(method_name.to_sym) || super end
def title=(value)
def title=(value) @attrs[:title] = value end
def to_h
def to_h @attrs end
def to_yaml
def to_yaml @attrs.to_yaml end