markmv - v1.41.7
    Preparing search index...

    Class BaseMergeStrategyAbstract

    Abstract base class for all merge strategies.

    Provides common functionality for merging markdown files including transclusion handling, conflict detection, and frontmatter management. Concrete strategies implement specific merging approaches.

    Implementing a custom merge strategy

      class CustomMergeStrategy extends BaseMergeStrategy {
    async merge(targetContent: string, sourceContent: string): Promise<MergeResult> {
    // Custom merging logic
    const conflicts = this.detectConflicts(targetContent, sourceContent);
    return this.buildResult(mergedContent, conflicts);
    }
    }

    Hierarchy (View Summary)

    Index
    • Creates a merge strategy.

      The defaults are automatic conflict resolution, a blank line between merged sections, no transclusions, frontmatter merging, structure preservation, the ![[{file}#{section}]] transclusion template and a maximum transclusion depth. Any supplied option overrides its default.

      Parameters

      Returns BaseMergeStrategy

    The effective options for this strategy: the supplied options layered over the defaults set in the constructor.

    • Builds a transclusion reference from the configured transclusionTemplate.

      The .md extension is dropped from the file name. Without a section, the #{section} part of the template is removed.

      Parameters

      • file: string

        The file to reference.

      • Optionalsection: string

        The section within the file, if any.

      Returns string

      The transclusion text.

    • Detects whether transcluding the source into the target would create a loop.

      A loop is reported when any existing transclusion mentions the target file name, or when the source and target are the same file.

      Parameters

      • targetFile: string

        The path of the file being merged into.

      • sourceFile: string

        The path of the file that would be transcluded.

      • existingTransclusions: readonly string[]

        The transclusion references already in the target.

      Returns boolean

      True when a loop would result.

    • Extracts every markdown header from content.

      Parameters

      • content: string

        The markdown content to scan.

      Returns { level: number; line: number; text: string }[]

      One entry per header, in document order.

      • level: number

        The header level, equal to the number of # characters.

      • line: number

        The one-based line number of the header.

      • text: string

        The header text, without the # markers.

    • Extracts Obsidian transclusions (![[file]] or ![[file#section]]) from content.

      Parameters

      • content: string

        The markdown content to scan.

      Returns { file: string; line: number; ref: string; section?: string }[]

      One entry per transclusion, in document order.

      • file: string

        The referenced file, with a .md extension added when the reference had none.

      • line: number

        The one-based line number on which the transclusion appears.

      • ref: string

        The full transclusion text as written, for example ![[notes#intro]].

      • Optionalsection?: string

        The referenced section, when the reference includes one after #.

    • Finds source headers that also exist in the target.

      Headers match when their text is equal ignoring case and they have the same level.

      Parameters

      • targetContent: string

        The target's content.

      • sourceContent: string

        The source's content.

      Returns { header: string; sourceLine: number; targetLine: number }[]

      One entry per colliding source header.

      • header: string

        The text of the source header.

      • sourceLine: number

        The one-based line of the header in the source.

      • targetLine: number

        The one-based line of the matching header in the target.

    • Merges the content of a source file into a target file.

      Each concrete strategy decides where the source content is placed. Conflicts are reported in the result rather than thrown, and a failure while merging is reported through errors with success set to false.

      Parameters

      • targetContent: string

        The full content of the file being merged into, including any frontmatter.

      • sourceContent: string

        The full content of the file being merged from, including any frontmatter.

      • targetFile: string

        The path of the target file, used in conflict reports and transclusion loop checks.

      • sourceFile: string

        The path of the source file, used in conflict reports and transclusion references.

      Returns Promise<MergeResult>

      The merged content and frontmatter, the files involved, and any conflicts, warnings, errors and created transclusions.

    • Merges the frontmatter of the target and source.

      When only one side has frontmatter it is returned unchanged. Otherwise, for keys present on both sides the target's value wins, except that tags, categories and keywords are combined as de-duplicated lists when both sides hold lists.

      Parameters

      • targetFrontmatter: string

        The target's raw frontmatter block, or an empty string.

      • sourceFrontmatter: string

        The source's raw frontmatter block, or an empty string.

      Returns string

      The merged frontmatter block, or an empty string when neither side has any.