Class: Ace::Support::Items::Atoms::TitleExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/support/items/atoms/title_extractor.rb

Overview

Extracts the first H1 heading from markdown body content.

Class Method Summary collapse

Class Method Details

.extract(body) ⇒ String?

Extract title from the first ‘# H1` heading in body content

Parameters:

  • body (String)

    Markdown body content

Returns:

  • (String, nil)

    Extracted title or nil if none found



12
13
14
15
16
17
# File 'lib/ace/support/items/atoms/title_extractor.rb', line 12

def self.extract(body)
  return nil if body.nil? || body.empty?

  match = body.match(/^#\s+(.+)$/)
  match ? match[1].strip : nil
end