Home / Function/ _is_custom_header() — langchain Function Reference

_is_custom_header() — langchain Function Reference

Architecture documentation for the _is_custom_header() function in markdown.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  c0f7b205_386f_81f7_010d_c9dac195bb30["_is_custom_header()"]
  6a11b5bb_e2e9_6671_54b0_3ed10f3c9672["MarkdownHeaderTextSplitter"]
  c0f7b205_386f_81f7_010d_c9dac195bb30 -->|defined in| 6a11b5bb_e2e9_6671_54b0_3ed10f3c9672
  b18c92c3_4d24_0e77_6322_b71c795c08ff["split_text()"]
  b18c92c3_4d24_0e77_6322_b71c795c08ff -->|calls| c0f7b205_386f_81f7_010d_c9dac195bb30
  style c0f7b205_386f_81f7_010d_c9dac195bb30 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/text-splitters/langchain_text_splitters/markdown.py lines 57–86

    def _is_custom_header(self, line: str, sep: str) -> bool:
        """Check if line matches a custom header pattern.

        Args:
            line: The line to check
            sep: The separator pattern to match

        Returns:
            `True` if the line matches the custom pattern format
        """
        if sep not in self.custom_header_patterns:
            return False

        # Escape special regex characters in the separator
        escaped_sep = re.escape(sep)
        # Create regex pattern to match exactly one separator at start and end
        # with content in between
        pattern = (
            f"^{escaped_sep}(?!{escaped_sep})(.+?)(?<!{escaped_sep}){escaped_sep}$"
        )

        match = re.match(pattern, line)
        if match:
            # Extract the content between the patterns
            content = match.group(1).strip()
            # Valid header if there's actual content (not just whitespace or separators)
            # Check that content doesn't consist only of separator characters
            if content and not all(c in sep for c in content.replace(" ", "")):
                return True
        return False

Subdomains

Called By

Frequently Asked Questions

What does _is_custom_header() do?
_is_custom_header() is a function in the langchain codebase, defined in libs/text-splitters/langchain_text_splitters/markdown.py.
Where is _is_custom_header() defined?
_is_custom_header() is defined in libs/text-splitters/langchain_text_splitters/markdown.py at line 57.
What calls _is_custom_header()?
_is_custom_header() is called by 1 function(s): split_text.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free