Smart Paste
The SmartPastePlugin detects structured content (JSON, XML, Java, TypeScript) in pasted clipboard text and automatically inserts it as a formatted code block with the detected language.
import { SmartPastePlugin } from '@notectl/core/plugins/smart-paste';
new SmartPastePlugin()// or with custom detectors:new SmartPastePlugin({ detectors: [myDetector] })Dependencies
Section titled “Dependencies”This plugin requires the CodeBlockPlugin to be loaded.
How It Works
Section titled “How It Works”When text is pasted, the plugin runs registered content detectors against the plain text. Each detector returns a confidence score (0—1) and a language identifier. The detector with the highest confidence above the threshold wins, and the content is inserted as a code block with the detected language.
If the cursor is already inside a code block, smart paste is skipped.
Built-in Detectors
Section titled “Built-in Detectors”| Detector | Language | Description |
|---|---|---|
| JSON | json | Detects valid JSON objects and arrays |
| XML | xml | Detects XML documents and fragments |
| Java | java | Detects Java source code (class/interface/enum/record declarations, package/import statements, method signatures) |
| TypeScript | typescript | Detects TypeScript / modern JavaScript (ES module imports/exports, type aliases, interfaces, decorators, arrow functions, optional chaining). Includes negative signals to avoid misdetecting Java code. |
Detectors are registered automatically by the CodeBlockPlugin via the language registry. When multiple detectors match the same input, the one with the highest confidence wins; on ties the earliest-registered detector wins (registration order: Java → JSON → TypeScript → XML).
Configuration
Section titled “Configuration”interface SmartPasteConfig { /** Additional content detectors to register. */ readonly detectors?: readonly ContentDetector[]; /** Custom locale strings. */ readonly locale?: SmartPasteLocale;}| Option | Type | Description |
|---|---|---|
detectors | readonly ContentDetector[] | Additional content detectors to register |
locale | SmartPasteLocale | Custom locale strings |
Custom Detectors
Section titled “Custom Detectors”You can add custom detectors via configuration or at runtime via the service.
Via Configuration
Section titled “Via Configuration”const myDetector: ContentDetector = { id: 'yaml', detect(text: string): DetectionResult | null { if (looksLikeYaml(text)) { return { language: 'yaml', formattedText: text, confidence: 0.8 }; } return null; }};
new SmartPastePlugin({ detectors: [myDetector] })Via Service
Section titled “Via Service”import { SMART_PASTE_SERVICE_KEY } from '@notectl/core/plugins/smart-paste';
// Inside a plugin's init method:const smartPaste = context.getService(SMART_PASTE_SERVICE_KEY);smartPaste?.registerDetector(myDetector);Accessibility
Section titled “Accessibility”When structured content is detected and formatted, the plugin announces the detection to screen readers.
Commands
Section titled “Commands”None.
Keyboard Shortcuts
Section titled “Keyboard Shortcuts”None.