Class: Chiridion::Engine::PostProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/chiridion/engine/post_processor.rb

Overview

Post-processes rendered markdown for consistent formatting.

Handles normalization that’s easier to do as a final pass rather than trying to get perfect output from templates. May grow into fuller linting/validation over time.

Current normalizations:

  • Collapse multiple consecutive newlines to single newlines

  • Ensure 2 newlines before horizontal rules (—)

  • Preserve frontmatter formatting

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.process(content) ⇒ String

Normalize markdown content.

Parameters:

  • content (String)

    Raw markdown content

Returns:

  • (String)

    Normalized content



20
21
22
# File 'lib/chiridion/engine/post_processor.rb', line 20

def self.process(content)
  new.process(content)
end

Instance Method Details

#process(content) ⇒ String

Returns Normalized content.

Parameters:

  • content (String)

    Raw markdown content

Returns:

  • (String)

    Normalized content



26
27
28
29
30
31
32
33
34
35
# File 'lib/chiridion/engine/post_processor.rb', line 26

def process(content)
  # Split off frontmatter to preserve it exactly
  frontmatter, body = split_frontmatter(content)

  # Normalize the body
  normalized = normalize_newlines(body)

  # Reassemble
  frontmatter ? "#{frontmatter}\n\n#{normalized}" : normalized
end