I have some characters that need to be replaced as above but I don't know how:
characters to replace:
first | end |
<day> | |
<red> | </red>|
<a ###> | </> |
day => get now day (ex: 14)
red => color red
<a ###https://www.google.com/>link</> => <a href="https://www.google.com/">link</>
input: hello <red>Mr.Siro</red>
output: hello <span style="color: red">Mr.Siro</span>
Can you show me how to write a common function to check the replacement of the above tags? here is my code:
export const formatTags = (content) => {
const firstTag = "<red>";
const secondTag = "</red>";
const tagsIndex = [...content.matchAll(new RegExp(firstTag, "gi"))].map(
(a) => a.index
);
const initialContent = content;
tagsIndex.forEach((index) => {
const tagContent = initialContent.substring(
index + firstTag.length,
initialContent.indexOf(secondTag, index)
);
if (firstTag === "<red>") {
content = content.replaceAll(
`${firstTag}${tagContent}${secondTag}`,
`<span style="color: red">${tagContent || "わからない"}</span>`
);
}
});
return content;
};
<span
:class="(msg.image || msg.file) && msg.text ? 'mt-2' : ''"
v-html="msg.text"
v-linkified:options="{
className: currentUserId === msg.senderId
? 'message-external-link'
: '',
}"
/>
sorry my english is not so good !
thanks all!