Skip to content

Commit

Permalink
feat: support of naked urls (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
akosbalasko authored Jul 18, 2021
1 parent d0cebb9 commit 193f61d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ The following configurational properties are available:
| ```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"
| ```keepOriginalAmountOfNewlines``` | true or false | keep the original amount of newlines, default is false, when the multiple newlines are collapsed to one.
```generateNakedUrls``` | true or false | if it's true, Yarle generates 'naked' external Urls without any extra characters. If its false, external Urls are wrapped by '<' and '>' characters

| ```addExtensionToInternalLinks``` | true or false | adds '.md' extensions at the end of internal file links, to make them recognizable by DevonThink and other tools

Metadata settings can be set via the template.
1 change: 1 addition & 0 deletions src/YarleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface YarleOptions {
nestedTags?: TagSeparatorReplaceOptions;
keepImageSize?: OutputFormat;
keepOriginalAmountOfNewlines?: boolean;
generateNakedUrls?: boolean;
addExtensionToInternalLinks?: boolean;
pathSeparator?: string;
resourcesDir?: string;
Expand Down
11 changes: 10 additions & 1 deletion src/ui/sections/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,16 @@ <h2>General</h2>
keep the original amount of newlines, default is false, when the multiple newlines are collapsed to one.)</i></div>
</label>
</div>

<div class="field half">
<input type="checkbox" value="false" id='generateNakedUrls'>
<label for="generateNakedUrls" class="pure-checkbox">
Generate 'naked' URLs
<br><div style='font-size: 12px;'><i>(
if it's true, Yarle generates 'naked' external Urls without any extra characters. If its false, external Urls are wrapped by '\<' and '\>' characters
)</i></div>
</label>
</div>

<div class="field half">
<input type="checkbox" value="false" id='addExtensionToInternalLinks'>
<label for="addExtensionToInternalLinks" class="pure-checkbox">
Expand Down
1 change: 1 addition & 0 deletions src/ui/settingsMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export const mapSettingsToYarleOptions = (): YarleOptions => {
keepImageSize: store.get('keepImageSize') as OutputFormat,
keepOriginalAmountOfNewlines: store.get('keepOriginalAmountOfNewlines') as boolean,
addExtensionToInternalLinks: store.get('addExtensionToInternalLinks') as boolean,
generateNakedUrls: store.get('generateNakedUrls') as boolean,
}
}
2 changes: 1 addition & 1 deletion src/utils/turndown-rules/internal-links-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ export const wikiStyleLinksRule = {

export const getShortLinkIfPossible = (token: any, value: string): string => {
return (!token['text'] || _.unescape(token['text']) === _.unescape(value))
? `<${value}>`
? yarleOptions.generateNakedUrls ? value : `<${value}>`
: `${token['mdKeyword']}[${token['text']}](${value})`;
}
5 changes: 5 additions & 0 deletions test/data/test-externalLink-naked.enex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export3.dtd">
<en-export export-date="20200518T214836Z" application="Evernote" version="Evernote Mac 7.14 (458265)">
<note><title>External Link</title><content><![CDATA[<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note><div><a href="https://444.hu/"></a></div></en-note>]]></content><created>20200518T214753Z</created><updated>20200518T214817Z</updated><note-attributes><latitude>47.62493896484375</latitude><longitude>19.13836314872808</longitude><altitude>127.599723815918</altitude><author>akos</author><source>desktop.mac</source><reminder-order>0</reminder-order></note-attributes></note>
</en-export>
8 changes: 8 additions & 0 deletions test/data/test-externalLink-naked.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# External Link

https://444.hu/

Created at: 2020-05-18T22:47:53+01:00
Updated at: 2020-05-18T22:48:17+01:00
Where: 47.62493896484375,19.13836314872808

14 changes: 14 additions & 0 deletions test/yarle-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,20 @@ export const yarleTests: Array<YarleTest> = [

expectedOutputPath: `${dataFolder}test-externalLink-escape.md`,
},
{
name: ' Pure external url naked',
options: {
enexSource: `.${testDataFolder}test-externalLink-naked.enex`,
outputDir: 'out',
isMetadataNeeded: true,
skipLocation: true,
keepMDCharactersOfENNotes: true,
generateNakedUrls: true,
},
testOutputPath: `notes${path.sep}test-externalLink-naked${path.sep}External Link.md`,

expectedOutputPath: `${dataFolder}test-externalLink-naked.md`,
},

{
name: ' Custom date format',
Expand Down

0 comments on commit 193f61d

Please sign in to comment.