MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _remove_marker_section

Function _remove_marker_section

graphify/install.py:963–998  ·  view source on GitHub ↗

Remove every section whose heading line is exactly ``marker``. The heading is matched only when a line *is* exactly ``marker`` (after stripping surrounding whitespace), never as a substring. The old uninstall regex ``## graphify`` was unanchored, so it matched inside a user's ``###

(content: str, marker: str, boundary_prefix: str = "## ")

Source from the content-addressed store, hash-verified

961
962
963def _remove_marker_section(content: str, marker: str, boundary_prefix: str = "## ") -> "str | None":
964 """Remove every section whose heading line is exactly ``marker``.
965
966 The heading is matched only when a line *is* exactly ``marker`` (after
967 stripping surrounding whitespace), never as a substring. The old uninstall
968 regex ``## graphify`` was unanchored, so it matched inside a user's
969 ``### graphify`` heading and deleted hand-written content (#2062) — the same
970 class of bug the install side hardened against in #1688. Each section runs to
971 the line before the next ``boundary_prefix`` heading (default the next H2) or
972 EOF, mirroring ``_replace_or_append_section``. All exact-heading sections are
973 removed (pre-#1688 installs could leave duplicates).
974
975 Returns None when no exact ``marker`` line exists — the caller must then leave
976 the file untouched. This doubles as the guard: a substring mention (a bullet,
977 an inline reference, a deeper ``###`` heading) never triggers a strip.
978 """
979 lines = content.split("\n")
980 removed = False
981 while True:
982 starts = [i for i, line in enumerate(lines) if line.strip() == marker]
983 if not starts:
984 break
985 start = starts[-1]
986 end = len(lines)
987 for j in range(start + 1, len(lines)):
988 if lines[j].startswith(boundary_prefix):
989 end = j
990 break
991 head = "\n".join(lines[:start]).rstrip()
992 tail = "\n".join(lines[end:]).lstrip()
993 merged = head + "\n\n" + tail if head and tail else (head or tail)
994 lines = merged.split("\n")
995 removed = True
996 if not removed:
997 return None
998 return "\n".join(lines).rstrip()
999
1000
1001def _read_keep_newline(path: Path) -> "tuple[str, str]":

Callers 7

gemini_uninstallFunction · 0.85
vscode_uninstallFunction · 0.85
_agents_uninstallFunction · 0.85
codebuddy_uninstallFunction · 0.85

Calls 1

joinMethod · 0.45