Skip to content

Commit 06419a6

Browse files
support for all note-attributes defined in the Evernote Note Export Format, 3.0 DTD
1 parent 2dfa5ff commit 06419a6

40 files changed

+482
-18
lines changed

src/YarleOptions.ts

+8
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,17 @@ export interface YarleOptions {
1818
useZettelIdAsFilename?: boolean;
1919
plainTextNotesOnly?: boolean;
2020
skipLocation?: boolean;
21+
skipAltitude?: boolean;
2122
skipCreationTime?: boolean;
2223
skipUpdateTime?: boolean;
24+
skipSubjectDate?: boolean;
25+
skipAuthor?: boolean;
26+
skipSource?: boolean;
2327
skipSourceUrl?: boolean;
28+
skipSourceApplication?: boolean;
29+
skipPlaceName?: boolean;
30+
skipContentClass?: boolean;
31+
skipApplicationData?: boolean;
2432
skipWebClips?: boolean;
2533
removeUnicodeCharsFromTags?: boolean
2634
skipReminderTime?: boolean;

src/models/MetaData.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
export interface MetaData {
22
createdAt?: string;
33
updatedAt?: string;
4+
subjectDate?: string;
5+
author?: string;
6+
source?: string;
47
sourceUrl?: string;
8+
sourceApplication?: string;
59
location?: string;
10+
altitude?: string;
11+
placeName?: string;
12+
contentClass?: string;
13+
applicationData?: string;
614
linkToOriginal?: string;
715
notebookName?: string;
816
reminderTime?: string;

src/models/NoteData.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ export interface NoteData {
1212
appliedMarkdownContent?: string;
1313
createdAt?: string;
1414
updatedAt?: string;
15+
subjectDate?: string;
16+
author?: string;
17+
source?: string;
1518
sourceUrl?: string;
19+
sourceApplication?: string;
20+
placeName?: string;
21+
contentClass?: string;
22+
applicationData?: string;
1623
location?: string;
24+
altitude?: string;
1725
linkToOriginal?: string;
1826
notebookName?: string;
1927
internalLinks?: Array<InternalLink>;
@@ -35,13 +43,18 @@ export interface EvernoteNoteData {
3543
}
3644

3745
interface NoteAttributes {
38-
'source-application'?: string;
39-
'source-url'?: string;
46+
'subject-date'?: string;
47+
'longitude'?: string;
48+
'latitude'?: string;
49+
'altitude'?: string;
50+
'author'?: string;
4051
'source'?: string;
41-
'reminder-time'?: string;
52+
'source-url'?: string;
53+
'source-application'?: string;
4254
'reminder-order'?: string;
55+
'reminder-time'?: string;
4356
'reminder-done-time'?: string;
44-
longitude?: string;
45-
latitude?: string;
46-
57+
'place-name'?: string;
58+
'content-class'?: string;
59+
'application-data'?: string;
4760
}

src/utils/content-utils.ts

+83-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ export const getMetadata = (note: EvernoteNoteData, notebookName: string): MetaD
1414
return {
1515
createdAt: getCreationTime(note),
1616
updatedAt: getUpdateTime(note),
17+
subjectDate: getSubjectDate(note),
18+
author: getAuthor(note),
19+
source: getSource(note),
1720
sourceUrl: getSourceUrl(note),
21+
sourceApplication: getSourceApplication(note),
1822
location: getLatLong(note),
23+
altitude: getAltitude(note),
24+
placeName: getPlaceName(note),
25+
contentClass: getContentClass(note),
26+
applicationData: getApplicationData(note),
1927
linkToOriginal: getLinkToOriginal(note),
2028
reminderTime: getReminderTime(note),
2129
reminderOrder: getReminderOrder(note),
@@ -40,32 +48,100 @@ export const getUpdateTime = (note: EvernoteNoteData): string => {
4048
: undefined;
4149
};
4250

51+
//////// Note Attributes
52+
export const getSubjectDate = (note: EvernoteNoteData): string => {
53+
return !yarleOptions.skipSubjectDate &&
54+
note['note-attributes']
55+
? note['note-attributes']['subject-date']
56+
: undefined;
57+
};
58+
59+
export const getLatLong = (note: EvernoteNoteData): string => {
60+
return !yarleOptions.skipLocation &&
61+
note['note-attributes'] &&
62+
note['note-attributes'].longitude
63+
? `${note['note-attributes'].latitude},${note['note-attributes'].longitude}`
64+
: undefined;
65+
};
66+
67+
export const getAltitude = (note: EvernoteNoteData): string => {
68+
return !yarleOptions.skipAltitude &&
69+
note['note-attributes']
70+
? note['note-attributes']['altitude']
71+
: undefined;
72+
};
73+
74+
export const getAuthor = (note: EvernoteNoteData): string => {
75+
return !yarleOptions.skipAuthor &&
76+
note['note-attributes']
77+
? note['note-attributes']['author']
78+
: undefined;
79+
};
80+
81+
export const getSource = (note: EvernoteNoteData): string => {
82+
return !yarleOptions.skipSource &&
83+
note['note-attributes']
84+
? note['note-attributes']['source']
85+
: undefined;
86+
};
87+
4388
export const getSourceUrl = (note: EvernoteNoteData): string => {
4489
return !yarleOptions.skipSourceUrl &&
4590
note['note-attributes']
4691
? note['note-attributes']['source-url']
4792
: undefined;
4893
};
4994

95+
export const getSourceApplication = (note: EvernoteNoteData): string => {
96+
return !yarleOptions.skipSourceApplication &&
97+
note['note-attributes']
98+
? note['note-attributes']['source-application']
99+
: undefined;
100+
};
101+
102+
export const getPlaceName = (note: EvernoteNoteData): string => {
103+
return !yarleOptions.skipPlaceName &&
104+
note['note-attributes']
105+
? note['note-attributes']['place-name']
106+
: undefined;
107+
};
108+
109+
export const getContentClass = (note: EvernoteNoteData): string => {
110+
return !yarleOptions.skipContentClass &&
111+
note['note-attributes']
112+
? note['note-attributes']['content-class']
113+
: undefined;
114+
};
115+
116+
export const getApplicationData = (note: EvernoteNoteData): string => {
117+
if (!yarleOptions.skipApplicationData && note['note-attributes'] && note['note-attributes']['application-data']) {
118+
const appdataArray = Array.isArray(note['note-attributes']['application-data'])
119+
? note['note-attributes']['application-data']
120+
: [note['note-attributes']['application-data']];
121+
const appdata = appdataArray.map((enexNode) => {
122+
return ` - ${enexNode.$attrs.key}: ${enexNode.$text}`;
123+
});
124+
return '\n'+appdata.join('\n');
125+
}
126+
else
127+
{
128+
return undefined;
129+
}
130+
};
131+
50132
export const getLinkToOriginal = (note: EvernoteNoteData): string => {
51133
return yarleOptions.keepOriginalHtml ?
52134
getHtmlFileLink(note) : undefined;
53135
};
54136

55-
export const getLatLong = (note: EvernoteNoteData): string => {
56-
return !yarleOptions.skipLocation &&
57-
note['note-attributes'] &&
58-
note['note-attributes'].longitude
59-
? `${note['note-attributes'].latitude},${note['note-attributes'].longitude}`
60-
: undefined;
61-
};
62137
export const getReminderTime = (note: EvernoteNoteData): string => {
63138
return !yarleOptions.skipReminderTime &&
64139
note['note-attributes'] &&
65140
note['note-attributes']['reminder-time']
66141
? Moment(note['note-attributes']['reminder-time']).format(yarleOptions.dateFormat)
67142
: undefined;
68143
};
144+
69145
export const getReminderOrder = (note: EvernoteNoteData): string => {
70146
return !yarleOptions.skipReminderOrder &&
71147
note['note-attributes'] &&
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NoteData } from '../../../models/NoteData';
2+
3+
import * as P from './../placeholders/altitude-placeholders';
4+
import { applyConditionalTemplate } from './apply-conditional-template';
5+
6+
export const applyAltitudeTemplate = (noteData: NoteData, text: string): string => {
7+
return applyConditionalTemplate(text, P, noteData.altitude);
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NoteData } from '../../../models/NoteData';
2+
3+
import * as P from './../placeholders/application-data-yaml-list-placeholders';
4+
import { applyConditionalTemplate } from './apply-conditional-template';
5+
6+
export const applyApplicationDataTemplate = (noteData: NoteData, text: string): string => {
7+
return applyConditionalTemplate(text, P, noteData.applicationData);
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NoteData } from '../../../models/NoteData';
2+
3+
import * as P from './../placeholders/author-placeholders';
4+
import { applyConditionalTemplate } from './apply-conditional-template';
5+
6+
export const applyAuthorTemplate = (noteData: NoteData, text: string): string => {
7+
return applyConditionalTemplate(text, P, noteData.author);
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NoteData } from '../../../models/NoteData';
2+
3+
import * as P from './../placeholders/content-class-placeholders';
4+
import { applyConditionalTemplate } from './apply-conditional-template';
5+
6+
export const applyContentClassTemplate = (noteData: NoteData, text: string): string => {
7+
return applyConditionalTemplate(text, P, noteData.contentClass);
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NoteData } from '../../../models/NoteData';
2+
3+
import * as P from './../placeholders/place-name-placeholders';
4+
import { applyConditionalTemplate } from './apply-conditional-template';
5+
6+
export const applyPlaceNameTemplate = (noteData: NoteData, text: string): string => {
7+
return applyConditionalTemplate(text, P, noteData.placeName);
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NoteData } from '../../../models/NoteData';
2+
3+
import * as P from './../placeholders/source-application-placeholders';
4+
import { applyConditionalTemplate } from './apply-conditional-template';
5+
6+
export const applySourceApplicationTemplate = (noteData: NoteData, text: string): string => {
7+
return applyConditionalTemplate(text, P, noteData.sourceApplication);
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NoteData } from '../../../models/NoteData';
2+
3+
import * as P from './../placeholders/source-placeholders';
4+
import { applyConditionalTemplate } from './apply-conditional-template';
5+
6+
export const applySourceTemplate = (noteData: NoteData, text: string): string => {
7+
return applyConditionalTemplate(text, P, noteData.source);
8+
};

src/utils/templates/apply-functions/apply-sourceurl-template.ts src/utils/templates/apply-functions/apply-source-url-template.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NoteData } from '../../../models/NoteData';
22

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

66
export const applySourceUrlTemplate = (noteData: NoteData, text: string): string => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NoteData } from '../../../models/NoteData';
2+
3+
import * as P from './../placeholders/subject-date-placeholders';
4+
import { applyConditionalTemplate } from './apply-conditional-template';
5+
6+
export const applySubjectDateTemplate = (noteData: NoteData, text: string): string => {
7+
return applyConditionalTemplate(text, P, noteData.subjectDate);
8+
};

src/utils/templates/apply-functions/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ export * from './apply-tags-template';
33
export * from './apply-title-template';
44
export * from './apply-createdat-template';
55
export * from './apply-updatedat-template';
6-
export * from './apply-sourceurl-template';
6+
export * from './apply-subject-date-template';
7+
export * from './apply-author-template';
8+
export * from './apply-source-template';
9+
export * from './apply-source-url-template';
10+
export * from './apply-source-application-template';
11+
export * from './apply-place-name-template';
12+
export * from './apply-content-class-template';
13+
export * from './apply-application-data-template';
714
export * from './apply-location-template';
15+
export * from './apply-altitude-template';
816
export * from './apply-original-template';
917
export * from './apply-notebook-template';
1018
export * from './apply-remindertime-template';

src/utils/templates/checker-functions.ts

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11

22
import * as CREATIONTIME from './placeholders/createdat-placeholders';
33
import * as LOCATION from './placeholders/location-placeholders';
4+
import * as ALTITUDE from './placeholders/altitude-placeholders';
45
import * as NOTEBOOK from './placeholders/notebook-placeholders';
56
import * as ORIGINALLINK from './placeholders/original-placeholders';
6-
import * as SOURCEURL from './placeholders/sourceurl-placeholders';
7+
import * as SUBJECTDATE from './placeholders/subject-date-placeholders';
8+
import * as AUTHOR from './placeholders/author-placeholders';
9+
import * as SOURCE from './placeholders/source-placeholders';
10+
import * as SOURCEURL from './placeholders/source-url-placeholders';
11+
import * as SOURCEAPPLICATION from './placeholders/source-application-placeholders';
12+
import * as PLACENAME from './placeholders/place-name-placeholders';
13+
import * as CONTENTCLASS from './placeholders/content-class-placeholders';
14+
import * as YAMLAPPLICATIONDATA from './placeholders/application-data-yaml-list-placeholders';
715
import * as TAGS from './placeholders/tags-placeholders';
816
import * as YAMLARRAYTAGS from './placeholders/tags-array-placeholders';
917
import * as YAMLLISTTAGS from './placeholders/tags-yaml-list-placeholders';
@@ -31,15 +39,39 @@ export const hasReminderOrderInTemplate = (templateContent: string): boolean =>
3139
export const hasLocationInTemplate = (templateContent: string): boolean => {
3240
return hasItemInTemplate(LOCATION, templateContent);
3341
};
42+
export const hasAltitudeInTemplate = (templateContent: string): boolean => {
43+
return hasItemInTemplate(ALTITUDE, templateContent);
44+
};
3445
export const hasNotebookInTemplate = (templateContent: string): boolean => {
3546
return hasItemInTemplate(NOTEBOOK, templateContent);
3647
};
3748
export const hasOriginalLinkInTemplate = (templateContent: string): boolean => {
3849
return hasItemInTemplate(ORIGINALLINK, templateContent);
3950
};
51+
export const hasSubjectDateInTemplate = (templateContent: string): boolean => {
52+
return hasItemInTemplate(SUBJECTDATE, templateContent);
53+
};
54+
export const hasAuthorInTemplate = (templateContent: string): boolean => {
55+
return hasItemInTemplate(AUTHOR, templateContent);
56+
};
57+
export const hasSourceInTemplate = (templateContent: string): boolean => {
58+
return hasItemInTemplate(SOURCE, templateContent);
59+
};
4060
export const hasSourceURLInTemplate = (templateContent: string): boolean => {
4161
return hasItemInTemplate(SOURCEURL, templateContent);
4262
};
63+
export const hasSourceApplicationInTemplate = (templateContent: string): boolean => {
64+
return hasItemInTemplate(SOURCEAPPLICATION, templateContent);
65+
};
66+
export const hasPlaceNameInTemplate = (templateContent: string): boolean => {
67+
return hasItemInTemplate(PLACENAME, templateContent);
68+
};
69+
export const hasContentClassInTemplate = (templateContent: string): boolean => {
70+
return hasItemInTemplate(CONTENTCLASS, templateContent);
71+
};
72+
export const hasApplicationDataInTemplate = (templateContent: string): boolean => {
73+
return hasItemInTemplate(YAMLAPPLICATIONDATA, templateContent);
74+
};
4375
export const hasAnyTagsInTemplate = (templateContent: string): boolean => {
4476
return (hasItemInTemplate(TAGS, templateContent)
4577
|| hasItemInTemplate(YAMLARRAYTAGS, templateContent)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const CONTENT_PLACEHOLDER = '{altitude}';
2+
export const START_BLOCK = '{altitude-block}';
3+
export const END_BLOCK = '{end-altitude-block}';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const CONTENT_PLACEHOLDER = '{application-data-yaml-list}';
2+
export const START_BLOCK = '{application-data-yaml-list-block}';
3+
export const END_BLOCK = '{end-application-data-yaml-list-block}';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const CONTENT_PLACEHOLDER = '{author}';
2+
export const START_BLOCK = '{author-block}';
3+
export const END_BLOCK = '{end-author-block}';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const CONTENT_PLACEHOLDER = '{content-class}';
2+
export const START_BLOCK = '{content-class-block}';
3+
export const END_BLOCK = '{end-content-class-block}';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const CONTENT_PLACEHOLDER = '{place-name}';
2+
export const START_BLOCK = '{place-name-block}';
3+
export const END_BLOCK = '{end-place-name-block}';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const CONTENT_PLACEHOLDER = '{source-application}';
2+
export const START_BLOCK = '{source-application-block}';
3+
export const END_BLOCK = '{end-source-application-block}';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const CONTENT_PLACEHOLDER = '{source}';
2+
export const START_BLOCK = '{source-block}';
3+
export const END_BLOCK = '{end-source-block}';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const CONTENT_PLACEHOLDER = '{subject-date}';
2+
export const START_BLOCK = '{subject-date-block}';
3+
export const END_BLOCK = '{end-subject-date-block}';

0 commit comments

Comments
 (0)