mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-28 04:46:41 -04:00
Add optional build tag for experimental BEAN Markdown renderer support
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ var (
|
||||
)
|
||||
|
||||
const (
|
||||
MUTNVersion = "0.2.3" // untagged releases feature a letter suffix corresponding to the eventual release version, e.g "0.2.A" -> "0.2.0", "0.2.B" -> "0.2.1"
|
||||
MUTNVersion = "0.2.E" // untagged releases feature a letter suffix corresponding to the eventual release version, e.g "0.2.A" -> "0.2.0", "0.2.B" -> "0.2.1"
|
||||
|
||||
AnsiBold = "\033[1m"
|
||||
ansiBlackOnWhite = "\033[38;5;0;48;5;15m"
|
||||
|
||||
@@ -3,7 +3,6 @@ package cli
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/rwinkhart/libmutton/core"
|
||||
"github.com/rwinkhart/libmutton/sync"
|
||||
@@ -50,14 +49,13 @@ func EntryReader(decryptedEntry []string, hideSecrets, syncEnabled bool) {
|
||||
fmt.Println(ansiDirectoryHeader + "Notes:" + core.AnsiReset)
|
||||
|
||||
// combine remaining fields into a single string (to support Markdown rendering)
|
||||
var notesSlice []string
|
||||
var noteLines []string
|
||||
for ; field < len(decryptedEntry); field++ {
|
||||
notesSlice = append(notesSlice, decryptedEntry[field])
|
||||
noteLines = append(noteLines, decryptedEntry[field])
|
||||
}
|
||||
joinedString := strings.Join(notesSlice, "\n")
|
||||
|
||||
// print notes to stdout
|
||||
renderNote(&joinedString)
|
||||
renderNote(noteLines)
|
||||
|
||||
// break after notes have been printed
|
||||
break
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
//go:build !noMarkdown && BEAN
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
bean "github.com/Trojan2021/BEAN/render"
|
||||
)
|
||||
|
||||
// renderNote renders the notes section of an entry (in Markdown) to stdout.
|
||||
func renderNote(noteLines []string) {
|
||||
fmt.Println(bean.RenderMarkdown(noteLines, width))
|
||||
}
|
||||
@@ -4,9 +4,10 @@ package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 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")
|
||||
func renderNote(noteLines []string) {
|
||||
fmt.Print("\n" + strings.Join(noteLines, "\n") + "\n\n")
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
//go:build !noMarkdown
|
||||
//go:build !noMarkdown && !BEAN
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/glamour"
|
||||
)
|
||||
|
||||
// renderNote renders the notes section of an entry (in Markdown) to stdout.
|
||||
func renderNote(note *string) {
|
||||
func renderNote(noteLines []string) {
|
||||
note := strings.Join(noteLines, "\n")
|
||||
r, _ := glamour.NewTermRenderer(glamour.WithStylesFromJSONBytes(glamourStyle()), glamour.WithPreservedNewLines(), glamour.WithWordWrap(width))
|
||||
markdownNotesString, _ := r.Render(*note)
|
||||
markdownNotesString, _ := r.Render(note)
|
||||
|
||||
// print markdown-rendered notes
|
||||
fmt.Print(markdownNotesString)
|
||||
Reference in New Issue
Block a user