/** * @license Copyright (c) 2003-2026, CKSource Holding sp. z o.o. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options */ /** * @module code-block/utils */ import type { Editor } from "@ckeditor/ckeditor5-core"; import type { CodeBlockLanguageDefinition } from "./codeblockconfig.js"; import type { ModelDocumentSelection, ModelElement, Model, ModelPosition, ModelSchema, ModelText, ViewUpcastWriter, ViewDocumentFragment } from "@ckeditor/ckeditor5-engine"; import { type LocaleTranslate } from "@ckeditor/ckeditor5-utils"; /** * Returns code block languages as defined in `config.codeBlock.languages` but processed: * * * To consider the editor localization, i.e. to display {@link module:code-block/codeblockconfig~CodeBlockLanguageDefinition} * in the correct language. There is no way to use {@link module:utils/locale~Locale#t} when the user * configuration is defined because the editor does not exist yet. * * To make sure each definition has a CSS class associated with it even if not specified * in the original configuration. * * @internal */ export declare function getNormalizedAndLocalizedLanguageDefinitions(editor: Editor): Array; /** * Returns an object associating certain language definition properties with others. For instance: * * For: * * ```ts * const definitions = { * { language: 'php', class: 'language-php', label: 'PHP' }, * { language: 'javascript', class: 'js', label: 'JavaScript' }, * }; * * getPropertyAssociation( definitions, 'class', 'language' ); * ``` * * returns: * * ```ts * { * 'language-php': 'php', * 'js': 'javascript' * } * ``` * * and * * ```ts * getPropertyAssociation( definitions, 'language', 'label' ); * ``` * * returns: * * ```ts * { * 'php': 'PHP', * 'javascript': 'JavaScript' * } * ``` * * @internal */ export declare function getPropertyAssociation(languageDefs: Array, key: keyof CodeBlockLanguageDefinition, value: keyof CodeBlockLanguageDefinition): Record; /** * For a given model text node, it returns white spaces that precede other characters in that node. * This corresponds to the indentation part of the code block line. * * @internal */ export declare function getLeadingWhiteSpaces(textNode: ModelText): string; /** * For plain text containing the code (a snippet), it returns a document fragment containing * view text nodes separated by `
` elements (in place of new line characters "\n"), for instance: * * Input: * * ```ts * "foo()\n * bar()" * ``` * * Output: * * ```html * * "foo()" *
* "bar()" *
* ``` * * @param text The raw code text to be converted. * @internal */ export declare function rawSnippetTextToViewDocumentFragment(writer: ViewUpcastWriter, text: string): ViewDocumentFragment; /** * Returns an array of all model positions within the selection that represent code block lines. * * If the selection is collapsed, it returns the exact selection anchor position: * * ```html * []foo -> ^foo * foo[]bar -> foo^bar * ``` * * Otherwise, it returns positions **before** each text node belonging to all code blocks contained by the selection: * * ```html * * foo[bar ^foobar * -> * baz]qux ^bazqux * * ``` * * It also works across other non–code blocks: * * ```html * * foo[bar ^foobar * * text -> text * * baz]qux ^bazqux * * ``` * * **Note:** The positions are in reverse order so they do not get outdated when iterating over them and * the writer inserts or removes elements at the same time. * * **Note:** The position is located after the leading white spaces in the text node. * * @internal */ export declare function getIndentOutdentPositions(model: Model): Array; /** * Checks if any of the blocks within the model selection is a code block. * * @internal */ export declare function isModelSelectionInCodeBlock(selection: ModelDocumentSelection): boolean; /** * Checks if an {@link module:engine/model/element~ModelElement Element} can become a code block. * * @param schema Model's schema. * @param element The element to be checked. * @returns Check result. * @internal */ export declare function canBeCodeBlock(schema: ModelSchema, element: ModelElement): boolean; /** * Get the translated message read by the screen reader when you enter or exit an element with your cursor. * * @internal */ export declare function getCodeBlockAriaAnnouncement(t: LocaleTranslate, languageDefs: Array, element: ModelElement, direction: "enter" | "leave"): string; /** * For given position, finds the closest position that is at the beginning of a line of code and returns a text node that is at the * beginning of the line (or `null` if there's no text node at the beginning of a given line). * * Line beings at the start of a code block element and after each `softBreak` element. * * Note: even though code block doesn't allow inline elements other than `` by default, some features may overwrite this rule, * so such inline elements are taken into account. * * Some examples of expected results: * * ``` * ^ -> null * ^foobar -> [foobar] * foobar^ -> [foobar] * foo^bar -> [foobar] * foo^bar -> [foo]bar * foobar^ -> foo[bar] * foob^ar -> foo[bar] * foo^bar -> foo[bar] * ^ -> null * ^ -> null * foo^ -> [foo] * foo^ -> [foo] * foobar^ -> [foo]bar * bar^ -> null * foo^ -> null * foo^ -> null * foo^ -> null * foobar^ -> foo[bar] * fooba^r -> null * ``` * * @internal */ export declare function getTextNodeAtLineStart(position: ModelPosition, model: Model): ModelText | null;