Skip to content

CodeHighlighterComponent

A component that displays and edits code.

You can add this component using SettingEx.addCodeHighlighter.

In order to add the styles for the component, use initPluginContext in your plugin’s onload() function.

Alternatively, you can copy styles from https://github.com/mnaoumov/obsidian-dev-utils/releases/latest/download/styles.css.

Import:

import { CodeHighlighterComponent } from 'obsidian-dev-utils/obsidian/setting-components/code-highlighter-component';

Signature:

export class CodeHighlighterComponent extends ValueComponent<string> implements TextBasedComponent<string>, ValidatorComponent, ValueComponentWithChangeTracking<string>

Extends: ValueComponent<string>

Implements: TextBasedComponent<string>, ValidatorComponent, ValueComponentWithChangeTracking<string>

Constructor

new CodeHighlighterComponent(containerEl: HTMLElement)

Creates a new multiple text component.

Properties

PropertyTypeDescription
codeElHTMLElementThe <code> element that renders the syntax-highlighted overlay. Subclasses customizing the highlighting can target it.
preElHTMLElementThe <pre> element that wraps the highlighted code overlay. Subclasses customizing the highlighting can target it.
textAreaComponentTextAreaComponentThe inner text area component.
validatorElValidatorElementA validator element of the component.
(Inherited from ValidatorComponent)

Methods

MethodReturnsDescription
empty()voidEmpties the component.
getValue()stringGets the value of the component.
isEmpty()booleanChecks if the component is empty.
onChange(callback)thisAdds a change listener to the component.
onChange(callback)thisSets a callback function to be called when the value of the component changes.
(Inherited from ValueComponentWithChangeTracking)
setDisabled(disabled)thisSets the disabled state of the component.
setLanguage(language)thisSets the language for code highlighting.
setPlaceholder(placeholder)thisSets the placeholder of the component.
setPlaceholderValue(placeholderValue)thisSets the placeholder value of the component.
setPlaceholderValue(placeholderValue)thisSets the placeholder value of the component.
(Inherited from TextBasedComponent)
setTabSize(tabSize)thisSets the tab size of the component.
setValue(value)thisSets the value of the component.
simulateChange__()voidSimulate a change event.
updateHighlightedCode()Promise<void>Re-renders the highlighted code overlay from the current text area value. Subclasses can override to customize the render.

Links to this page: