Skip to content

Commit

Permalink
feat: evernote v10+ tasks implemented (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
akosbalasko authored May 26, 2022
1 parent 6713beb commit e1f5155
Show file tree
Hide file tree
Showing 27 changed files with 532 additions and 90 deletions.
1 change: 1 addition & 0 deletions Notes_for_Logseq.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Please use settings below
"replaceSpaceWith": "-"
},
"outputFormat": "StandardMD",
"taskOutputFormat: "StandardMD",
"urlEncodeFileNamesAndLinks": false,
"sanitizeResourceNameSpaces": false,
"replacementChar": "_",
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ To configure Yarle, you must create a config file. By default it looks like this
"skipWebClips": false,
"useHashTags": true,
"outputFormat": "StandardMD",
"taskOutputFormat": "StandardMD",
"urlEncodeFileNamesAndLinks": false,
"skipEnexFileNameFromOutputPath": false,
"monospaceIsCodeBlock": false,
Expand Down Expand Up @@ -166,6 +167,8 @@ The following configurational properties are available:
| ```turndownOptions``` | `{...}` | additional configuration options for [turndown](https://github.com/mixmark-io/turndown#options), e.g., `{ "bulletListMarker": "-" }` (only in Yarle config file, not desktop app)
| ```obsidianSettings``` | `{...}` | settings for Obsidian output. Currently, ```omitLinkDisplayName``` is supported. If set to `true` links will be of the form `[[foo]]`. Conversely they will be of the form `[[foo|bar]]`. Defaults to `false`.
| ```logseqSettings````{...}` | settings for Logseq output, currently ```journalNotes``` property is supported, if it is set to `true`, then the notes will be converted to be recognizable by Logseq as Journal notes, the notes will be named by their creation date and they will be collected under `journal` folder. If it is `false`, then they will be converted to be `Pages` (e.g. simple notes, collected in `pages` folder).
| ```taskOutputFormat``` | `ObsidianMD` or `StandardMD` | Output format of Evernote v10+ tasks. ObsidianMD will connvert tasks to match with Obsidian Tasks plugin's requirements. StandardMD will create plain tasks, loosing many features like reminders or due dates.
| ```obsidianTaskTag``` | string | a tag to put to a task converted from Evernote v10+ tasks. Optional by Obsidian Tasks plugin, pls check the details there.

Metadata settings can be set via the template.

Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"skipTags": false,
"useHashTags": true,
"outputFormat": "ObsidianMD",
"taskOutputFormat": "ObsidianMD",
"skipEnexFileNameFromOutputPath": false,
"keepOriginalAmountOfNewlines": false,
"urlEncodeFileNamesAndLinks": false,
Expand Down
1 change: 1 addition & 0 deletions config.logseq.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"replaceSpaceWith": "-"
},
"outputFormat": "StandardMD",
"taskOutputFormat": "StandardMD",
"urlEncodeFileNamesAndLinks": false,
"sanitizeResourceNameSpaces": false,
"replacementChar": "_",
Expand Down
3 changes: 3 additions & 0 deletions src/YarleOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OutputFormat } from './output-format';
import { TagSeparatorReplaceOptions } from './models';
import { TaskOutputFormat } from './task-output-format';

export interface YarleOptions {
enexDir?: string; // used by command line
Expand Down Expand Up @@ -47,4 +48,6 @@ export interface YarleOptions {
pathSeparator?: string;
resourcesDir?: string;
turndownOptions?: Record<string, any>;
taskOutputFormat?: TaskOutputFormat;
obsidianTaskTag?: string;
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './runtime-properties';
export * from './task-output-format';
43 changes: 43 additions & 0 deletions src/models/EvernoteTask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import moment from 'moment';

export enum EvernoteTaskStatus {
Open = 'open',
Closed= 'closed',
}
export interface EvernoteTask {
$name: string;
created: Date;
creator: string;
lasteditor: string;
notelevelid: string;
sortweight: string;
statusupdated: Date;
taskflag: boolean;
taskgroupnotelevelid: string;
taskstatus: EvernoteTaskStatus;
title: string;
duedate: Date;
duedateoption: string;
reminderdate: Date;
reminderdateoption: string;
updated: Date;
}

export const mapEvernoteTask = (pureTask: any): EvernoteTask => {
return {
...pureTask,
created: getDateFromProperty(pureTask.created),
statusupdated: getDateFromProperty(pureTask.statusupdated),
updated: getDateFromProperty(pureTask.updated),
duedate: getDateFromProperty(pureTask.duedate),
taskflag: pureTask.taskflag === 'true',
reminderdate: pureTask.reminder ? getDateFromProperty(pureTask.reminder.reminderdate) : undefined,

};
};

const getDateFromProperty = (property: string) => {
return property
? moment(property, 'YYYYMMDDThhmmssZ').toDate()
: undefined;
};
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './ResourceFileProperties';
export * from './ResourceHash';
export * from './TagSeparatorReplaceOptions';
export * from './InternalLink';
export * from './EvernoteTask';
49 changes: 49 additions & 0 deletions src/process-tasks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { cloneDeep } from 'lodash';
import moment from 'moment';

import { yarleOptions } from './yarle';
import { TaskOutputFormat } from './task-output-format';
import { EvernoteTask, EvernoteTaskStatus } from './models/EvernoteTask';

const MEDIUM_PRIORITY_ICON = '🔼';
const LOW_PRIORITY_ICON = '🔽';
const DUE_DATE_ICON = '📅';
const SCHEDULE_DATE_ICON = '⏳';

export const processTaskFactory = (outputFormat: TaskOutputFormat): Function => {
switch (outputFormat) {
case TaskOutputFormat.ObsidianMD:
return convertTasktoMd;
default :
return convertTasktoPlainMdTask;
}
};

const convertTasktoPlainMdTask = (task: EvernoteTask, notebookName: string): string => {
const taskStatusMd = (task.taskstatus === EvernoteTaskStatus.Open)
? '- [ ]'
: '- [x]';
const title = task.title ? ` ${task.title}` : '';

return `${taskStatusMd}${title}`;
};

export const convertTasktoMd = (task: EvernoteTask, notebookName: string): string => {
const taskStatusMd = (task.taskstatus === EvernoteTaskStatus.Open)
? '- [ ]'
: '- [x]';
const title = task.title ? ` ${task.title}` : '';
const tag = yarleOptions.obsidianTaskTag !== '' ? ` ${yarleOptions.obsidianTaskTag}` : '';
const duedate = task.duedate
? ` ${DUE_DATE_ICON} ${convertDateFormat(task.duedate)}`
: '';
const reminder = task.reminderdate ? ` ${SCHEDULE_DATE_ICON} ${convertDateFormat(task.reminderdate)}` : '';

const priority = task.taskflag ? ` ${MEDIUM_PRIORITY_ICON}` : ` ${LOW_PRIORITY_ICON}`;

return `${taskStatusMd}${tag}${title}${duedate}${reminder}${priority}`;
};

const convertDateFormat = (dateProp: Date): string => {
return moment(dateProp).format('YYYY-MM-DD').toString();
};
9 changes: 9 additions & 0 deletions src/runtime-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class RuntimePropertiesSingleton {
noteIdNameTOCMap: any; // Table of Contents map - the trusted source
currentNoteName: string;
currentNotebookName: string;
currentNotePath: string;

private constructor() {
this.noteIdNameMap = {};
Expand Down Expand Up @@ -65,4 +66,12 @@ export class RuntimePropertiesSingleton {
getCurrentNoteName(): string {
return this.currentNoteName;
}
getCurrentNotePath(): string {
return this.currentNotePath;
}

setCurrentNotePath(value: string): void {
this.currentNotePath = value;
}

}
4 changes: 4 additions & 0 deletions src/task-output-format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum TaskOutputFormat {
ObsidianMD= 'ObsidianMD',
StandardMD= 'StandardMD',
}
33 changes: 30 additions & 3 deletions src/ui/sections/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ <h2>Target Dialect</h2>
<option value="StandardMD">Other Standard Markdown-based application</option>
</select>
</div>
</section></div>
</section>
</div>


<br><br>
Expand Down Expand Up @@ -252,8 +253,34 @@ <h2>Tags</h2>
</div>
</section>
<section></section>
</div>

</div>
<!--
<br><br>
<div class="split style1">
</div>
-->
<br><br>
<div class="split style1">
<section>
<h2>Evernote v10+ Tasks</h2>
<div class="field half">
<select name="taskOutputFormat" id="taskOutputFormat">
<option value="ObsidianMD">Obsidian</option>
<option value="StandardMD">Other Standard Markdown-based application</option>
</select>
</div>
<div class="field half">

<label for="obsidianTaskTag" class="pure-input-1-2">Obsidian tasks tag
</label>

<input type="text" id='obsidianTaskTag' width="20px">
</div>
</section>
<section></section>
</div>
</div>
</div>
</section>
Expand Down
3 changes: 3 additions & 0 deletions src/ui/settingsMapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { YarleOptions } from './../YarleOptions';
import { store } from './store';
import { OutputFormat } from './../output-format';
import { TaskOutputFormat } from './../task-output-format';

export const mapSettingsToYarleOptions = (): YarleOptions => {
return {
Expand All @@ -18,6 +19,8 @@ export const mapSettingsToYarleOptions = (): YarleOptions => {
skipTags: !(store.get('addTags') as boolean),
useHashTags: store.get('useHashTags') as boolean,
outputFormat: store.get('outputFormat') as OutputFormat,
obsidianTaskTag: store.get('obsidianTaskTag') as string,
taskOutputFormat: store.get('taskOutputFormat') as TaskOutputFormat,
skipEnexFileNameFromOutputPath: store.get('skipEnexFileNameFromOutputPath') as boolean,
keepMDCharactersOfENNotes: store.get('keepMDCharactersOfENNotes') as boolean,
monospaceIsCodeBlock: store.get('monospaceIsCodeBlock') as boolean,
Expand Down
2 changes: 2 additions & 0 deletions src/ui/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const schema: any = {
addTags: { type: 'boolean', default: false },
useHashTags: { type: 'boolean', default: false },
outputFormat: {type: 'string', default: OutputFormat.ObsidianMD},
obsidianTaskTag: { type: 'string' },
taskOutputFormat: {type: 'string', default: OutputFormat.ObsidianMD},
skipEnexFileNameFromOutputPath: { type: 'boolean', default: false },
keepMDCharactersOfENNotes: { type: 'boolean', default: false },
monospaceIsCodeBlock: { type: 'boolean', default: false },
Expand Down
3 changes: 3 additions & 0 deletions src/utils/save-md-file.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { RuntimePropertiesSingleton } from './../runtime-properties';
import { writeFile } from './file-utils';
import { getMdFilePath } from './folder-utils';
import { loggerInfo } from './loggerInfo';

export const saveMdFile = (data: any, note: any) => {

const absMdFilePath = getMdFilePath(note);
const runtimeProps = RuntimePropertiesSingleton.getInstance();
runtimeProps.setCurrentNotePath(absMdFilePath);
writeFile(absMdFilePath, data, note);
loggerInfo(`Note saved to ${absMdFilePath}`);
};
57 changes: 0 additions & 57 deletions src/utils/turndown-rules/code-block-rule.ts

This file was deleted.

33 changes: 33 additions & 0 deletions src/utils/turndown-rules/div-rule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { yarleOptions } from './../../yarle';
import { replaceCodeBlock } from './replace-code-block';
import { filterByNodeName } from './filter-by-nodename';
import { getAttributeProxy } from './get-attribute-proxy';
import { replaceMonospaceCodeBlock } from './replace-monospace-code-block';

const markdownBlock = '\n```\n';

const isTaskBlock = (node: any) => {
const nodeProxy = getAttributeProxy(node);
const taskFlag = '--en-task-group:true';

return nodeProxy.style && nodeProxy.style.value.indexOf(taskFlag) >= 0;
};
const getTaskGroupId = (node: any) => {
const nodeProxy = getAttributeProxy(node);
const idAttr = '--en-id:';

return nodeProxy.style.value.split(idAttr)[1].split(';')[0];
};

export const divRule = {
filter: filterByNodeName('DIV'),
replacement: (content: string, node: any) => {
const nodeProxy = getAttributeProxy(node);

return (isTaskBlock(node))
? `<YARLE-EN-V10-TASK>${getTaskGroupId(node)}</YARLE-EN-V10-TASK>`
: (yarleOptions.monospaceIsCodeBlock)
? replaceMonospaceCodeBlock(content, node)
: replaceCodeBlock(content, node);
},
};
5 changes: 3 additions & 2 deletions src/utils/turndown-rules/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export * from './code-block-rule';
export * from './monospace-code-block-rule';
export * from './replace-code-block';
export * from './replace-monospace-code-block';
export * from './images-rule';
export * from './internal-links-rule';
export * from './span-rule';
export * from './strikethrough-rule';
export * from './task-items-rule';
export * from './newline-rule';
export * from './div-rule';
Loading

0 comments on commit e1f5155

Please sign in to comment.