fix(tags): ignore escaped \#tag to align with Obsidian behavior; refs #438

This commit is contained in:
Quorafind 2025-09-16 09:32:09 +08:00
parent a94d20db22
commit 4a15c61432

View file

@ -471,8 +471,24 @@ export function extractTags(
}
// Find all #tags in the content with links and inline code replaced by placeholders
const tagMatches = processedContent.match(EMOJI_TAG_REGEX) || [];
task.metadata.tags = tagMatches.map((tag) => tag.trim());
// But ignore escaped tags (\#tag)
const allTagMatches = processedContent.match(EMOJI_TAG_REGEX) || [];
// Filter out escaped tags by checking the original content
const validTags: string[] = [];
for (const tag of allTagMatches) {
const tagIndex = processedContent.indexOf(tag);
if (tagIndex > 0) {
// Check if the character before the # is a backslash in the original content
// We need to check the remainingContent (not processedContent) for the backslash
const originalTagIndex = remainingContent.indexOf(tag);
if (originalTagIndex > 0 && remainingContent[originalTagIndex - 1] === '\\') {
// This is an escaped tag, skip it
continue;
}
}
validTags.push(tag.trim());
}
task.metadata.tags = validTags;
// Get configurable project prefix
const projectPrefix =