Class: LlmDocsBuilder::HtmlToMarkdown::FigureCodeBlockRenderer Private
- Inherits:
-
Object
- Object
- LlmDocsBuilder::HtmlToMarkdown::FigureCodeBlockRenderer
- Defined in:
- lib/llm_docs_builder/html_to_markdown/figure_code_block_renderer.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Converts
Constant Summary collapse
- GENERIC_CODE_CLASSES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Generic CSS class names commonly used for code formatting that should be ignored
%w[highlight code main gutter numbers line-numbers line-number line wrap table].freeze
Instance Attribute Summary collapse
-
#code_block_node ⇒ Nokogiri::XML::Node?
readonly
private
The identified code block node.
Instance Method Summary collapse
-
#initialize(element, inline_collapser:, fence_calculator:) ⇒ FigureCodeBlockRenderer
constructor
private
Initialize a new figure code block renderer.
-
#render ⇒ String?
private
Render the figure as a fenced code block.
Constructor Details
#initialize(element, inline_collapser:, fence_calculator:) ⇒ FigureCodeBlockRenderer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a new figure code block renderer
24 25 26 27 28 |
# File 'lib/llm_docs_builder/html_to_markdown/figure_code_block_renderer.rb', line 24 def initialize(element, inline_collapser:, fence_calculator:) @element = element @inline_collapser = inline_collapser @fence_calculator = fence_calculator end |
Instance Attribute Details
#code_block_node ⇒ Nokogiri::XML::Node? (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the identified code block node.
17 18 19 |
# File 'lib/llm_docs_builder/html_to_markdown/figure_code_block_renderer.rb', line 17 def code_block_node @code_block_node end |
Instance Method Details
#render ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Render the figure as a fenced code block
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/llm_docs_builder/html_to_markdown/figure_code_block_renderer.rb', line 33 def render @code_block_node = nil return unless code_figure? lines = extract_figure_code_lines return if lines.empty? language = detect_code_language caption = caption_text info_string = [language, caption].compact.reject(&:empty?).join(' ') code_body = lines.join("\n") fence = fence_calculator.call(code_body) opening_fence = info_string.empty? ? fence : "#{fence}#{info_string}" "#{opening_fence}\n#{code_body}\n#{fence}" end |