refac: citations
This commit is contained in:
@@ -55,15 +55,12 @@ export const replaceTokens = (content, sourceIds, char, user) => {
|
||||
|
||||
// Remove sourceIds from the content and replace them with <source_id>...</source_id>
|
||||
if (Array.isArray(sourceIds)) {
|
||||
sourceIds.forEach((sourceId) => {
|
||||
// Escape special characters in the sourceId
|
||||
const escapedSourceId = escapeRegExp(sourceId);
|
||||
|
||||
sourceIds.forEach((sourceId, idx) => {
|
||||
// Create a token based on the exact `[sourceId]` string
|
||||
const sourceToken = `\\[${escapedSourceId}\\]`; // Escape special characters for RegExp
|
||||
const sourceToken = `\\[${idx}\\]`; // Escape special characters for RegExp
|
||||
const sourceRegex = new RegExp(sourceToken, 'g'); // Match all occurrences of [sourceId]
|
||||
|
||||
content = content.replace(sourceRegex, `<source_id data="${sourceId}" />`);
|
||||
content = content.replace(sourceRegex, `<source_id data="${idx}" title="${sourceId}" />`);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user