Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions apps/obsidian/src/utils/tagNodeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ const HIDE_DELAY = 100;
const OBSERVER_RESTART_DELAY = 100;
const TOOLTIP_OFFSET = 40;

const LIST_INDICATOR_REGEX = /^(\s*)(\d+[.)]\s+|[-*+]\s+(?:\[[ xX]\]\s+)?)/;

const sanitizeTitle = (title: string): string => {
const invalidChars = /[\\/:]/g;

// Remove list item indicators (numbered, bulleted, etc.)
const listIndicator = /^(\s*)(\d+\.\s+|-\s+|\*\s+|\+\s+)/;

return title
.replace(listIndicator, "")
.replace(LIST_INDICATOR_REGEX, "")
.replace(invalidChars, "")
.replace(/\s+/g, " ")
.trim();
};

const extractListPrefix = (line: string): string => {
const match = line.match(LIST_INDICATOR_REGEX);
return match ? match[0] : "";
};

type ExtractedTagData = {
fullLineContent: string;
tagName: string;
Expand Down Expand Up @@ -350,9 +354,11 @@ export class TagNodeHandler {
return;
}

// Replace the entire line with just the discourse node link
const listPrefix = extractListPrefix(actualLineText);
const replacementText = listPrefix + linkText;

editor.replaceRange(
linkText,
replacementText,
{ line: lineNumber, ch: 0 },
{ line: lineNumber, ch: actualLineText.length },
);
Expand Down