Class: Markdown::Merge::FreezeNode

Inherits:
Ast::Merge::FreezeNodeBase
  • Object
show all
Defined in:
lib/markdown/merge/freeze_node.rb

Overview

Represents a frozen block of Markdown content that should be preserved during merges.

Freeze blocks are marked with HTML comments:

<!-- markdown-merge:freeze -->
... frozen content ...
<!-- markdown-merge:unfreeze -->

Content within freeze blocks is preserved exactly as-is during merge operations, preventing automated tools from modifying manually-curated sections.

Examples:

Basic freeze block

<!-- markdown-merge:freeze -->
## Custom Section
This content will not be modified by merge operations.
<!-- markdown-merge:unfreeze -->

Freeze block with reason

<!-- markdown-merge:freeze Manual TOC -->
## Table of Contents
- [Introduction](#introduction)
- [Usage](#usage)
<!-- markdown-merge:unfreeze -->

See Also:

  • Base class

Instance Method Summary collapse

Constructor Details

#initialize(start_line:, end_line:, content:, start_marker:, end_marker:, nodes: [], reason: nil) ⇒ FreezeNode

Initialize a new FreezeNode

Parameters:

  • start_line (Integer)

    Starting line number (1-indexed)

  • end_line (Integer)

    Ending line number (1-indexed)

  • content (String)

    Raw Markdown content within the block

  • start_marker (String)

    The freeze marker comment

  • end_marker (String)

    The unfreeze marker comment

  • nodes (Array) (defaults to: [])

    Parsed nodes within the block

  • reason (String, nil) (defaults to: nil)

    Optional reason extracted from marker



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/markdown/merge/freeze_node.rb', line 39

def initialize(start_line:, end_line:, content:, start_marker:, end_marker:, nodes: [], reason: nil)
  # Let the base class handle reason extraction via pattern_for
  super(
    start_line: start_line,
    end_line: end_line,
    content: content,
    nodes: nodes,
    start_marker: start_marker,
    end_marker: end_marker,
    pattern_type: :html_comment,
    reason: reason
  )
end

Instance Method Details

#contains_type?(type) ⇒ Boolean

Check if block contains a specific node type

Parameters:

  • type (Symbol)

    Node type to check for (e.g., :heading, :paragraph)

Returns:

  • (Boolean)

    True if block contains the node type



81
82
83
# File 'lib/markdown/merge/freeze_node.rb', line 81

def contains_type?(type)
  nodes.any? { |node| node.type == type }
end

#full_textString

Get the full text including markers

Returns:

  • (String)

    Complete freeze block with markers



66
67
68
# File 'lib/markdown/merge/freeze_node.rb', line 66

def full_text
  "#{start_marker}\n#{content}\n#{end_marker}"
end

#inspectString

String representation for debugging

Returns:

  • (String)

    Debug representation



88
89
90
# File 'lib/markdown/merge/freeze_node.rb', line 88

def inspect
  "#<#{self.class.name} lines=#{start_line}..#{end_line} nodes=#{nodes.size} reason=#{reason.inspect}>"
end

#line_countInteger

Get line count of the freeze block

Returns:

  • (Integer)

    Number of lines



73
74
75
# File 'lib/markdown/merge/freeze_node.rb', line 73

def line_count
  end_line - start_line + 1
end

#signatureArray<Symbol, String>

Generate a signature for matching this freeze block

Signatures are based on the normalized content, allowing freeze blocks with the same content to be matched across files.

Returns:

  • (Array<Symbol, String>)

    Signature array [:freeze_block, content_digest]



59
60
61
# File 'lib/markdown/merge/freeze_node.rb', line 59

def signature
  [:freeze_block, Digest::SHA256.hexdigest(content.strip)[0, 16]]
end