diff --git a/parser/parser.go b/parser/parser.go
index d1c8e09..0834599 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -16,19 +16,19 @@ import (
func DetectType(markdownContent string) (string, error) {
defaultSchemaContent, err := registry.GetTemplate("_default")
if err != nil {
- return "", fmt.Errorf("could not get schema: %w", err)
+ return "", fmt.Errorf("could not get schema -> %w", err)
}
defaultSchema, err := template.CompileTemplate(defaultSchemaContent)
if err != nil {
- return "", fmt.Errorf("failed to compile template: %w", err)
+ return "", fmt.Errorf("failed to compile template -> %w", err)
}
blocks := matcher.MatchBlocksFuzzy(markdownContent, defaultSchema, 0.3)
result, err := decoders.Parse(blocks)
if err != nil {
- return "", fmt.Errorf("failed to parse blocks: %w", err)
+ return "", fmt.Errorf("failed to parse blocks -> %w", err)
}
if result, ok := result.(map[string]any); ok {
@@ -45,7 +45,7 @@ func MatchBlocks(markdownContent, templateContent string) ([]matcher.Block, erro
tpl, err := template.CompileTemplate(templateContent)
if err != nil {
- return nil, fmt.Errorf("failed to compile template: %w", err)
+ return nil, fmt.Errorf("failed to compile template -> %w", err)
}
return matcher.MatchBlocksFuzzy(markdownContent, tpl, 0.3), nil
@@ -59,21 +59,21 @@ func ParseFile(markdownContent string) (any, error) {
contentType, err := DetectType(markdownContent)
if err != nil {
- return nil, fmt.Errorf("could not detect type: %w", err)
+ return nil, fmt.Errorf("could not detect type -> %w", err)
}
timings["detect_type"] = time.Since(startDetectType).Milliseconds()
startGetTemplate := time.Now()
templateContent, err := registry.GetTemplate(contentType)
if err != nil {
- return nil, fmt.Errorf("could not get schema: %w", err)
+ return nil, fmt.Errorf("could not get schema -> %w", err)
}
timings["get_template"] = time.Since(startGetTemplate).Milliseconds()
startTemplate := time.Now()
tpl, err := template.CompileTemplate(templateContent)
if err != nil {
- return nil, fmt.Errorf("failed to compile template: %w", err)
+ return nil, fmt.Errorf("failed to compile template -> %w", err)
}
timings["template_compilation"] = time.Since(startTemplate).Milliseconds()
@@ -82,7 +82,7 @@ func ParseFile(markdownContent string) (any, error) {
result, err := decoders.Parse(blocks)
if err != nil {
- return nil, fmt.Errorf("failed to parse blocks: %w", err)
+ return nil, fmt.Errorf("failed to parse blocks -> %w", err)
}
timings["markdown_parsing"] = time.Since(startMarkdown).Milliseconds()
@@ -102,7 +102,7 @@ func ParseFileWithTemplate(markdownContent string, templateContent string) (any,
tpl, err := template.CompileTemplate(templateContent)
if err != nil {
- return nil, fmt.Errorf("failed to compile template: %w", err)
+ return nil, fmt.Errorf("failed to compile template -> %w", err)
}
timings["template_compilation"] = time.Since(startTemplate).Milliseconds()
@@ -111,7 +111,7 @@ func ParseFileWithTemplate(markdownContent string, templateContent string) (any,
result, err := decoders.Parse(blocks)
if err != nil {
- return nil, fmt.Errorf("failed to parse blocks: %w", err)
+ return nil, fmt.Errorf("failed to parse blocks -> %w", err)
}
timings["markdown_parsing"] = time.Since(startMarkdown).Milliseconds()
diff --git a/playground/src/lib/components/EditorPanel.svelte b/playground/src/lib/components/EditorPanel.svelte
index d692853..7a89082 100644
--- a/playground/src/lib/components/EditorPanel.svelte
+++ b/playground/src/lib/components/EditorPanel.svelte
@@ -15,6 +15,7 @@
children?: Snippet;
headerActions?: Snippet;
subtitle?: string;
+ error?: string;
status?: 'success' | 'error' | 'indeterminate';
timing?: number;
pillText?: string;
@@ -23,6 +24,7 @@
let {
title,
+ error,
value = $bindable(),
placeholder = '',
readonly = false,
@@ -69,21 +71,20 @@
{timing}ms
{/if}
-
+ {#if error}
+
+ {/if}
+
+
{#if children}
{@render children()}
diff --git a/playground/src/lib/components/Playground.svelte b/playground/src/lib/components/Playground.svelte
index d88aeed..2e9d09a 100644
--- a/playground/src/lib/components/Playground.svelte
+++ b/playground/src/lib/components/Playground.svelte
@@ -4,7 +4,6 @@
import {
getTemplate,
listTemplates,
- matchBlocks,
parseMarkdown,
parseMarkdownWithTemplate,
wasmReady,
@@ -57,6 +56,7 @@ My favourite baguette recipe
let timings = $state(null);
let templateStatus = $state<'success' | 'error' | 'indeterminate' | undefined>(undefined);
let dataStatus = $state<'success' | 'error' | 'indeterminate' | undefined>(undefined);
+ let templateError = $state();
$effect(() => {
if (typeof window !== 'undefined') {
@@ -91,11 +91,13 @@ My favourite baguette recipe
: parseMarkdown(markdownValue);
if ('error' in result) {
- jsonOutput = result.error;
+ jsonOutput = '';
if (result.error.startsWith('failed to compile template')) {
+ templateError = result.error.replaceAll(' -> ', '\n ⟶ ');
templateStatus = 'error';
dataStatus = 'indeterminate';
} else {
+ templateError = undefined;
templateStatus = undefined;
dataStatus = 'error';
}
@@ -138,6 +140,7 @@ My favourite baguette recipe
title="Template"
bind:value={templateValue}
placeholder="Enter your Marka template here..."
+ error={templateError}
status={templateStatus}
timing={timings?.template_compilation}
subtitle="Define your mapping schema"
diff --git a/playground/static/logo.svg b/playground/static/logo.svg
index 19a6963..e4f85db 100644
--- a/playground/static/logo.svg
+++ b/playground/static/logo.svg
@@ -1,15 +1,15 @@
-