MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / _repl

Function _repl

openkb/lint.py:98–124  ·  view source on GitHub ↗
(m: re.Match)

Source from the content-addressed store, hash-verified

96 ghosts: list[str] = []
97
98 def _repl(m: re.Match) -> str:
99 raw = m.group(1)
100 if "|" in raw:
101 target, alias = raw.split("|", 1)
102 target = target.strip()
103 alias = alias.strip()
104 else:
105 target = raw.strip()
106 alias = None
107
108 # Direct hit
109 if target in known_targets:
110 return m.group(0)
111
112 # Fuzzy normalized hit → rewrite to canonical
113 canonical = norm_index.get(_normalize_target(target))
114 if canonical is not None:
115 if alias:
116 return f"[[{canonical}|{alias}]]"
117 return f"[[{canonical}]]"
118
119 # Ghost — strip brackets, leave readable display
120 ghosts.append(target)
121 if alias:
122 return alias
123 stem = target.rsplit("/", 1)[-1]
124 return stem.replace("-", " ").replace("_", " ")
125
126 cleaned = _WIKILINK_RE.sub(_repl, content)
127 return cleaned, ghosts

Callers

nothing calls this directly

Calls 2

_normalize_targetFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected