Skip to content

Smart content-aware sorting for text nodes #1

@SyntaxAsSpiral

Description

@SyntaxAsSpiral

Vision

Canvas text nodes are containers for structured content, not just plain text. Semantic JSON should intelligently parse and sort based on content type:

  • YAML (templater templates, frontmatter, config)
  • Markdown (headers, hierarchy, documentation)
  • JSON (embedded data, API responses)
  • Code blocks (snippets with language context)

This positions semantic-json as a true lingua franca - visual IDE for structured data across formats.

Use Cases

Templater Templates (YAML)

Current: Alphabetical by full text content (chaotic)

"zapier webhook config"
"daily note template"
"meeting template"

Enhanced: Extract title/name field from YAML frontmatter

---
title: Daily Note Template
type: templater
priority: 1
---

→ Sorts by extracted title field

Markdown Hierarchy

Current: Treats headers as plain text

"# Main Topic"
"Regular text"
"## Subtopic"

Enhanced: Header-level aware sorting

# Main Topic     (level 1)
## Subtopic      (level 2)
### Detail       (level 3)
Regular text     (no header)

Creates implicit document structure from flat Canvas nodes.

Embedded JSON

Current: Sorts by raw JSON string
Enhanced: Extract id/name/title fields for semantic ordering

Technical Approach

Detection + Extraction Pattern

function getSmartSortKey(node: CanvasNode): string {
  const text = node.text;
  
  // YAML: Extract title/name field
  if (text.startsWith('---\n')) {
    const match = text.match(/(?:title|name):\s*(.+)/i);
    if (match) return match[1].toLowerCase().trim();
  }
  
  // Markdown: Extract first header (strip #)
  const headerMatch = text.match(/^(#+)\s+(.+)/m);
  if (headerMatch) {
    const level = headerMatch[1].length;
    const title = headerMatch[2];
    return `${level}_${title.toLowerCase().trim()}`; // hierarchy-aware
  }
  
  // JSON: Extract id/name/title
  if (text.trim().match(/^[\{\[]/)) {
    try {
      const obj = JSON.parse(text);
      const key = obj.id || obj.name || obj.title;
      if (key) return String(key).toLowerCase().trim();
    } catch {}
  }
  
  // Fallback: plain text
  return text.toLowerCase().trim().slice(0, 100);
}

Implementation Options

Option A: Settings Toggle

settings: {
  smartContentParsing: boolean,
  yamlKeyFields: ['title', 'name', 'id'], // priority order
  markdownStripFormatting: boolean,
}

Option B: Always-On Intelligence

Auto-detect format, gracefully degrade to plain text

Option C: Per-Node Type Hints

Future enhancement: Canvas metadata with contentType field

Considerations

  • Backward compatibility: Should default to current behavior or auto-enable?
  • Performance: Regex/JSON parsing on every node (likely negligible)
  • Extensibility: Plugin system for custom content parsers?
  • Edge cases: Mixed content, malformed YAML/JSON

Strategic Positioning

This elevates semantic-json from "deterministic Canvas ordering" to "intelligent structured content compiler" - turning visual Canvas into a semantic layer over heterogeneous text formats.

Especially powerful for:

  • Templater workflows
  • Zettelkasten with YAML metadata
  • API documentation (JSON examples in nodes)
  • Code snippet organization

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions