all repos — searchix @ d2962720cfd4b4f022ccd564f39189db1ccfa0b7

Search engine for NixOS, nix-darwin, home-manager and NUR users

feat: parse {var} in markdown documentation

Alan Pearce
commit

d2962720cfd4b4f022ccd564f39189db1ccfa0b7

parent

7ab69fb0411fc260e3f3ea519443abd87ace3a7e

1 file changed, 44 insertions(+), 0 deletions(-)

changed files
A internal/nixdocs/variable/example/main.go
@@ -0,0 +1,44 @@
+package main + +import ( + "bytes" + "fmt" + "os" + + "github.com/yuin/goldmark" + "go.alanpearce.eu/searchix/internal/nixdocs/variable" +) + +func main() { + // Create a new Goldmark instance with our variable extension + md := goldmark.New( + goldmark.WithExtensions( + variable.New(), + ), + ) + + // Some example Markdown content with variable references + src := []byte(` +# Variable References Example + +Nix packages like {var}` + "`pkgs.virtualbox`" + ` and {var}` + "`pkgs.firefox`" + ` +can be installed in your system. + +The {var}` + "`services.postgresql.enable`" + ` option enables the PostgreSQL service. + +Configuration variables are often found in these contexts: +- {var}` + "`system.stateVersion`" + ` for system configuration +- {var}` + "`networking.hostName`" + ` for network settings +- {var}` + "`users.users.alice`" + ` for user accounts +`) + + // Convert the markdown to HTML + var buf bytes.Buffer + if err := md.Convert(src, &buf); err != nil { + fmt.Println("Conversion error:", err) + os.Exit(1) + } + + // Print the HTML output + fmt.Println(buf.String()) +}