Skip to content

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] })

This plugin requires the CodeBlockPlugin to be loaded.

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.

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).

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

You can add custom detectors via configuration or at runtime via the service.

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] })
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);

When structured content is detected and formatted, the plugin announces the detection to screen readers.

None.

None.