Class: Markdown::Merge::PartialTemplateMerger
- Inherits:
-
Ast::Merge::PartialTemplateMergerBase
- Object
- Ast::Merge::PartialTemplateMergerBase
- Markdown::Merge::PartialTemplateMerger
- Includes:
- PreservationSupport
- Defined in:
- lib/markdown/merge/partial_template_merger.rb
Overview
Markdown-specific implementation of PartialTemplateMerger.
Merges a partial template into a specific section of a destination markdown document. This class extends the parser-agnostic base with markdown-specific logic for:
- Heading-level-aware section boundaries
- Source-based text extraction to preserve link references and table formatting
- Backend-specific parser initialization (Markly, Commonmarker)
Constant Summary collapse
- Result =
Re-export Result class from base for convenience
Ast::Merge::PartialTemplateMergerBase::Result
Instance Attribute Summary collapse
-
#backend ⇒ Symbol
readonly
Backend to use (:markly, :commonmarker).
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(template:, destination:, anchor:, boundary: nil, backend: self.class.default_backend, preference: :template, add_missing: true, when_missing: :skip, replace_mode: false, signature_generator: nil, node_typing: nil, match_refiner: nil, normalize_whitespace: false, rehydrate_link_references: false) ⇒ PartialTemplateMerger
constructor
Initialize a markdown PartialTemplateMerger.
-
#merge ⇒ Result
Perform the partial template merge with post-processing.
Constructor Details
#initialize(template:, destination:, anchor:, boundary: nil, backend: self.class.default_backend, preference: :template, add_missing: true, when_missing: :skip, replace_mode: false, signature_generator: nil, node_typing: nil, match_refiner: nil, normalize_whitespace: false, rehydrate_link_references: false) ⇒ PartialTemplateMerger
Initialize a markdown PartialTemplateMerger.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/markdown/merge/partial_template_merger.rb', line 71 def initialize( template:, destination:, anchor:, boundary: nil, backend: self.class.default_backend, preference: :template, add_missing: true, when_missing: :skip, replace_mode: false, signature_generator: nil, node_typing: nil, match_refiner: nil, normalize_whitespace: false, rehydrate_link_references: false ) validate_backend!(backend) @backend = backend @normalize_whitespace = normalize_whitespace @rehydrate_link_references = rehydrate_link_references super( template: template, destination: destination, anchor: anchor, boundary: boundary, preference: preference, add_missing: add_missing, when_missing: when_missing, replace_mode: replace_mode, signature_generator: signature_generator, node_typing: node_typing, match_refiner: match_refiner, ) end |
Instance Attribute Details
#backend ⇒ Symbol (readonly)
Returns Backend to use (:markly, :commonmarker).
53 54 55 |
# File 'lib/markdown/merge/partial_template_merger.rb', line 53 def backend @backend end |
Class Method Details
.default_backend ⇒ Object
39 40 41 |
# File 'lib/markdown/merge/partial_template_merger.rb', line 39 def default_backend :markly end |
.file_analysis_class ⇒ Object
43 44 45 |
# File 'lib/markdown/merge/partial_template_merger.rb', line 43 def file_analysis_class FileAnalysis end |
.smart_merger_class ⇒ Object
47 48 49 |
# File 'lib/markdown/merge/partial_template_merger.rb', line 47 def smart_merger_class SmartMerger end |
Instance Method Details
#merge ⇒ Result
Perform the partial template merge with post-processing.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/markdown/merge/partial_template_merger.rb', line 109 def merge result = super # Apply post-processing if enabled if result.changed && (@normalize_whitespace || @rehydrate_link_references) content = result.content problems = DocumentProblems.new if @normalize_whitespace normalizer = WhitespaceNormalizer.new(content) content = normalizer.normalize problems.merge!(normalizer.problems) end if @rehydrate_link_references rehydrator = LinkReferenceRehydrator.new(content) content = rehydrator.rehydrate problems.merge!(rehydrator.problems) end # Return new result with transformed content and problems Result.new( content: content, has_section: result.has_section, changed: result.changed, stats: result.stats.merge(problems: problems.all), injection_point: result.injection_point, message: result. ) else result end end |