about summary refs log tree commit diff stats
path: root/internal/options/option.go
diff options
context:
space:
mode:
authorAlan Pearce2024-05-06 10:14:17 +0200
committerAlan Pearce2024-05-06 10:14:17 +0200
commitc0fbf11f843af84e8891a708c4d217dd6c523473 (patch)
tree1fca048be6f784dd895d2c2d9ff09200d5d610fd /internal/options/option.go
parent7d08b696e9ab6de61c53a5dc9153595a5a8a6d98 (diff)
downloadsearchix-c0fbf11f843af84e8891a708c4d217dd6c523473.tar.lz
searchix-c0fbf11f843af84e8891a708c4d217dd6c523473.tar.zst
searchix-c0fbf11f843af84e8891a708c4d217dd6c523473.zip
feat: render markdown examples
Diffstat (limited to 'internal/options/option.go')
-rw-r--r--internal/options/option.go62
1 files changed, 11 insertions, 51 deletions
diff --git a/internal/options/option.go b/internal/options/option.go
index b8b838a..a43dd49 100644
--- a/internal/options/option.go
+++ b/internal/options/option.go
@@ -1,67 +1,27 @@
 package options
 
-import (
-	"encoding/json"
-	"strings"
-
-	"github.com/pkg/errors"
-	"github.com/yuin/goldmark"
-	"github.com/yuin/goldmark/extension"
-)
+type Markdown string
 
 type NixValue struct {
-	Type string `json:"_type" mapstructure:"_type"`
-	Text string `json:"text"`
-}
-
-type HTML struct {
-	HTML string
-}
-
-var md = goldmark.New(
-	goldmark.WithExtensions(extension.NewLinkify()),
-)
-
-func (html *HTML) UnmarshalText(text []byte) error {
-	var out strings.Builder
-	err := md.Convert(text, &out)
-	if err != nil {
-		return errors.WithMessage(err, "failed to convert markdown to HTML")
-	}
-
-	html.HTML = out.String()
-
-	return nil
-}
-
-func (html *HTML) UnmarshalJSON(raw []byte) error {
-	var v struct {
-		HTML string
-	}
-	err := json.Unmarshal(raw, &v)
-	if err != nil {
-		return errors.WithMessage(err, "error unmarshaling json")
-	}
-	html.HTML = v.HTML
-
-	return nil
+	Text     string   `json:",omitempty"`
+	Markdown Markdown `json:",omitempty"`
 }
 
 type Link struct {
 	Name string
-	URL  string `json:"url"`
+	URL  string
 }
 
 type NixOption struct {
-	Option          string
+	Option string
+
 	Declarations    []Link
-	Default         NixValue
-	Description     HTML
-	Example         NixValue
-	ReadOnly        bool
-	Type            string
+	Default         *NixValue `json:",omitempty"`
+	Description     Markdown
+	Example         *NixValue `json:",omitempty"`
 	Loc             []string
-	RelatedPackages HTML
+	RelatedPackages Markdown `json:",omitempty"`
+	Type            string
 }
 
 type NixOptions []NixOption