Skip to content

Smart Paste

The SmartPastePlugin detects structured content (JSON, XML) 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.

DetectorLanguageDescription
JSONjsonDetects valid JSON objects and arrays
XMLxmlDetects XML documents and fragments
interface SmartPasteConfig {
/** Additional content detectors to register. */
readonly detectors?: ContentDetector[];
/** Custom locale strings. */
readonly locale?: SmartPasteLocale;
}
OptionTypeDescription
detectorsContentDetector[]Additional content detectors to register
localeSmartPasteLocaleCustom locale strings

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

const myDetector: ContentDetector = {
detect(text: string): DetectionResult | null {
if (looksLikeYaml(text)) {
return { language: 'yaml', 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.