-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: evernote v10+ tasks implemented (#388)
- Loading branch information
1 parent
6713beb
commit e1f5155
Showing
27 changed files
with
532 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './runtime-properties'; | ||
export * from './task-output-format'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum TaskOutputFormat { | ||
ObsidianMD= 'ObsidianMD', | ||
StandardMD= 'StandardMD', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
Oops, something went wrong.