Class: Kward::MarkdownCodeBlock::Block
- Inherits:
-
Struct
- Object
- Struct
- Kward::MarkdownCodeBlock::Block
- Defined in:
- lib/kward/prompt_interface/editor/markdown_code_block.rb
Instance Attribute Summary collapse
-
#body_end ⇒ Object
Returns the value of attribute body_end.
-
#body_start ⇒ Object
Returns the value of attribute body_start.
-
#close_end ⇒ Object
Returns the value of attribute close_end.
-
#close_line ⇒ Object
Returns the value of attribute close_line.
-
#language ⇒ Object
Returns the value of attribute language.
-
#next_fence_start ⇒ Object
Returns the value of attribute next_fence_start.
-
#open_line ⇒ Object
Returns the value of attribute open_line.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
Instance Attribute Details
#body_end ⇒ Object
Returns the value of attribute body_end
5 6 7 |
# File 'lib/kward/prompt_interface/editor/markdown_code_block.rb', line 5 def body_end @body_end end |
#body_start ⇒ Object
Returns the value of attribute body_start
5 6 7 |
# File 'lib/kward/prompt_interface/editor/markdown_code_block.rb', line 5 def body_start @body_start end |
#close_end ⇒ Object
Returns the value of attribute close_end
5 6 7 |
# File 'lib/kward/prompt_interface/editor/markdown_code_block.rb', line 5 def close_end @close_end end |
#close_line ⇒ Object
Returns the value of attribute close_line
5 6 7 |
# File 'lib/kward/prompt_interface/editor/markdown_code_block.rb', line 5 def close_line @close_line end |
#language ⇒ Object
Returns the value of attribute language
5 6 7 |
# File 'lib/kward/prompt_interface/editor/markdown_code_block.rb', line 5 def language @language end |
#next_fence_start ⇒ Object
Returns the value of attribute next_fence_start
5 6 7 |
# File 'lib/kward/prompt_interface/editor/markdown_code_block.rb', line 5 def next_fence_start @next_fence_start end |
#open_line ⇒ Object
Returns the value of attribute open_line
5 6 7 |
# File 'lib/kward/prompt_interface/editor/markdown_code_block.rb', line 5 def open_line @open_line end |
#source ⇒ Object
Returns the value of attribute source
5 6 7 |
# File 'lib/kward/prompt_interface/editor/markdown_code_block.rb', line 5 def source @source end |
Instance Method Details
#code ⇒ Object
9 10 11 |
# File 'lib/kward/prompt_interface/editor/markdown_code_block.rb', line 9 def code source[body_start...body_end].to_s end |
#output_edit(output) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/kward/prompt_interface/editor/markdown_code_block.rb', line 19 def output_edit(output) replacement = MarkdownCodeBlock.format_output(output, newline: newline) match = output_match if match [match.begin(0), match.end(0), replacement] else insertion = if source[close_end - newline.length, newline.length] == newline "#{newline}#{replacement}#{newline}" else "#{newline}#{newline}#{replacement}#{newline}" end [close_end, close_end, insertion] end end |
#output_match ⇒ Object
13 14 15 16 17 |
# File 'lib/kward/prompt_interface/editor/markdown_code_block.rb', line 13 def output_match limit = next_fence_start || source.length match = source.match(/<output\b[^>]*>.*?<\/output>/mi, close_end) match if match && match.begin(0) < limit && match.end(0) <= limit end |
#with_output(output) ⇒ Object
34 35 36 37 |
# File 'lib/kward/prompt_interface/editor/markdown_code_block.rb', line 34 def with_output(output) start_index, end_index, replacement = output_edit(output) source.dup.tap { |content| content[start_index...end_index] = replacement } end |