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 44 | package main
import (
"bytes"
"fmt"
"os"
"github.com/yuin/goldmark"
"alin.ovh/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())
}
|