mindmap

package
v0.31.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package mindmap turns a note's Markdown outline (its headings and nested list items) into a Mermaid `mindmap` diagram. It's the terminal/agent counterpart to the web app's interactive mind map: `nt mindmap <note>` (and the MCP nt_mindmap tool) emit a ```mermaid``` fence an agent can drop straight into a note — where nt's own web viewer, Obsidian, or GitHub render it.

The parser is a deliberately small line scanner (headings + lists, skipping fenced code) rather than a full Markdown AST: notes are simple, the mapping is the markmap model (H1 trunk → headings branches → bullets leaves), and a pure function is trivially unit-tested.

Index

Constants

View Source
const MaxNodes = 400

MaxNodes bounds a single map so a pathological note can't produce a runaway diagram (mirrors the web view's cap).

Variables

This section is empty.

Functions

func Fence

func Fence(mermaid string) string

Fence wraps a Mermaid body in a ```mermaid``` code block, so the output pastes straight into a note and renders in nt's web viewer / Obsidian / GitHub.

func Mermaid

func Mermaid(root *Node, maxDepth int) string

Mermaid renders the tree as a Mermaid `mindmap` body (no code fence). maxDepth limits how many levels below the root are emitted (0 = all). Indentation is two spaces per level, which is what mindmap uses to infer hierarchy.

Types

type Node

type Node struct {
	Text     string  `json:"text"`
	Children []*Node `json:"children,omitempty"`
}

Node is one entry in the outline tree (the root carries the note title).

func Outline

func Outline(body, title string) *Node

Outline parses a note body into a tree rooted at the title. Headings nest by level; a list under a heading (or before the first heading, under the root) contributes its items, with sub-lists nested by indentation. Fenced code blocks and plain paragraphs are ignored — a mind map is the skeleton.

func WikiTree

func WikiTree(root *note.Note, notes []*note.Note, doc *task.Doc, maxDepth int) *Node

WikiTree builds a breadth-first mind-map tree rooted at `root`, radiating along resolved [[wikilinks]] between notes (undirected, up to maxDepth hops). It's the terminal/agent counterpart to the web app's "Links" map: notes only, each note appears once at its shortest distance, neighbors visited in title order.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL