import { KbqCodeBlockModule } from '@koobiq/components/code-block';Component which highlights blocks of code.
@Component({ selector: 'kbq-code-block', exportAs: 'kbqCodeBlock' })
class KbqCodeBlock {
readonly lineNumbers = input<boolean>(
this.defaultOptions?.lineNumbers ?? false
);
readonly filled = input<boolean>(false);
readonly canToggleSoftWrap = input<boolean>(false);
readonly softWrap = model<boolean>(false);
readonly viewAll = model<boolean>(false);
readonly maxHeight = input<number | undefined>();
readonly canDownload = input<boolean>(false);
readonly canCopy = input<boolean>(true);
readonly alwaysShowActionbar = input<boolean>(
this.defaultOptions?.alwaysShowActionbar ?? false
);
readonly files = input<KbqCodeBlockFile[]>([]);
readonly activeFileIndex = model<number>(0);
readonly noBorder = input<boolean>(false);
readonly hideTabs = model<boolean>(false);
toggleViewAll(): void;
scrollTo(options: KbqScrollbarScrollToOptions): void;
toggleSoftWrap(): void;
}lineNumbersboolean Whether to display line numbers. Defaults to lineNumbers of KBQ_CODE_BLOCK_DEFAULT_OPTIONS, or false.
filledboolean Whether the code block should be filled.
canToggleSoftWrapboolean Added soft wrap toggle button.
softWrapboolean Whether sequences of whitespace should be preserved.
viewAllboolean Allows to view all the code, otherwise it will be hidden.
Works only with maxHeight property.
maxHeightnumber | undefined Maximum height of the code block content, other parts will be hidden.
Can be toggled by viewAll property.
canDownloadboolean Added download code button.
canCopyboolean Added copy code button.
alwaysShowActionbarboolean Whether the actionbar should remain visible when tabs are hidden.
filesKbqCodeBlockFile[] Files to display.
activeFileIndexnumber Defines which file (index) is active.
noBorderboolean Whether to hide border.
hideTabsboolean Whether to hide header tabs. A single file without a filename hides them regardless - read
tabsHidden for what the header actually does.
Makes actionbar floating if tabs are hidden.
localeOverridesKbqPartialLocaleData | undefined Localized strings for this element and its subtree, keyed by locale section. Every key is optional at every depth.
toggleViewAll()void Toggles the viewAll property.
When viewAll is set to true, the content of the code block will be
displayed in its entirety. When set to false, the content will be
limited to the maxHeight property. If the content exceeds the
maxHeight, it will be scrolled to the top and the viewAll button
will be displayed.
scrollTo()void Scrolls the code content to the specified position.
toggleSoftWrap()void Toggles softWrap property.
When softWrap is set to true, the content of the code block will be
wrapped if it exceeds the height of the component. When set to false
the content will not be wrapped.
Marks a template as a custom tab link.
@Directive({
selector: 'ng-template[kbqCodeBlockTabLinkContent]',
exportAs: 'kbqCodeBlockTabLinkContent'
})
class KbqCodeBlockTabLinkContent {}Default options for kbq-code-block.
type KbqCodeBlockDefaultOptions = Partial<{
alwaysShowActionbar: boolean;
lineNumbers: boolean;
}>;alwaysShowActionbarboolean Whether the actionbar should remain visible when tabs are hidden. Defaults to false.
lineNumbersboolean Whether to display line numbers. Defaults to false.
Code block file object.
type KbqCodeBlockFile = {
content: string;
filename?: string;
language?: string;
link?: string;
};contentstring Code content.
filenamestring File name, which will be displayed in UI and when downloading.
If not provided, will be set to KBQ_CODE_BLOCK_FALLBACK_FILE_NAME.
languagestring File language, required for correct syntax highlighting. It has to be registered in languages of
KbqCodeBlockHighlightJsConfig, unless the full bundle of highlight.js is loaded. If not provided or not
registered, will be set to KBQ_CODE_BLOCK_FALLBACK_FILE_LANGUAGE, or to plaintext if that is not registered
either.
See the list of supported languages.
linkstring Link to the file, which will be opened in a new window.
Adds openExternalSystem button.
Configuration of highlight.js, which highlights the code of a code block: how to load it and which languages to
register. Without a configuration, the code block loads the highlight.js core, which has no languages, and shows the
code as plain text. Provide it with kbqCodeBlockHighlightJsConfigProvider.
type KbqCodeBlockHighlightJsConfig = Partial<{
core: () => Promise<{ default: HLJSApi }>;
languages: Record<string, () => Promise<{ default: LanguageFn }>>;
}>;core() => Promise<{ default: HLJSApi }> Lazy loader for the highlight.js instance. The core has no languages: register the ones the files use in
languages, or load all of them with () => import('highlight.js'), the full bundle of about 1 MB.
Defaults to () => import('highlight.js/lib/core').
languagesRecord<string, () => Promise<{ default: LanguageFn }>> Map of language name to lazy loader for that language's LanguageFn. A language of highlight.js loads from
highlight.js/lib/languages/<name>, where <name> is the name of its file in
src/languages. Plain text needs no
entry: the code block registers it as the fallback language.
Context provided to the tab link template: $implicit is the code block file for the current tab, and
fallbackFileName is displayed when the file has no explicit name.
type KbqTabLinkTemplateContext = {
$implicit: KbqCodeBlockFile;
fallbackFileName: string;
};Injection token used to configure the default options for all kbq-code-block components.
const KBQ_CODE_BLOCK_DEFAULT_OPTIONS: InjectionToken<KbqCodeBlockDefaultOptions>;Fallback language for code block if language is not supported/specified. It has to be registered in languages of
KbqCodeBlockHighlightJsConfig, unless it is plain text or the full bundle of highlight.js is loaded, or the code
block falls back to plaintext.
See the list of supported languages.
const KBQ_CODE_BLOCK_FALLBACK_FILE_LANGUAGE: InjectionToken<string>;Fallback file name for code block if file name is not specified.
const KBQ_CODE_BLOCK_FALLBACK_FILE_NAME: InjectionToken<string>;Injection token for configuring KbqCodeBlockHighlightJsConfig.
const KBQ_CODE_BLOCK_HIGHLIGHT_JS_CONFIG: InjectionToken<KbqCodeBlockHighlightJsConfig>;Localization configuration provider.
const KBQ_CODE_BLOCK_LOCALE_CONFIGURATION: InjectionToken<KbqCodeBlockLocaleConfiguration>;Utility provider for KBQ_CODE_BLOCK_DEFAULT_OPTIONS.
const kbqCodeBlockDefaultOptionsProvider: (
options: KbqCodeBlockDefaultOptions
) => Provider;Utility provider for KBQ_CODE_BLOCK_FALLBACK_FILE_LANGUAGE.
const kbqCodeBlockFallbackFileLanguageProvider: (
language: string
) => Provider;Utility provider for KBQ_CODE_BLOCK_FALLBACK_FILE_NAME.
const kbqCodeBlockFallbackFileNameProvider: (
fileName: string
) => Provider;Utility provider for KBQ_CODE_BLOCK_HIGHLIGHT_JS_CONFIG.
providers: [
kbqCodeBlockHighlightJsConfigProvider({
languages: {
typescript: () => import('highlight.js/lib/languages/typescript'),
css: () => import('highlight.js/lib/languages/css'),
html: () => import('highlight.js/lib/languages/xml')
}
})
]const kbqCodeBlockHighlightJsConfigProvider: (
options: KbqCodeBlockHighlightJsConfig
) => Provider;Utility provider for KBQ_CODE_BLOCK_LOCALE_CONFIGURATION. Only the strings you pass are overridden;
the rest keep following the active locale.
const kbqCodeBlockLocaleConfigurationProvider: (
configuration: KbqDeepPartial<KbqCodeBlockLocaleConfiguration>
) => Provider;