Designed to highlight a part of the text with a certain template. The plugin settings are very simple, you define a regular expression, finding which, the plugin will replace it with the function result.
IDictionary<(jodit: IJodit, matches: RegExpMatchArray) => HTMLElement>
{}
A dictionary where keys are regular expressions and values are functions that return HTML elements to wrap matched text.
Copyconst editor = Jodit.make('#editor', { highlightSignature: { schema: { '[^\\s]+@[a-z.-]+': (jodit) => jodit.createInside.element('strong') } } });
number
0
The delay in milliseconds between processing chunks of text. This can be useful to prevent UI freezing when processing large documents.
Copyconst editor = Jodit.make('#editor', { highlightSignature: { processDelay: 10, // 10ms delay between processing chunks schema: { // your schema here } } });
number
300
The number of text nodes to process in a single chunk. This helps to optimize performance by breaking the processing into smaller chunks.
Copyconst editor = Jodit.make('#editor', { highlightSignature: { processInChunkCount: 500, // Process 500 nodes at once schema: { // your schema here } } });
HTMLTagNames[]
['pre']
An array of HTML tag names that should be excluded from processing. By default, the plugin doesn't process text inside <pre>
tags.
Copyconst editor = Jodit.make('#editor', { highlightSignature: { excludeTags: ['pre', 'code', 'script'], // Don't process text in these tags schema: { // your schema here } } });
But this temporary element will not get into the final HTML.
For example, we need to highlight email addresses everywhere:
Copyconst editor = Jodit.make('#editor', { highlightSignature: { schema: { '[^\\s]+@[a-z.-]+': (jodit) => jodit.createInside.element('strong') } } }); editor.value = '<p>Hi Valery chupurnov@gmail.om</p>'; console.log(editor.value); // '<p>Hi Valery chupurnov@gmail.om</p>' console.log(editor.getNativeEditorValue()); // '<p>Hi Valery <strong data-jodit="temp">chupurnov@gmail.om</strong></p>'
The final value does not change. And in the original textarea
the value not wrapped in the strong
tag will be saved.
Now let's highlight something else. Let us have macros ${formSubmittedDate}
, ${formSessionURL}
which
need to be highlighted with different background color.
Copyconst editor = Jodit.make('#editor', { highlightSignature: { schema: { '\\$\\{([^}]+)\\}': (jodit, matched) => { let color = 'yellow'; // all another macros will be `yellow` switch (matched[1]) { case 'formSubmittedDate': color = 'red'; break; case 'formSessionURL': color = '#0f0'; break; } const span = jodit.createInside.element('span', { style: { backgroundColor: color } }); return span; } } } }); editor.value = '<p>The text ${formSubmittedDate} and ${formSessionURL} has some styling/decoration around it.</p>'; console.log(editor.value); // '<p>The text ${formSubmittedDate} and ${formSessionURL} has some styling/decoration around it.</p>' console.log(editor.element.value); // '<p>The text ${formSubmittedDate} and ${formSessionURL} has some styling/decoration around it.</p>' console.log(editor.getNativeEditorValue()); // '<p>The text <span data-jodit="temp" style="background-color:red">${formSubmittedDate}</span> and <span data-jodit="temp" style="background-color:#0f0">${formSessionURL}</span> has some styling/decoration around it.</p>' console.log(editor.editor.innerHTML === editor.getNativeEditorValue()); // true
For large documents with many text nodes, you can optimize performance by adjusting the processing delay and chunk size:
Copyconst editor = Jodit.make('#editor', { highlightSignature: { processDelay: 5, // 5ms delay between chunks processInChunkCount: 200, // Process 200 nodes at a time schema: { '\\b\\d{3}-\\d{3}-\\d{4}\\b': (jodit) => { // Highlight phone numbers const span = jodit.createInside.element('span', { style: { backgroundColor: '#e6f7ff', borderBottom: '1px dashed #1890ff' } }); return span; } } } });
You can exclude specific tags from processing:
Copyconst editor = Jodit.make('#editor', { highlightSignature: { excludeTags: ['pre', 'code', 'script', 'style'], schema: { '\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}\\b': (jodit) => { // Highlight email addresses const span = jodit.createInside.element('span', { style: { color: 'blue', textDecoration: 'underline' } }); return span; } } } });
This approach allows you to visually highlight specific patterns in the editor without affecting the final HTML output.