Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 556 possible improvement to add file link function #557

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
25 changes: 24 additions & 1 deletion src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,30 @@ export class FormatConverter {
}

format_note_with_url(note: AnkiConnectNote, url: string, field: string): void {
note.fields[field] += '<br><a href="' + url + '" class="obsidian-link">Obsidian</a>'
let mdFilename: string = ""

// We separate the string by "&file=".
const splitUrl: string[] = url.split("&file=");

// Check if the split resulted in two parts
if (splitUrl.length === 2) {
// Extract the part after "&file="
const encodedPathWithExtension: string = splitUrl[1]; // Extracted part containing path with extension
const decodedPathWithExtension: string = decodeURIComponent(encodedPathWithExtension);

// Split the filename from its directory path
const pathSegments: string[] = decodedPathWithExtension.split('/');
const filenameWithExtension: string | undefined = pathSegments.pop()?.trim();

// Check if the filename with extension is not empty
if (filenameWithExtension) {
// Split the filename from its extension
const filenameSegments: string[] = filenameWithExtension.split('.');
mdFilename = filenameSegments[0]?.trim();
}
}

note.fields[field] += '<br><a href="' + url + `" class="obsidian-link">Obsidian${mdFilename ? " - " + mdFilename : ""}</a>`;
}

format_note_with_frozen_fields(note: AnkiConnectNote, frozen_fields_dict: Record<string, Record<string, string>>): void {
Expand Down
Loading