Skip to content

Implement TextNodeBehavior #130

Closed
Closed

Description

@malibio

Overview

Implement the TextNodeBehavior for handling general text content nodes with markdown support and mention extraction.

Prerequisites

Before starting this issue:

Implementation Tasks

  • Create TextNodeBehavior struct implementing NodeBehavior trait
  • Implement validation logic for text nodes
  • Add markdown content validation (optional feature)
  • Implement mention extraction for @node:node-id and [[node-id]] patterns
  • Add content processing for text normalization
  • Set default metadata for text nodes
  • Implement deletion behavior (clean up mentions)
  • Add comprehensive unit tests for all behavior methods

Acceptance Criteria

  • TextNodeBehavior properly implements all NodeBehavior trait methods
  • Validation prevents empty text content
  • Markdown validation works when enabled in metadata
  • Mention extraction correctly identifies node references in content
  • Content processing handles text normalization
  • Default metadata includes markdown_enabled, auto_save, word_wrap
  • Deletion behavior removes mentions properly
  • Unit tests cover validation, mention extraction, and edge cases
  • Code follows Rust best practices and passes cargo clippy

Technical Specifications

Implementation Pattern:

pub struct TextNodeBehavior;

impl NodeBehavior for TextNodeBehavior {
    fn type_name(&self) -> &'static str {
        "text"
    }

    fn validate(&self, node: &Node) -> Result<(), ValidationError> {
        // Validate non-empty content
        // Optional markdown validation if enabled
    }

    fn can_have_children(&self) -> bool {
        true // Text nodes can contain other nodes
    }

    fn supports_markdown(&self) -> bool {
        true
    }

    fn extract_mentions(&self, content: &str) -> Vec<String> {
        // Pattern: @node:node-id
        // Pattern: [[node-id]]
    }

    fn default_metadata(&self) -> Value {
        json!({
            "markdown_enabled": true,
            "auto_save": true,
            "word_wrap": true
        })
    }
}

Mention Extraction Patterns:

  • @node:node-id - Explicit node references
  • [[node-id]] - Wiki-style node links
  • Use regex crate for pattern matching

Dependencies:

Testing Requirements:

  • Test empty content validation
  • Test mention extraction with various patterns
  • Test markdown validation (if implemented)
  • Test default metadata generation
  • Test behavior with edge cases (special characters, etc.)

Related Issues

Implementation Notes

This provides the foundation for text content management in NodeSpace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions