| 30 | |
| 31 | class="cm">// Anchors can be derived from headers, or explicitly written as {#names}. |
| 32 | function 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 | |
| 49 | class="cm">// Internal links. |
| 50 | function getLinks(file, text) { |