all repos — searchix @ 93b800b4862d5c7e0e621647d78b79416a9f3101

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

internal/nixdocs/optlink/example/main.go (view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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())
}