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"
"strings"
"github.com/charmbracelet/glamour"
"github.com/rwinkhart/MUTN/src/backend"
"github.com/rwinkhart/MUTN/src/sync"
)
@@ -50,18 +49,17 @@ func EntryReader(decryptedEntry []string, hideSecrets, syncEnabled bool) {
// print the notes header
fmt.Println(ansiDirectoryHeader + "Notes:" + backend.AnsiReset)
// combine remaining fields into a single string (for markdown rendering)
var markdownNotes []string
// combine remaining fields into a single string (to support Markdown rendering)
var notesSlice []string
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))
markdownNotesString, _ := r.Render(strings.Join(markdownNotes, "\n"))
joinedString := strings.Join(notesSlice, "\n")
// print markdown-rendered notes
fmt.Print(markdownNotesString)
// print notes to stdout
renderNote(&joinedString)
// break after all lines have been printed
// break after notes have been printed
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")
}