Anchors

Summary

How anchors are parsed

There are two types of anchors:

  • headers
# 1234

Hello world
  • block anchors
hello world ^1234

Startup

At startup, Dendron finds all anchors for a ntoe

  • src/drivers/file/storev2.ts
_initNotes {
    ...
    notes.forEach n => {
        anchors = findAnchors(n)
        ...
        n.anchors = anchors
    }
    ...

}
  • src/markdown/remark/utils.ts
findAnchors(note) {
    noteContents := note
    anchors = RemarkUtils.findAnchors(noteContents)
    return anchors.map anchor => {
        anchorNode2anchor(anchor)
    }
}

RemarkUtils.findAnchors(contents) {
    resp = procRehypeParse.parse(content)
    return [
        selectAll(HEADING, resp),
        selectAll(BLOCK_ANCHOR, resp)
    ]
}

anchorNode2anchor(node) {
    if node.type = HEADING {
        text, value, depth := node
        return {
            type: HEADING,
            text, value, depth
        }
    } else if node.type = BLOCK_ANCHOR {
        ...
    }
}

Remark