From 122c5c29b56a3cd5814a5aa0c2df447b57e2dc9f Mon Sep 17 00:00:00 2001 From: Akos Balasko Date: Tue, 2 Feb 2021 07:59:13 +0100 Subject: [PATCH 1/3] config option added --- README.md | 3 +-- package-lock.json | 2 +- package.json | 2 +- src/YarleOptions.ts | 1 + src/output-format.ts | 1 - src/utils/turndown-rules/images-rule.ts | 15 ++++++----- .../turndown-rules/internal-links-rule.ts | 25 ++++++------------- test/yarle-tests.ts | 2 +- 8 files changed, 20 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 6bb9c5b8..cd1ea8de 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,7 @@ The following configurational properties are available: |```keepMDCharactersOfENNotes```| true or false | set it true, if you used Markdown format in your EN notes| | ```nestedTags``` | it's a complex property contains the following subitems: "separatorInEN", "replaceSeparatorWith" and "replaceSpaceWith" | separatorInEN stores the tag separator used in Evernote, replaceSeparatorWith is the string to what separatorInEN should be replaced to, and replaceSpaceWith is the string to what the space character should be replaced to in the tags. For example using the default settings a tag ```tag1_sub tag of tag1``` is going to be converted to ```tag1/sub-tag-of-tag1``` | ```keepImageSize``` | `ObsidianMD` or `StandardMD` | preserve an image's width and height in the chosen format when specified +| ```urlEncodeFileNamesAndLinks``` | true or false | URL-encodes linked file names and internal EN links . e.g "linked file.jpg" will be converted to "linked%20file.jpg" Metadata settings can be set via the template. - -## [Release notes](https://github.com/akosbalasko/yarle/wiki/Release-notes) diff --git a/package-lock.json b/package-lock.json index b53a798a..cb370123 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "yarle-evernote-to-md", - "version": "3.9.1", + "version": "3.10.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 9542347f..f80dde50 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yarle-evernote-to-md", - "version": "3.9.1", + "version": "3.11.0", "description": "Yet Another Rope Ladder from Evernote", "keywords": [ "evernote", diff --git a/src/YarleOptions.ts b/src/YarleOptions.ts index 29f963a0..7ad699be 100644 --- a/src/YarleOptions.ts +++ b/src/YarleOptions.ts @@ -22,6 +22,7 @@ export interface YarleOptions { skipEnexFileNameFromOutputPath?: boolean; haveEnexLevelResources?: boolean; keepMDCharactersOfENNotes?: boolean; + urlEncodeFileNamesAndLinks?: boolean; monospaceIsCodeBlock?: boolean; dateFormat?: string; nestedTags?: TagSeparatorReplaceOptions; diff --git a/src/output-format.ts b/src/output-format.ts index a50ee219..601bcca1 100644 --- a/src/output-format.ts +++ b/src/output-format.ts @@ -1,5 +1,4 @@ export enum OutputFormat { ObsidianMD= 'ObsidianMD', StandardMD= 'StandardMD', - UrlEncodeMD= 'UrlEncodeMD', } diff --git a/src/utils/turndown-rules/images-rule.ts b/src/utils/turndown-rules/images-rule.ts index 38710cfa..03501afd 100644 --- a/src/utils/turndown-rules/images-rule.ts +++ b/src/utils/turndown-rules/images-rule.ts @@ -13,27 +13,26 @@ export const imagesRule = { return ''; } const value = nodeProxy.src.value; + const realValue = yarleOptions.urlEncodeFileNamesAndLinks ? encodeURI(value) : value; // while this isn't really a standard, it is common enough if (yarleOptions.keepImageSize === OutputFormat.StandardMD) { const widthParam = node.width || ''; const heightParam = node.height || ''; - - return `![](${value} =${widthParam}x${heightParam})`; + + return `![](${realValue} =${widthParam}x${heightParam})`; } else if (yarleOptions.keepImageSize === OutputFormat.ObsidianMD) { - return `![|${node.width}x${node.height}](${value})`; + return `![|${node.width}x${node.height}](${realValue})`; } const useObsidianMD = yarleOptions.outputFormat === OutputFormat.ObsidianMD; if (useObsidianMD && !value.match(/^[a-z]+:/)) { - return `![[${value}]]`; + return `![[${realValue}]]`; } const srcSpl = nodeProxy.src.value.split('/'); - if (yarleOptions.outputFormat === OutputFormat.UrlEncodeMD) { - return `![${srcSpl[srcSpl.length - 1]}](${encodeURI(value)})`; - } - return `![${srcSpl[srcSpl.length - 1]}](${value})`; + + return `![${srcSpl[srcSpl.length - 1]}](${realValue})`; }, }; diff --git a/src/utils/turndown-rules/internal-links-rule.ts b/src/utils/turndown-rules/internal-links-rule.ts index 6848e8ac..a373871f 100644 --- a/src/utils/turndown-rules/internal-links-rule.ts +++ b/src/utils/turndown-rules/internal-links-rule.ts @@ -33,6 +33,8 @@ export const wikiStyleLinksRule = { token['mdKeyword'] = `${'#'.repeat(tokens[0]['depth'])} `; } const value = nodeProxy.href.value; + const realValue = yarleOptions.urlEncodeFileNamesAndLinks ? encodeURI(value) : value; + if (value.match(/^(https?:|www\.|file:|ftp:|mailto:)/)) { return (!token['text'] || _.unescape(token['text']) === _.unescape(value)) ? `<${value}>` @@ -41,12 +43,10 @@ export const wikiStyleLinksRule = { if (value.startsWith('evernote://')) { const fileName = normalizeTitle(token['text']); const displayName = token['text']; - if (yarleOptions.outputFormat === OutputFormat.ObsidianMD) { - return `${token['mdKeyword']}[[${fileName}|${displayName}]]`; - } + const realFileName = yarleOptions.urlEncodeFileNamesAndLinks ? encodeURI(fileName) : fileName; - if (yarleOptions.outputFormat === OutputFormat.UrlEncodeMD) { - return `${token['mdKeyword']}[${displayName}](${encodeURI(fileName)})`; + if (yarleOptions.outputFormat === OutputFormat.ObsidianMD) { + return `${token['mdKeyword']}[[${realFileName}|${displayName}]]`; } return `${token['mdKeyword']}[${displayName}](${fileName})`; @@ -54,18 +54,9 @@ export const wikiStyleLinksRule = { } return (yarleOptions.outputFormat === OutputFormat.ObsidianMD) - ? `${token['mdKeyword']}[[${value} | ${token['text']}]]` + ? `${token['mdKeyword']}[[${realValue} | ${token['text']}]]` : (yarleOptions.outputFormat === OutputFormat.StandardMD) - ? `${token['mdKeyword']}[${token['text']}](${value})` - : `${token['mdKeyword']}[[${value}]]`; - // todo embed - - /*return ( - !value.match(/^(https?:|www\.|file:|ftp:|mailto:)/) - ? `[[${removeBrackets(node.innerHTML)}]]` - : (yarleOptions.outputFormat === OutputFormat.ObsidianMD) - ? `![[${removeBrackets(node.innerHTML)}]]` - : `[${removeBrackets(node.innerHTML)}](${value})`; - */ + ? `${token['mdKeyword']}[${token['text']}](${realValue})` + : `${token['mdKeyword']}[[${realValue}]]`; }, }; diff --git a/test/yarle-tests.ts b/test/yarle-tests.ts index 0f8dc936..905dd36c 100644 --- a/test/yarle-tests.ts +++ b/test/yarle-tests.ts @@ -428,7 +428,7 @@ export const yarleTests: Array = [ enexSource: './test/data/test-urlencode.enex', outputDir: 'out', isMetadataNeeded: true, - outputFormat: OutputFormat.UrlEncodeMD, + urlEncodeFileNamesAndLinks: true, }, testOutputPath: 'notes/test-urlencode/test - note with picture (filename with spaces).md', From 8c346c707e469180b27d2b24e2adea6b87ad7af7 Mon Sep 17 00:00:00 2001 From: Akos Balasko Date: Tue, 2 Feb 2021 08:00:41 +0100 Subject: [PATCH 2/3] default options added --- src/yarle.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/yarle.ts b/src/yarle.ts index ca9e197d..a26dd4da 100644 --- a/src/yarle.ts +++ b/src/yarle.ts @@ -7,6 +7,7 @@ import { processNode } from './process-node'; import { isWebClip } from './utils/note-utils'; import { hasCreationTimeInTemplate, hasLocationInTemplate, hasSourceURLInTemplate, hasTagsInTemplate, hasUpdateTimeInTemplate, hasNotebookInTemplate, hasLinkToOriginalInTemplate } from './utils/templates/checker-functions'; import { defaultTemplate } from './utils/templates/default-template'; +import { OutputFormat } from 'output-format'; export const defaultYarleOptions: YarleOptions = { enexSource: 'notebook.enex', @@ -22,7 +23,9 @@ export const defaultYarleOptions: YarleOptions = { separatorInEN: '_', replaceSeparatorWith: '/', replaceSpaceWith: '-' - } + }, + outputFormat: OutputFormat.StandardMD, + urlEncodeFileNamesAndLinks: false, }; export let yarleOptions: YarleOptions = { ...defaultYarleOptions }; From 9a080f910264ed105e6071082fbaf543def2d83d Mon Sep 17 00:00:00 2001 From: Akos Balasko Date: Tue, 2 Feb 2021 08:02:57 +0100 Subject: [PATCH 3/3] option added to example --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cd1ea8de..1accdeb9 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ To configure Yarle, you must create a config file. By default it looks like this "skipWebClips": false, "useHashTags": true, "outputFormat": "StandardMD", + "urlEncodeFileNamesAndLinks": false, "skipEnexFileNameFromOutputPath": false, "haveEnexLevelResources": false, "monospaceIsCodeBlock": false,