diff --git a/parser/matcher/matcher_test.go b/parser/matcher/matcher_test.go index 864cc3b..8969889 100644 --- a/parser/matcher/matcher_test.go +++ b/parser/matcher/matcher_test.go @@ -17,14 +17,14 @@ func TestFuzzyFindAll(t *testing.T) { Needle string Start, End, StartIndex int }{ - {StartIndex: 0, Needle: "# Ingredients\n", Start: 77, End: 91}, - {StartIndex: 0, Needle: "# Ingrdients\n", Start: 77, End: 91}, - {StartIndex: 0, Needle: "# Inrdients\n", Start: 77, End: 91}, + {StartIndex: 0, Needle: "## Ingredients\n", Start: 90, End: 105}, + {StartIndex: 0, Needle: "## Ingrdients\n", Start: 90, End: 105}, + {StartIndex: 0, Needle: "## Inrdients\n", Start: 90, End: 105}, {StartIndex: 0, Needle: "---\n", Start: 0, End: 4}, - {StartIndex: 4, Needle: "---\n", Start: 29, End: 33}, - {StartIndex: 0, Needle: "# Steps\n", Start: 116, End: 124}, - {StartIndex: 0, Needle: "# Stps\n", Start: 116, End: 124}, - {StartIndex: 0, Needle: "# Step\n", Start: 116, End: 124}, + {StartIndex: 4, Needle: "---\n", Start: 43, End: 47}, + {StartIndex: 0, Needle: "## Steps\n", Start: 129, End: 138}, + {StartIndex: 0, Needle: "## Stps\n", Start: 129, End: 138}, + {StartIndex: 0, Needle: "## Step\n", Start: 129, End: 138}, } for _, test := range tests { @@ -51,6 +51,11 @@ func TestFuzzyBlockMatch(t *testing.T) { matches := matcher.MatchBlocksFuzzy(string(recipeMd), blocks, 0.3) + for _, b := range blocks { + fmt.Printf("Block: %+v\n", b) + fmt.Printf("Content: '%q'\n\n", b.GetContent()) + } + expected := []struct { value string }{ @@ -80,7 +85,7 @@ func TestFuzzyBlockMatch(t *testing.T) { t.FailNow() } if expected[i].value != m.GetContent() { - t.Errorf("Match %d did not match expected: %q", i, m.GetContent()) + t.Errorf("Match %d did not match expected: %q", i, expected[i].value) } fmt.Printf("match: %s->%q\n", m.Block.Path, m.GetContent()) } diff --git a/parser/parser.go b/parser/parser.go index 0834599..58fcd99 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -26,6 +26,9 @@ func DetectType(markdownContent string) (string, error) { blocks := matcher.MatchBlocksFuzzy(markdownContent, defaultSchema, 0.3) + fmt.Printf("%+v\n", blocks[0]) + fmt.Printf("Content: '%q'\n", blocks[0].GetContent()) + result, err := decoders.Parse(blocks) if err != nil { return "", fmt.Errorf("failed to parse blocks -> %w", err) @@ -37,6 +40,7 @@ func DetectType(markdownContent string) (string, error) { } return "", fmt.Errorf("frontmatter did not contain '_type'") } + return "", fmt.Errorf("could not parse frontmatter") } diff --git a/playground/src/lib/components/EditorPanel.svelte b/playground/src/lib/components/EditorPanel.svelte index 7a89082..574c0e2 100644 --- a/playground/src/lib/components/EditorPanel.svelte +++ b/playground/src/lib/components/EditorPanel.svelte @@ -38,7 +38,7 @@ }: Props = $props(); -
+
{#if status === 'success'} diff --git a/playground/src/lib/components/Header.svelte b/playground/src/lib/components/Header.svelte index 6a1d78b..65beb31 100644 --- a/playground/src/lib/components/Header.svelte +++ b/playground/src/lib/components/Header.svelte @@ -4,7 +4,7 @@
-
+
diff --git a/playground/src/lib/components/Playground.svelte b/playground/src/lib/components/Playground.svelte index 2e9d09a..879f085 100644 --- a/playground/src/lib/components/Playground.svelte +++ b/playground/src/lib/components/Playground.svelte @@ -102,6 +102,7 @@ My favourite baguette recipe dataStatus = 'error'; } } else { + templateError = undefined; jsonOutput = JSON.stringify(result.data, null, 2); timings = result.timings; templateStatus = 'success'; diff --git a/playground/src/lib/icons/Logo.svelte b/playground/src/lib/icons/Logo.svelte index fa4e15f..68c327c 100644 --- a/playground/src/lib/icons/Logo.svelte +++ b/playground/src/lib/icons/Logo.svelte @@ -1,4 +1,4 @@ -logo +logo