all repos — searchix @ 93b800b4862d5c7e0e621647d78b79416a9f3101

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

feat: create option link parser Fixes: https://todo.sr.ht/~alanpearce/searchix/22

Alan Pearce
commit

93b800b4862d5c7e0e621647d78b79416a9f3101

parent

ad670006a58faa22a183212f3b68189b6ab8d5fa

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

changed files
A internal/nixdocs/optlink/example/main.go
@@ -0,0 +1,43 @@
+package main + +import ( + "bytes" + "fmt" + "os" + + "github.com/yuin/goldmark" + "go.alanpearce.eu/searchix/internal/nixdocs/optlink" +) + +func main() { + // Create a new Goldmark instance with our optlink extension + markdown := goldmark.New( + goldmark.WithExtensions( + optlink.New(), + ), + ) + + // Sample markdown content with option links + src := []byte(` +# Example using the OptLink Extension + +This is a regular paragraph with an empty link that points to an option: [](#opt-systemd.sysusers.enable) + +You can use multiple option links in the same document: +- [](#opt-networking.firewall.enable) +- [](#opt-services.openssh.enable) +- [](#opt-users.users.<n>.hashedPassword) + +Regular links still work normally: [NixOS](https://nixos.org) +`) + + // Convert the markdown to HTML + var buf bytes.Buffer + if err := markdown.Convert(src, &buf); err != nil { + fmt.Fprintf(os.Stderr, "Error converting markdown: %v\n", err) + os.Exit(1) + } + + // Print the resulting HTML + fmt.Println(buf.String()) +}