Add tag for building without Markdown support

This commit is contained in:
2024-07-16 15:30:48 -04:00
parent 66e9511eec
commit c6734dd283
4 changed files with 39 additions and 10 deletions
+7 -9
View File
@@ -5,7 +5,6 @@ import (
"os" "os"
"strings" "strings"
"github.com/charmbracelet/glamour"
"github.com/rwinkhart/MUTN/src/backend" "github.com/rwinkhart/MUTN/src/backend"
"github.com/rwinkhart/MUTN/src/sync" "github.com/rwinkhart/MUTN/src/sync"
) )
@@ -50,18 +49,17 @@ func EntryReader(decryptedEntry []string, hideSecrets, syncEnabled bool) {
// print the notes header // print the notes header
fmt.Println(ansiDirectoryHeader + "Notes:" + backend.AnsiReset) fmt.Println(ansiDirectoryHeader + "Notes:" + backend.AnsiReset)
// combine remaining fields into a single string (for markdown rendering) // combine remaining fields into a single string (to support Markdown rendering)
var markdownNotes []string var notesSlice []string
for ; field < len(decryptedEntry); field++ { for ; field < len(decryptedEntry); field++ {
markdownNotes = append(markdownNotes, decryptedEntry[field]) notesSlice = append(notesSlice, decryptedEntry[field])
} }
r, _ := glamour.NewTermRenderer(glamour.WithStylesFromJSONBytes(glamourStyle()), glamour.WithPreservedNewLines(), glamour.WithWordWrap(width)) joinedString := strings.Join(notesSlice, "\n")
markdownNotesString, _ := r.Render(strings.Join(markdownNotes, "\n"))
// print markdown-rendered notes // print notes to stdout
fmt.Print(markdownNotesString) renderNote(&joinedString)
// break after all lines have been printed // break after notes have been printed
break break
} }
} }
+18
View File
@@ -0,0 +1,18 @@
//go:build !noMarkdown
package cli
import (
"fmt"
"github.com/charmbracelet/glamour"
)
// renderNote renders the notes section of an entry (in Markdown) to stdout
func renderNote(note *string) {
r, _ := glamour.NewTermRenderer(glamour.WithStylesFromJSONBytes(glamourStyle()), glamour.WithPreservedNewLines(), glamour.WithWordWrap(width))
markdownNotesString, _ := r.Render(*note)
// print markdown-rendered notes
fmt.Print(markdownNotesString)
}
+12
View File
@@ -0,0 +1,12 @@
//go:build noMarkdown
package cli
import (
"fmt"
)
// renderNote prints the notes section of an entry to stdout (when Markdown rendering is disabled)
func renderNote(note *string) {
fmt.Print("\n" + *note + "\n\n")
}
+2 -1
View File
@@ -8,5 +8,6 @@ CGO_ENABLED=0 go build -ldflags="-s -w" -trimpath ./libmuttonserver.go
``` ```
Additionally, some custom build tags can be used to create different binaries. The following tags are not used in official builds: Additionally, some custom build tags can be used to create different binaries. The following tags are not used in official builds:
- `noMarkdown`: Creates a binary without Markdown support (much smaller binary size and faster launch time)
- `wsl`: Allows creating a Linux binary that can interact with the Windows clipboard (for WSL) - `wsl`: Allows creating a Linux binary that can interact with the Windows clipboard (for WSL)
- `termux`: Allows creating a Linux binary that can interact with the Termux clipboard (for Android) - `termux`: Allows creating a Linux binary that can interact with the Termux clipboard (for Android)