Link Search Menu Expand Document

Remark

Summary

This goes over how Dendron parses markdown files

Init

Get Processor

This starts markdown parsing. It’s called in multiple points (eg. dendron-cli, dendron markdown preview enhanced, etc) when markdown needs to be converted.

  • file: engine-server/src/topics/markdown/utils.ts
getProcessor() 
    .use(markdownParse, { gfm: true })
    .use(frontmatterPlugin, ["yaml"])
    .use(dendronLinksPlugin)
    .use(dendronRefsPlugin, { root, renderWithOutline, replaceRefs })
    .use({ settings: { listItemIndent: "1", fences: true } });

Note References

References are parsed using the dendronRefsPlugin.

  • file: engine-server/src/topics/markdown/plugins/dendronRefsPlugin.ts

Parse

plugin.inlineTokenizer(eat, value) {
    if match(eat, DENDRON_REF):
        link := match

        return {
            type: refLink,
            value: normalize(link)
        }
}

Stringify

plugin.Compiler {
    visitor.refLink(content) {
        link := 
        bodyOfTarget = read(link)
        markers = findRef(link, bodyOfTarget)
        return modifyContent(content, markers)
    }
}