Skip to content

Hybrid Markdown Rendering #47

Closed
Closed

Description

@malibio

Overview

Implement hybrid markdown rendering where users see both syntax characters AND formatting simultaneously during editing. This builds on the simplified CodeMirror foundation from Issue #46.

Scope

Core hybrid syntax + formatting feature:

  • Build on always-editing CodeMirror foundation from CodeMirror Foundation Setup #46
  • Apply heading font sizes (H1-H6) while preserving syntax characters (#, ##, etc.)
  • Match font sizes to existing MarkdownRenderer display mode exactly
  • Real-time updates as user types (using CodeMirror's debounced events)
  • TextNode extends BaseNode with multiline={true} and markdown={true}

Technical Specifications

Exact Font Size Requirements

Match existing MarkdownRenderer heading sizes:

```css
/* Heading sizes to replicate in CodeMirror theme */
.cm-header1 { font-size: 2rem; font-weight: 600; line-height: 1.38em; }
.cm-header2 { font-size: 1.5rem; font-weight: 600; line-height: 1.38em; }
.cm-header3 { font-size: 1.2rem; font-weight: 600; line-height: 1.15em; }
.cm-header4 { font-size: 1rem; font-weight: 600; line-height: 1.15em; }
.cm-header5 { font-size: 0.9rem; font-weight: 600; line-height: 1.15em; }
.cm-header6 { font-size: 0.8rem; font-weight: 600; line-height: 1.15em; }
```

CodeMirror Theme Configuration

```javascript
import { EditorView } from '@codemirror/view'
import { markdown } from '@codemirror/lang-markdown'

// NodeSpace hybrid theme with heading sizes
const nodeSpaceHybridTheme = EditorView.theme({
'.cm-header1': { fontSize: '2rem', fontWeight: '600', lineHeight: '1.38em' },
'.cm-header2': { fontSize: '1.5rem', fontWeight: '600', lineHeight: '1.38em' },
'.cm-header3': { fontSize: '1.2rem', fontWeight: '600', lineHeight: '1.15em' },
'.cm-header4': { fontSize: '1rem', fontWeight: '600', lineHeight: '1.15em' },
'.cm-header5': { fontSize: '0.9rem', fontWeight: '600', lineHeight: '1.15em' },
'.cm-header6': { fontSize: '0.8rem', fontWeight: '600', lineHeight: '1.15em' },
});

// Extensions for TextNode (markdown={true})
const markdownExtensions = [
markdown(),
nodeSpaceHybridTheme
];
```

Component Integration

TextNode extends BaseNode with markdown enabled:
```svelte
<!-- TextNode.svelte -->
<BaseNode
{nodeId}
{content}
multiline={true} <!-- Enable multiline editing -->
markdown={true} <!-- Enable hybrid markdown rendering -->
on:contentChanged
/>
```

CodeMirrorEditor applies theme when `markdown={true}`:
```svelte
<!-- CodeMirrorEditor.svelte -->

<script> \$: extensions = [ // Base extensions... ...(markdown ? [markdownLanguage(), hybridTheme] : []) ]; </script>

```

Implementation Tasks

  • Create NodeSpace hybrid markdown theme with exact heading font sizes
  • Integrate theme into CodeMirrorEditor when `markdown={true}`
  • Implement real-time syntax detection and class application
  • Verify font sizes match MarkdownRenderer output exactly
  • Test all markdown heading levels (H1-H6)
  • Verify syntax characters remain visible during formatting
  • Ensure smooth real-time updates without lag
  • Test TextNode inheritance pattern works correctly

Acceptance Criteria

  • Typing `# Header` shows large font (2rem) immediately while keeping `#` visible
  • Removing `#` character returns to normal font size immediately
  • All heading levels (H1-H6) work with exact font sizes specified above
  • Font sizes match MarkdownRenderer display mode pixel-perfectly
  • No visual lag or glitches during real-time updates (< 50ms)
  • Syntax characters (`#`, `##`, etc.) remain fully visible
  • Cursor position preserved during font size changes
  • Multiple headings in same document work correctly
  • Heading detection only occurs at line start (not mid-line)
  • TextNode properly extends BaseNode with `markdown={true}`

Definition of Done

  • Hybrid markdown rendering works end-to-end in TextNode
  • All acceptance criteria met and verified
  • Font size matching verified visually and through tests
  • Performance benchmarks pass (< 50ms update times)
  • Real-time updates work smoothly across all heading levels
  • Code follows project standards (linting passes)
  • Component composition inheritance verified working
  • Ready for Performance & Bundle Optimization #49 (performance optimization)

Dependencies

Related Issues

Activity

  1. added
    enhancement
    on Aug 11, 2025
  2. added a commit that references this issue on Aug 11, 2025
  3. self-assigned this
    on Aug 11, 2025
  4. malibio commented on Aug 16, 2025

    @malibio
    CollaboratorAuthor

    🔄 Architecture Decision Update

    Closing CodeMirror-based hybrid markdown rendering as our research determined that enhanced contenteditable with Logseq patterns is the optimal approach.

    Key Decision Points:

    • NodeSpace's indented node indicators are architecturally superior to ProseMirror/CodeMirror approaches
    • Logseq's dual-representation pattern provides the hybrid rendering we need
    • Enhanced contenteditable preserves our unique hierarchical value proposition

    Superseded by:

    The hybrid markdown functionality will be implemented using our enhanced contenteditable foundation with real-time AST processing for seamless syntax/formatting display.

  5. added 2 commits that reference this issue on Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions