markmv - v1.41.7
    Preparing search index...

    Class SizeBasedSplitStrategy

    Split strategy that divides content based on file size limits.

    Creates new files when the current section exceeds a specified size limit. This ensures that no generated file becomes too large, which is useful for performance or platform constraints.

    Size-based splitting

      const strategy = new SizeBasedSplitStrategy({
    maxSize: 50, // 50KB per file
    outputDir: './chunks/',
    filenamePattern: '{original}-part-{index}'
    });

    const result = await strategy.split(content, 'large-document.md');
    console.log(`Split into ${result.sections.length} files under 50KB each`);

    Hierarchy (View Summary)

    Index

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

    • Separates a leading frontmatter block from the rest of the content.

      Parameters

      • content: string

        The full file content.

      Returns { content: string; frontmatter: string }

      The split content.

      • content: string

        The content following the frontmatter, or the whole input when there is none.

      • frontmatter: string

        The leading --- delimited block including its delimiters, or an empty string when there is none.

    • Generates a filename for a section from the filenamePattern option.

      {title} is replaced by the sanitised title (or section-N when that is empty), {index} by the one-based index and {original} by the original filename without its extension. The original file's extension is appended, defaulting to .md.

      Parameters

      • title: string

        The section title.

      • index: number

        The zero-based position of the section.

      • originalFilename: string

        The name of the file being split.

      Returns string

      The generated filename.

    • Returns the header level of a line.

      Parameters

      • line: string

        The line to inspect.

      Returns number

      The number of leading # characters when the line is a header (the markers followed by whitespace or the end of the line), otherwise 0.

    • Checks whether a line is a header of exactly the given level.

      Parameters

      • line: string

        The line to inspect.

      • targetLevel: number

        The header level to match.

      Returns boolean

      True when the line's header level equals targetLevel; headers of other levels do not match.

    • Converts a string into a filename-safe slug.

      The text is lower-cased, characters other than letters, digits, spaces and hyphens are removed, whitespace becomes hyphens, repeated and surrounding hyphens are collapsed, and the result is limited to 50 characters.

      Parameters

      • str: string

        The text to convert.

      Returns string

      The slug, which may be empty.

    • Splits into consecutive parts that stay within the maxSize option (in kilobytes, default 100).

      Lines are accumulated until adding the next one would exceed the limit, then a new part starts at that line, so splits fall on line boundaries and a single line larger than the limit becomes a part of its own. Each part is titled after the nearest header (searching backwards from its first line, then forwards), or Part N when the content has no headers. Filenames from the second part onwards carry an index suffix to keep them unique. An error is recorded when the content yields no parts.

      Parameters

      • content: string

        The full content of the file to split, including any frontmatter.

      • originalFilename: string

        The name of the file being split, used when generating section filenames.

      Returns Promise<SplitResult>

      The parts, with the frontmatter as remaining content when preserveFrontmatter is on.

    • Returns value unless it is nullish or zero, in which case fallback is used, since zero is not a meaningful value for these options (header levels start at 1, size limits must be positive).

      Parameters

      • value: number | undefined
      • fallback: number

      Returns number

    • Returns value unless it is nullish or the empty string, in which case fallback is used, an empty string is treated as "no value supplied" rather than a meaningful value to preserve.

      Parameters

      • value: string | null | undefined
      • fallback: string

      Returns string