Refactor variable highlighting regex in constants.ts and fix error handling in genericModal
This commit is contained in:
parent
8b99087cff
commit
e0989c0f53
2 changed files with 25 additions and 6 deletions
|
|
@ -25,10 +25,18 @@ export const INVALID_CHARACTERS = [
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* regex to highlight the variables in the text
|
* regex to highlight the variables in the text
|
||||||
* @constant
|
* @constant regexHighlight
|
||||||
|
* @type {RegExp}
|
||||||
|
* @default
|
||||||
|
* @example
|
||||||
|
* {{variable}} or {variable}
|
||||||
|
* @returns {RegExp}
|
||||||
|
* @description
|
||||||
|
* This regex is used to highlight the variables in the text.
|
||||||
|
* It matches the variables in the text that are between {{}} or {}.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const regexHighlight = /\{([^}]+)\}/g;
|
export const regexHighlight = /\{\{(.*?)\}\}|\{([^{}]+)\}/g;
|
||||||
export const specialCharsRegex = /[!@#$%^&*()\-_=+[\]{}|;:'",.<>/?\\`´]/;
|
export const specialCharsRegex = /[!@#$%^&*()\-_=+[\]{}|;:'",.<>/?\\`´]/;
|
||||||
|
|
||||||
export const programmingLanguages: languageMap = {
|
export const programmingLanguages: languageMap = {
|
||||||
|
|
|
||||||
|
|
@ -97,13 +97,24 @@ export default function GenericModal({
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setInputValue(value);
|
setInputValue(value);
|
||||||
}, [value, modalOpen]);
|
}, [value, modalOpen]);
|
||||||
|
|
||||||
const coloredContent = (inputValue || "")
|
const coloredContent = (inputValue || "")
|
||||||
.replace(/</g, "<")
|
.replace(/</g, "<")
|
||||||
.replace(/>/g, ">")
|
.replace(/>/g, ">")
|
||||||
.replace(regexHighlight, varHighlightHTML({ name: "$1" }))
|
.replace(regexHighlight, (match, p1, p2) => {
|
||||||
.replace(/\n/g, "<br />");
|
// Decide which group was matched. If p1 is not undefined, do nothing
|
||||||
|
// we don't want to change the text. If p2 is not undefined, then we
|
||||||
|
// have a variable, so we should highlight it.
|
||||||
|
// ! This will not work with multiline or indented json yet
|
||||||
|
if (p1 !== undefined) {
|
||||||
|
return match;
|
||||||
|
} else if (p2 !== undefined) {
|
||||||
|
return varHighlightHTML({ name: p2 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return match;
|
||||||
|
})
|
||||||
|
.replace(/\n/g, "<br />");
|
||||||
|
console.log(coloredContent);
|
||||||
function getClassByNumberLength(): string {
|
function getClassByNumberLength(): string {
|
||||||
let sumOfCaracteres: number = 0;
|
let sumOfCaracteres: number = 0;
|
||||||
wordsHighlight.forEach((element) => {
|
wordsHighlight.forEach((element) => {
|
||||||
|
|
@ -159,7 +170,7 @@ export default function GenericModal({
|
||||||
setIsEdit(true);
|
setIsEdit(true);
|
||||||
return setErrorData({
|
return setErrorData({
|
||||||
title: PROMPT_ERROR_ALERT,
|
title: PROMPT_ERROR_ALERT,
|
||||||
list: [error.toString()],
|
list: [error.response.data.detail ?? ""],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue