Skip to content

Commit

Permalink
support of evernote links fine tuned
Browse files Browse the repository at this point in the history
  • Loading branch information
akosbalasko committed Sep 6, 2023
1 parent 4da33a9 commit 3f09ba6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/models/InternalLink.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface InternalLink {
id: string;
url: string;
title: string;
uniqueEnd?: string;
Expand Down
12 changes: 8 additions & 4 deletions src/runtime-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface NoteIdNameEntry {
noteName: string;
notebookName: string;
uniqueEnd: string;
url: string
}

export interface NoteIdNames {
Expand Down Expand Up @@ -34,18 +35,21 @@ export class RuntimePropertiesSingleton {
}

addItemToMap(linkItem: InternalLink): void {
this.noteIdNameMap[linkItem.url] = {
...this.noteIdNameMap[linkItem.url],
this.noteIdNameMap[linkItem.id] = {
...this.noteIdNameMap[linkItem.id],
url: linkItem.url,
title: linkItem.title,
noteName: this.currentNoteName,
notebookName: this.currentNotebookName,
uniqueEnd: linkItem.uniqueEnd,

};
}
addItemToTOCMap(linkItem: InternalLink): void {
this.noteIdNameTOCMap[linkItem.url] = {
...this.noteIdNameMap[linkItem.url],
this.noteIdNameTOCMap[linkItem.id] = {
...this.noteIdNameMap[linkItem.id],
title: linkItem.title,
url: linkItem.url,
noteName: this.currentNoteName,
notebookName: this.currentNotebookName,
uniqueEnd: linkItem.uniqueEnd,
Expand Down
23 changes: 17 additions & 6 deletions src/utils/turndown-rules/internal-links-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ export const removeBrackets = (str: string): string => {
export const removeDoubleBackSlashes = (str: string): string => {
return str.replace(/\\/g, '');
};
const isEvernoteLink = (value: string): boolean => {
return value.startsWith('evernote:///view') || value.startsWith('https://www.evernote.com')
}
const getEvernoteUniqueId = (value: string): string => {
const urlSpl = value.split('/').reverse()
return (urlSpl[0] !== '')
? urlSpl[0]
: urlSpl[1]
}
export const wikiStyleLinksRule = {
filter: filterByNodeName('A'),
replacement: (content: any, node: any) => {
Expand Down Expand Up @@ -50,7 +59,7 @@ export const wikiStyleLinksRule = {
? `![[${realValue}]]`
: getShortLinkIfPossible(token, value);
}
if (value.match(/^(https?:|www\.|file:|ftp:|mailto:)/)) {
if (value.match(/^(https?:|www\.|file:|ftp:|mailto:)/) && !value.startsWith("https://www.evernote.com")) {
return getShortLinkIfPossible(token, value);
}

Expand All @@ -63,17 +72,19 @@ export const wikiStyleLinksRule = {
&& yarleOptions.obsidianSettings.omitLinkDisplayName;
const renderedObsidianDisplayName = omitObsidianLinksDisplayName ? '' : `|${displayName}`;

if (value.startsWith('evernote://')) {
if (isEvernoteLink(value) ) {
const fileName = normalizeTitle(token['text']);
const noteIdNameMap = RuntimePropertiesSingleton.getInstance();
const uniqueId = getUniqueId();
const uniqueEnd = getUniqueId();
const id = getEvernoteUniqueId(value)
if (isTOC(noteIdNameMap.getCurrentNoteName())) {
noteIdNameMap.addItemToTOCMap({ url: value, title: fileName, uniqueEnd: uniqueId });
noteIdNameMap.addItemToTOCMap({ id, url: value, title: fileName, uniqueEnd });

} else {
noteIdNameMap.addItemToMap({ url: value, title: fileName, uniqueEnd: uniqueId });
noteIdNameMap.addItemToMap({ id, url: value, title: fileName, uniqueEnd });
}

const linkedNoteId = value;
const linkedNoteId = id;
if (isHeptaOrObsidianOutput()) {
return `${mdKeyword}[[${linkedNoteId}${extension}${renderedObsidianDisplayName}]]`;
}
Expand Down

0 comments on commit 3f09ba6

Please sign in to comment.