Skip to content

Commit

Permalink
Merge pull request #194 from akosbalasko/feat-urlencode-as-option
Browse files Browse the repository at this point in the history
  • Loading branch information
akosbalasko authored Feb 2, 2021
2 parents d6af464 + 9a080f9 commit e591c33
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 32 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -80,8 +81,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)
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/YarleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface YarleOptions {
skipEnexFileNameFromOutputPath?: boolean;
haveEnexLevelResources?: boolean;
keepMDCharactersOfENNotes?: boolean;
urlEncodeFileNamesAndLinks?: boolean;
monospaceIsCodeBlock?: boolean;
dateFormat?: string;
nestedTags?: TagSeparatorReplaceOptions;
Expand Down
1 change: 0 additions & 1 deletion src/output-format.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export enum OutputFormat {
ObsidianMD= 'ObsidianMD',
StandardMD= 'StandardMD',
UrlEncodeMD= 'UrlEncodeMD',
}
15 changes: 7 additions & 8 deletions src/utils/turndown-rules/images-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`;
},
};
25 changes: 8 additions & 17 deletions src/utils/turndown-rules/internal-links-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}>`
Expand All @@ -41,31 +43,20 @@ 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})`;

}

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}]]`;
},
};
5 changes: 4 additions & 1 deletion src/yarle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -22,7 +23,9 @@ export const defaultYarleOptions: YarleOptions = {
separatorInEN: '_',
replaceSeparatorWith: '/',
replaceSpaceWith: '-'
}
},
outputFormat: OutputFormat.StandardMD,
urlEncodeFileNamesAndLinks: false,
};

export let yarleOptions: YarleOptions = { ...defaultYarleOptions };
Expand Down
2 changes: 1 addition & 1 deletion test/yarle-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export const yarleTests: Array<YarleTest> = [
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',

Expand Down

0 comments on commit e591c33

Please sign in to comment.