fix: make sure to handle any numbers of ending newlines
All checks were successful
Build and Push Server / build-and-push (push) Successful in 2m52s

This commit is contained in:
Max Richter
2025-10-24 18:30:30 +02:00
parent 026537fa05
commit 53e6c6fb9f
2 changed files with 7 additions and 4 deletions

View File

@@ -41,8 +41,6 @@ func DetectType(markdownContent string) (string, error) {
} }
func MatchBlocks(markdownContent, templateContent string) ([]matcher.Block, error) { func MatchBlocks(markdownContent, templateContent string) ([]matcher.Block, error) {
markdownContent = strings.TrimSuffix(markdownContent, "\n")
tpl, err := template.CompileTemplate(templateContent) tpl, err := template.CompileTemplate(templateContent)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to compile template -> %w", err) return nil, fmt.Errorf("failed to compile template -> %w", err)
@@ -66,13 +64,16 @@ func ParseFile(markdownContent string) (any, error) {
} }
func ParseFileWithTemplate(markdownContent string, templateContent string) (any, error) { func ParseFileWithTemplate(markdownContent string, templateContent string) (any, error) {
markdownContent = strings.TrimSuffix(markdownContent, "\n")
tpl, err := template.CompileTemplate(templateContent) tpl, err := template.CompileTemplate(templateContent)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to compile template -> %w", err) return nil, fmt.Errorf("failed to compile template -> %w", err)
} }
for strings.HasSuffix(markdownContent, "\n") {
markdownContent = strings.TrimSuffix(markdownContent, "\n")
}
markdownContent = markdownContent + "\n"
blocks := matcher.MatchBlocksFuzzy(markdownContent, tpl, 0.3) blocks := matcher.MatchBlocksFuzzy(markdownContent, tpl, 0.3)
result, err := decoders.Parse(blocks) result, err := decoders.Parse(blocks)

View File

@@ -2,6 +2,7 @@ package adapters
import ( import (
"errors" "errors"
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -118,6 +119,7 @@ func (l *LocalFsAdapter) readFile(path string, root string) (*Entry, error) {
if err == nil { if err == nil {
content = parsedContent content = parsedContent
} else { } else {
fmt.Println(err)
// Fallback to raw content on parsing error // Fallback to raw content on parsing error
content = fileContent content = fileContent
} }