Class: Markbridge::Renderers::Discourse::Builders::ListItemBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/markbridge/renderers/discourse/builders/list_item_builder.rb

Overview

Builder for list item formatting Handles complex multi-line formatting with proper indentation and preservation of blank lines and nested list items

Instance Method Summary collapse

Instance Method Details

#build(content, marker:, indent:) ⇒ String

Build a formatted list item string

Parameters:

  • content (String)

    the item content

  • marker (String)

    the list marker (“- ” or “1. ”)

  • indent (String)

    the indentation string

Returns:

  • (String)


16
17
18
19
20
21
22
23
24
25
# File 'lib/markbridge/renderers/discourse/builders/list_item_builder.rb', line 16

def build(content, marker:, indent:)
  lines = content.split("\n")
  lines = [""] if lines.empty? # Handle empty content
  first_line = "#{indent}#{marker}#{lines.first}"

  return "#{first_line}\n" if lines.size == 1

  # Handle multi-line content with sophisticated blank line handling
  format_multiline(lines, first_line, indent)
end