Typix LogoTypix
Extensions

Keywords

Highlight specific keywords in the editor

The Keywords extension highlights predefined keywords in the editor content using a custom KeywordNode.

Demo

Loading preview...
import {  EditorContent,  EditorRoot,  createEditorConfig,  defaultExtensionNodes,} from "@typix-editor/react";import {  KeywordsExtension,  KeywordNode,} from "@typix-editor/extension-keywords";import { theme } from "./theme";import "./style.css";const config = createEditorConfig({  extensionNodes: [...defaultExtensionNodes, KeywordNode],  theme,});export default function KeywordsExample() {  return (    <EditorRoot config={config}>      <EditorContent placeholder='Type "congratulations" to see it highlighted...' />      <KeywordsExtension />    </EditorRoot>  );}

Installation

pnpm add @typix-editor/extension-keywords
npm install @typix-editor/extension-keywords
yarn add @typix-editor/extension-keywords

Setup

Register the KeywordNode and add the extension:

import { createEditorConfig, defaultExtensionNodes } from '@typix-editor/react';
import { KeywordsExtension, KeywordNode } from '@typix-editor/extension-keywords';

const config = createEditorConfig({
  extensionNodes: [...defaultExtensionNodes, KeywordNode],
});

function MyEditor() {
  return (
    <EditorRoot config={config}>
      <EditorContent />
      <KeywordsExtension />
    </EditorRoot>
  );
}

Exports

ExportTypeDescription
KeywordsExtensionComponentThe keyword detection plugin
KeywordNodeLexical NodeNode for highlighted keywords
$createKeywordNodeFunctionCreate a keyword node
$isKeywordNodeFunctionType guard for keyword nodes

Nodes

NodeDescription
KeywordNodeRenders keyword text with special styling. Must be registered in editor config.

On this page