Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for all note-attributes defined in the ENEX DTD 3.0 #659

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/YarleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ export interface YarleOptions {
useZettelIdAsFilename?: boolean;
plainTextNotesOnly?: boolean;
skipLocation?: boolean;
skipAltitude?: boolean;
skipCreationTime?: boolean;
skipUpdateTime?: boolean;
skipSubjectDate?: boolean;
skipAuthor?: boolean;
skipSource?: boolean;
skipSourceUrl?: boolean;
skipSourceApplication?: boolean;
skipPlaceName?: boolean;
skipContentClass?: boolean;
skipApplicationData?: boolean;
skipWebClips?: boolean;
removeUnicodeCharsFromTags?: boolean
skipReminderTime?: boolean;
Expand Down
8 changes: 8 additions & 0 deletions src/models/MetaData.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
export interface MetaData {
createdAt?: string;
updatedAt?: string;
subjectDate?: string;
author?: string;
source?: string;
sourceUrl?: string;
sourceApplication?: string;
location?: string;
altitude?: string;
placeName?: string;
contentClass?: string;
applicationData?: string;
linkToOriginal?: string;
notebookName?: string;
reminderTime?: string;
Expand Down
25 changes: 19 additions & 6 deletions src/models/NoteData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ export interface NoteData {
appliedMarkdownContent?: string;
createdAt?: string;
updatedAt?: string;
subjectDate?: string;
author?: string;
source?: string;
sourceUrl?: string;
sourceApplication?: string;
placeName?: string;
contentClass?: string;
applicationData?: string;
location?: string;
altitude?: string;
linkToOriginal?: string;
notebookName?: string;
internalLinks?: Array<InternalLink>;
Expand All @@ -35,13 +43,18 @@ export interface EvernoteNoteData {
}

interface NoteAttributes {
'source-application'?: string;
'source-url'?: string;
'subject-date'?: string;
'longitude'?: string;
'latitude'?: string;
'altitude'?: string;
'author'?: string;
'source'?: string;
'reminder-time'?: string;
'source-url'?: string;
'source-application'?: string;
'reminder-order'?: string;
'reminder-time'?: string;
'reminder-done-time'?: string;
longitude?: string;
latitude?: string;

'place-name'?: string;
'content-class'?: string;
'application-data'?: string;
}
90 changes: 83 additions & 7 deletions src/utils/content-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ export const getMetadata = (note: EvernoteNoteData, notebookName: string): MetaD
return {
createdAt: getCreationTime(note),
updatedAt: getUpdateTime(note),
subjectDate: getSubjectDate(note),
author: getAuthor(note),
source: getSource(note),
sourceUrl: getSourceUrl(note),
sourceApplication: getSourceApplication(note),
location: getLatLong(note),
altitude: getAltitude(note),
placeName: getPlaceName(note),
contentClass: getContentClass(note),
applicationData: getApplicationData(note),
linkToOriginal: getLinkToOriginal(note),
reminderTime: getReminderTime(note),
reminderOrder: getReminderOrder(note),
Expand All @@ -40,32 +48,100 @@ export const getUpdateTime = (note: EvernoteNoteData): string => {
: undefined;
};

//////// Note Attributes
export const getSubjectDate = (note: EvernoteNoteData): string => {
return !yarleOptions.skipSubjectDate &&
note['note-attributes']
? note['note-attributes']['subject-date']
: undefined;
};

export const getLatLong = (note: EvernoteNoteData): string => {
return !yarleOptions.skipLocation &&
note['note-attributes'] &&
note['note-attributes'].longitude
? `${note['note-attributes'].latitude},${note['note-attributes'].longitude}`
: undefined;
};

export const getAltitude = (note: EvernoteNoteData): string => {
return !yarleOptions.skipAltitude &&
note['note-attributes']
? note['note-attributes']['altitude']
: undefined;
};

export const getAuthor = (note: EvernoteNoteData): string => {
return !yarleOptions.skipAuthor &&
note['note-attributes']
? note['note-attributes']['author']
: undefined;
};

export const getSource = (note: EvernoteNoteData): string => {
return !yarleOptions.skipSource &&
note['note-attributes']
? note['note-attributes']['source']
: undefined;
};

export const getSourceUrl = (note: EvernoteNoteData): string => {
return !yarleOptions.skipSourceUrl &&
note['note-attributes']
? note['note-attributes']['source-url']
: undefined;
};

export const getSourceApplication = (note: EvernoteNoteData): string => {
return !yarleOptions.skipSourceApplication &&
note['note-attributes']
? note['note-attributes']['source-application']
: undefined;
};

export const getPlaceName = (note: EvernoteNoteData): string => {
return !yarleOptions.skipPlaceName &&
note['note-attributes']
? note['note-attributes']['place-name']
: undefined;
};

export const getContentClass = (note: EvernoteNoteData): string => {
return !yarleOptions.skipContentClass &&
note['note-attributes']
? note['note-attributes']['content-class']
: undefined;
};

export const getApplicationData = (note: EvernoteNoteData): string => {
if (!yarleOptions.skipApplicationData && note['note-attributes'] && note['note-attributes']['application-data']) {
const appdataArray = Array.isArray(note['note-attributes']['application-data'])
? note['note-attributes']['application-data']
: [note['note-attributes']['application-data']];
const appdata = appdataArray.map((enexNode) => {
return ` - ${enexNode.$attrs.key}: ${enexNode.$text}`;
});
return '\n'+appdata.join('\n');
}
else
{
return undefined;
}
};

export const getLinkToOriginal = (note: EvernoteNoteData): string => {
return yarleOptions.keepOriginalHtml ?
getHtmlFileLink(note) : undefined;
};

export const getLatLong = (note: EvernoteNoteData): string => {
return !yarleOptions.skipLocation &&
note['note-attributes'] &&
note['note-attributes'].longitude
? `${note['note-attributes'].latitude},${note['note-attributes'].longitude}`
: undefined;
};
export const getReminderTime = (note: EvernoteNoteData): string => {
return !yarleOptions.skipReminderTime &&
note['note-attributes'] &&
note['note-attributes']['reminder-time']
? Moment(note['note-attributes']['reminder-time']).format(yarleOptions.dateFormat)
: undefined;
};

export const getReminderOrder = (note: EvernoteNoteData): string => {
return !yarleOptions.skipReminderOrder &&
note['note-attributes'] &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NoteData } from '../../../models/NoteData';

import * as P from './../placeholders/altitude-placeholders';
import { applyConditionalTemplate } from './apply-conditional-template';

export const applyAltitudeTemplate = (noteData: NoteData, text: string): string => {
return applyConditionalTemplate(text, P, noteData.altitude);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NoteData } from '../../../models/NoteData';

import * as P from './../placeholders/application-data-yaml-list-placeholders';
import { applyConditionalTemplate } from './apply-conditional-template';

export const applyApplicationDataTemplate = (noteData: NoteData, text: string): string => {
return applyConditionalTemplate(text, P, noteData.applicationData);
};
8 changes: 8 additions & 0 deletions src/utils/templates/apply-functions/apply-author-template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NoteData } from '../../../models/NoteData';

import * as P from './../placeholders/author-placeholders';
import { applyConditionalTemplate } from './apply-conditional-template';

export const applyAuthorTemplate = (noteData: NoteData, text: string): string => {
return applyConditionalTemplate(text, P, noteData.author);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NoteData } from '../../../models/NoteData';

import * as P from './../placeholders/content-class-placeholders';
import { applyConditionalTemplate } from './apply-conditional-template';

export const applyContentClassTemplate = (noteData: NoteData, text: string): string => {
return applyConditionalTemplate(text, P, noteData.contentClass);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NoteData } from '../../../models/NoteData';

import * as P from './../placeholders/place-name-placeholders';
import { applyConditionalTemplate } from './apply-conditional-template';

export const applyPlaceNameTemplate = (noteData: NoteData, text: string): string => {
return applyConditionalTemplate(text, P, noteData.placeName);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NoteData } from '../../../models/NoteData';

import * as P from './../placeholders/source-application-placeholders';
import { applyConditionalTemplate } from './apply-conditional-template';

export const applySourceApplicationTemplate = (noteData: NoteData, text: string): string => {
return applyConditionalTemplate(text, P, noteData.sourceApplication);
};
8 changes: 8 additions & 0 deletions src/utils/templates/apply-functions/apply-source-template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NoteData } from '../../../models/NoteData';

import * as P from './../placeholders/source-placeholders';
import { applyConditionalTemplate } from './apply-conditional-template';

export const applySourceTemplate = (noteData: NoteData, text: string): string => {
return applyConditionalTemplate(text, P, noteData.source);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NoteData } from '../../../models/NoteData';

import * as P from './../placeholders/sourceurl-placeholders';
import * as P from './../placeholders/source-url-placeholders';
import { applyConditionalTemplate } from './apply-conditional-template';

export const applySourceUrlTemplate = (noteData: NoteData, text: string): string => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { NoteData } from '../../../models/NoteData';

import * as P from './../placeholders/subject-date-placeholders';
import { applyConditionalTemplate } from './apply-conditional-template';

export const applySubjectDateTemplate = (noteData: NoteData, text: string): string => {
return applyConditionalTemplate(text, P, noteData.subjectDate);
};
10 changes: 9 additions & 1 deletion src/utils/templates/apply-functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ export * from './apply-tags-template';
export * from './apply-title-template';
export * from './apply-createdat-template';
export * from './apply-updatedat-template';
export * from './apply-sourceurl-template';
export * from './apply-subject-date-template';
export * from './apply-author-template';
export * from './apply-source-template';
export * from './apply-source-url-template';
export * from './apply-source-application-template';
export * from './apply-place-name-template';
export * from './apply-content-class-template';
export * from './apply-application-data-template';
export * from './apply-location-template';
export * from './apply-altitude-template';
export * from './apply-original-template';
export * from './apply-notebook-template';
export * from './apply-remindertime-template';
Expand Down
34 changes: 33 additions & 1 deletion src/utils/templates/checker-functions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@

import * as CREATIONTIME from './placeholders/createdat-placeholders';
import * as LOCATION from './placeholders/location-placeholders';
import * as ALTITUDE from './placeholders/altitude-placeholders';
import * as NOTEBOOK from './placeholders/notebook-placeholders';
import * as ORIGINALLINK from './placeholders/original-placeholders';
import * as SOURCEURL from './placeholders/sourceurl-placeholders';
import * as SUBJECTDATE from './placeholders/subject-date-placeholders';
import * as AUTHOR from './placeholders/author-placeholders';
import * as SOURCE from './placeholders/source-placeholders';
import * as SOURCEURL from './placeholders/source-url-placeholders';
import * as SOURCEAPPLICATION from './placeholders/source-application-placeholders';
import * as PLACENAME from './placeholders/place-name-placeholders';
import * as CONTENTCLASS from './placeholders/content-class-placeholders';
import * as YAMLAPPLICATIONDATA from './placeholders/application-data-yaml-list-placeholders';
import * as TAGS from './placeholders/tags-placeholders';
import * as YAMLARRAYTAGS from './placeholders/tags-array-placeholders';
import * as YAMLLISTTAGS from './placeholders/tags-yaml-list-placeholders';
Expand Down Expand Up @@ -31,15 +39,39 @@ export const hasReminderOrderInTemplate = (templateContent: string): boolean =>
export const hasLocationInTemplate = (templateContent: string): boolean => {
return hasItemInTemplate(LOCATION, templateContent);
};
export const hasAltitudeInTemplate = (templateContent: string): boolean => {
return hasItemInTemplate(ALTITUDE, templateContent);
};
export const hasNotebookInTemplate = (templateContent: string): boolean => {
return hasItemInTemplate(NOTEBOOK, templateContent);
};
export const hasOriginalLinkInTemplate = (templateContent: string): boolean => {
return hasItemInTemplate(ORIGINALLINK, templateContent);
};
export const hasSubjectDateInTemplate = (templateContent: string): boolean => {
return hasItemInTemplate(SUBJECTDATE, templateContent);
};
export const hasAuthorInTemplate = (templateContent: string): boolean => {
return hasItemInTemplate(AUTHOR, templateContent);
};
export const hasSourceInTemplate = (templateContent: string): boolean => {
return hasItemInTemplate(SOURCE, templateContent);
};
export const hasSourceURLInTemplate = (templateContent: string): boolean => {
return hasItemInTemplate(SOURCEURL, templateContent);
};
export const hasSourceApplicationInTemplate = (templateContent: string): boolean => {
return hasItemInTemplate(SOURCEAPPLICATION, templateContent);
};
export const hasPlaceNameInTemplate = (templateContent: string): boolean => {
return hasItemInTemplate(PLACENAME, templateContent);
};
export const hasContentClassInTemplate = (templateContent: string): boolean => {
return hasItemInTemplate(CONTENTCLASS, templateContent);
};
export const hasApplicationDataInTemplate = (templateContent: string): boolean => {
return hasItemInTemplate(YAMLAPPLICATIONDATA, templateContent);
};
export const hasAnyTagsInTemplate = (templateContent: string): boolean => {
return (hasItemInTemplate(TAGS, templateContent)
|| hasItemInTemplate(YAMLARRAYTAGS, templateContent)
Expand Down
3 changes: 3 additions & 0 deletions src/utils/templates/placeholders/altitude-placeholders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CONTENT_PLACEHOLDER = '{altitude}';
export const START_BLOCK = '{altitude-block}';
export const END_BLOCK = '{end-altitude-block}';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CONTENT_PLACEHOLDER = '{application-data-yaml-list}';
export const START_BLOCK = '{application-data-yaml-list-block}';
export const END_BLOCK = '{end-application-data-yaml-list-block}';
3 changes: 3 additions & 0 deletions src/utils/templates/placeholders/author-placeholders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CONTENT_PLACEHOLDER = '{author}';
export const START_BLOCK = '{author-block}';
export const END_BLOCK = '{end-author-block}';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CONTENT_PLACEHOLDER = '{content-class}';
export const START_BLOCK = '{content-class-block}';
export const END_BLOCK = '{end-content-class-block}';
3 changes: 3 additions & 0 deletions src/utils/templates/placeholders/place-name-placeholders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CONTENT_PLACEHOLDER = '{place-name}';
export const START_BLOCK = '{place-name-block}';
export const END_BLOCK = '{end-place-name-block}';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CONTENT_PLACEHOLDER = '{source-application}';
export const START_BLOCK = '{source-application-block}';
export const END_BLOCK = '{end-source-application-block}';
3 changes: 3 additions & 0 deletions src/utils/templates/placeholders/source-placeholders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CONTENT_PLACEHOLDER = '{source}';
export const START_BLOCK = '{source-block}';
export const END_BLOCK = '{end-source-block}';
3 changes: 3 additions & 0 deletions src/utils/templates/placeholders/subject-date-placeholders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CONTENT_PLACEHOLDER = '{subject-date}';
export const START_BLOCK = '{subject-date-block}';
export const END_BLOCK = '{end-subject-date-block}';
Loading