MCPcopy
hub / github.com/d3/d3 / getAnchors

Function getAnchors

test/docs-test.js:32–47  ·  test/docs-test.js::getAnchors
(text)

Source from the content-addressed store, hash-verified

30
31class="cm">// Anchors can be derived from headers, or explicitly written as {#names}.
32function getAnchors(text) {
33 const anchors = [class="st">""]; class="cm">// empty string for non-fragment links
34 for (const [, header] of text.matchAll(/^#+ ([*\w][*().,\w\d -]+)\n/gm)) {
35 anchors.push(
36 header
37 .replaceAll(/[^\w\d\s]+/g, class="st">" ")
38 .trim()
39 .replaceAll(/ +/g, class="st">"-")
40 .toLowerCase()
41 );
42 }
43 for (const [, anchor] of text.matchAll(/ \{#([\w\d-]+)\}/g)) {
44 anchors.push(anchor);
45 }
46 return anchors;
47}
48
49class="cm">// Internal links.
50function getLinks(file, text) {

Callers 1

docs-test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected