MCPcopy Create free account
hub / github.com/Qinbf/groundmap / resolveBlockTarget

Function resolveBlockTarget

web/components/HashScroller.tsx:44–54  ·  view source on GitHub ↗

* 把锚点元素归一到「该参考块的起点元素」。 * * convert.py 把「块级锚点」一律追加到块的**最后一行**,于是渲染后 id 落在块的最后一个 * 子元素上: * - 表格 → 最后一行的某个 ` `(经 relocateTableRowAnchors 搬入单元格) * - 多项列表 → 最后一个 ` `(整张列表是一个 ^p-N 块、锚点只标在末项) * - 多段引用块 → 最后一个 ` ` * - 代码块 → ` ` 内的 ` `(高亮 code 会漏掉 pre 的内边距/边框,看着只高亮一部分) * 直接滚到

(el: HTMLElement)

Source from the content-addressed store, hash-verified

42 * 嵌套列表取最外层(^p-N 块本就是顶层列表)。爬到正文 / 滚动容器边界即停,绝不整页归一。
43 */
44function resolveBlockTarget(el: HTMLElement): HTMLElement {
45 let target: HTMLElement = el;
46 for (
47 let cur: HTMLElement | null = el;
48 cur && !cur.matches?.("[data-kb-scroll-main], main, article, body");
49 cur = cur.parentElement
50 ) {
51 if (cur.matches?.("table, ul, ol, blockquote, pre")) target = cur; // 记最外层命中
52 }
53 return target;
54}
55
56const HIGHLIGHT_CLASS = "kb-hash-highlight"; // 单块:背景 + 外圈
57const HIGHLIGHT_REGION_CLASS = "kb-hash-highlight-region"; // 多块连片:仅背景,避免每段都套一圈

Callers 1

tryScrollFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected