Skip to content

Commit

Permalink
fix: unrecognized guid/links added (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
akosbalasko authored Feb 27, 2024
1 parent 5cb0b52 commit 99da0ef
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/utils/apply-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,31 @@ export const applyLinks = (options: YarleOptions, outputNotebookFolders: Array<s

}
}


}



}
const unrecognizable = "Unrecognizable";

for (const targetFile of allconvertedFiles) {
const fileContent = fs.readFileSync(targetFile, 'UTF-8');

// TODO APPLY EVERNOTE LINK
const evernoteInternalLinkPlaceholderRegExp = new RegExp('<YARLE_EVERNOTE_LINK_PLACEHOLDER>', 'g');
let updatedContent = fileContent.replace(evernoteInternalLinkPlaceholderRegExp, unrecognizable);


// TODO APPLY EVERNOTE GUID
const evernoteGuidPlaceholderRegExp = new RegExp('<YARLE_EVERNOTE_GUID_PLACEHOLDER>', 'g');
updatedContent = updatedContent.replace(evernoteGuidPlaceholderRegExp, unrecognizable);

if (fileContent !== updatedContent) {
updateFileContentSafely(targetFile, updatedContent);

}
}
};

9 changes: 9 additions & 0 deletions test/data/two-untitled-notes-with-toc.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Untitled Note



noteOne


Evernote Link: Unrecognizable
Evernote GUID: Unrecognizable
37 changes: 37 additions & 0 deletions test/data/two-untitled-notes-with-toc.enex
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export4.dtd">
<en-export export-date="20240226T092626Z" application="Evernote" version="10.74.1">
<note>
<title>Table of Contents</title>
<created>20240226T092601Z</created>
<updated>20240226T092610Z</updated>
<note-attributes>
</note-attributes>
<content>
<![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note><div><a href="evernote:///view/244421476/s470/51d20bcc-9067-a174-11db-8654e3b7275e/d8ce9322-b866-453a-90b3-81923b70c474/" rel="noopener noreferrer" rev="en_rl_none">Untitled</a></div><div><a href="evernote:///view/244421476/s470/204864a5-3e65-ed00-8bad-1073ff6b65d9/d8ce9322-b866-453a-90b3-81923b70c474/" rel="noopener noreferrer" rev="en_rl_none">Untitled</a></div></en-note> ]]>
</content>
</note>
<note>
<title>Untitled Note</title>
<created>20240226T091903Z</created>
<updated>20240226T092317Z</updated>
<note-attributes>
</note-attributes>
<content>
<![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note><div>noteTwo</div></en-note> ]]>
</content>
</note>
<note>
<title>Untitled Note</title>
<created>20240226T092256Z</created>
<updated>20240226T092306Z</updated>
<note-attributes>
</note-attributes>
<content>
<![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note><div>noteOne</div></en-note> ]]>
</content>
</note>
</en-export>
9 changes: 9 additions & 0 deletions test/data/two-untitled-notes-with-toc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Untitled Note



noteTwo


Evernote Link: Unrecognizable
Evernote GUID: Unrecognizable
89 changes: 88 additions & 1 deletion test/yarle-special-cases.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ dateFormat: undefined,

it('Multiple enex files with interEnex links', async () => {
const options: YarleOptions = {
dateFormat: undefined,
dateFormat: undefined,
enexSources: [ `${process.cwd()}${path.sep}test${path.sep}data${path.sep}LinkedInterNotebooks` ],
outputDir: 'out',
isMetadataNeeded: true,
Expand Down Expand Up @@ -1201,6 +1201,93 @@ dateFormat: undefined,
fs.readFileSync(`${__dirname}/data/LinkedInterNotebooks/test-internotebook_links_B/Note in Notebook B.md`, 'utf8'),
);

});

it('Multiple untitled note - unregognized guid/link', async () => {
const options: YarleOptions = {
templateFile: `${testDataFolder}evernotelink-template.templ`,
enexSources: [ `${testDataFolder}two-untitled-notes-with-toc.enex` ],
"isMetadataNeeded": true,
"isNotebookNameNeeded": false,
"isZettelkastenNeeded": false,
"useZettelIdAsFilename": false,
"plainTextNotesOnly": false,
"skipLocation": true,
"skipCreationTime": true,
"skipUpdateTime": true,
"skipSourceUrl": true,
"skipWebClips": false,
"skipTags": true,
"useHashTags": true,
"outputFormat": OutputFormat.ObsidianMD,
"taskOutputFormat": TaskOutputFormat.ObsidianMD,
"skipEnexFileNameFromOutputPath": false,
"keepMDCharactersOfENNotes": false,
"monospaceIsCodeBlock": false,
"keepOriginalHtml": true,
"resourcesDir": "_resources",
"trimStartingTabs": false,
"convertPlainHtmlNewlines": false,
"encryptionPasswords": [
""
],
"logseqSettings": {
"journalNotes": false
},
"obsidianSettings": {
"omitLinkDisplayName": false
},
"dateFormat": "YYYY-MM-DD HH:mm",
"keepImageSize": OutputFormat.ObsidianMD,

Check failure on line 1241 in test/yarle-special-cases.spec.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Type 'import("D:/a/yarle/yarle/src/output-format").OutputFormat' is not assignable to type 'boolean'.
"keepOriginalAmountOfNewlines": true,
"addExtensionToInternalLinks": false,
"generateNakedUrls": true,
"urlEncodeFileNamesAndLinks": false,
"haveEnexLevelResources": false,
"haveGlobalResources": false,
"useUniqueUnknownFileNames": true,
"useLevenshteinForLinks": false,
"sanitizeResourceNameSpaces": false,
"replacementChar": "_",
"replacementCharacterMap": {
"<": "_",
">": "_",
":": "_",
"\"": "_",
"/": "_",
"\\": "_",
"|": "_",
"?": "_",
"*": "_"
}

};
await dropTheRopeRunner.run(options);

assert.equal(
fs.existsSync(`${__dirname}/../out/notes/two-untitled-notes-with-toc/Untitled Note.1.md`),
true,
);
assert.equal(
fs.existsSync(`${__dirname}/../out/notes/two-untitled-notes-with-toc/Untitled Note.md`),
true,
);

assert.equal(
eol.auto(fs.readFileSync(
`${__dirname}/../out/notes/two-untitled-notes-with-toc/Untitled Note.md`,
'utf8',
)),
fs.readFileSync(`${__dirname}/data/two-untitled-notes-with-toc.md`, 'utf8'),
);
assert.equal(
eol.auto(fs.readFileSync(
`${__dirname}/../out/notes/two-untitled-notes-with-toc/Untitled Note.1.md`,
'utf8',
)),
fs.readFileSync(`${__dirname}/data/two-untitled-notes-with-toc.1.md`, 'utf8'),
);

});
it('Enex file with PDF attachment', async () => {
const options: YarleOptions = {
Expand Down

0 comments on commit 99da0ef

Please sign in to comment.