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

#204 - Evernote bug bounty #207

Merged
merged 15 commits into from
Feb 9, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { applyTemplateOnBlock } from './apply-template-on-block';
import { getTemplateBlockSettings } from './get-templateblock-settings';

export const applyTagsArrayTemplate = (noteData: NoteData, inputText: string, check: Function): string => {
if (noteData.tags) {
noteData.tags = JSON.stringify(noteData.tags.split(' '));
}
const tagsTemplateSettings = getTemplateBlockSettings(inputText, check, P, noteData.tags);
const tags = (noteData.tags)
? JSON.stringify(noteData.tags.split(' '))
: undefined;

const tagsTemplateSettings = getTemplateBlockSettings(inputText, check, P, tags);

return applyTemplateOnBlock(tagsTemplateSettings);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { NoteData } from '../../../models/NoteData';
import * as P from '../placeholders/tags-yaml-list-placeholders';

import { applyTemplateOnBlock } from './apply-template-on-block';
import { getTemplateBlockSettings } from './get-templateblock-settings';

export const applyTagsYamlListTemplate = (noteData: NoteData, inputText: string, check: Function): string => {
let tags;
if (noteData.tags) {
tags = '\n'+noteData.tags.split(' ').map(tag => ` - ${tag.replace(/^#/, '')}`).join('\n');
}
const tagsTemplateSettings = getTemplateBlockSettings(inputText, check, P, tags);

return applyTemplateOnBlock(tagsTemplateSettings);
};
1 change: 1 addition & 0 deletions src/formats/yarle/utils/templates/apply-functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './apply-remindertime-template';
export * from './apply-reminderorder-template';
export * from './apply-reminderdonetime-template';
export * from './apply-tags-array-template';
export * from './apply-tags-yaml-list-template';
4 changes: 3 additions & 1 deletion src/formats/yarle/utils/templates/checker-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as REMINDERORDER from './placeholders/reminderorder-placeholders';
import * as REMINDERTIME from './placeholders/remindertime-placeholders';
import * as SOURCEURL from './placeholders/sourceurl-placeholders';
import * as YAMLARRAYTAGS from './placeholders/tags-array-placeholders';
import * as YAMLLISTTAGS from './placeholders/tags-yaml-list-placeholders';
import * as TAGS from './placeholders/tags-placeholders';
import * as UPDATETIME from './placeholders/updatedat-placeholders';

Expand Down Expand Up @@ -40,7 +41,8 @@ export const hasSourceURLInTemplate = (templateContent: string): boolean => {
};
export const hasAnyTagsInTemplate = (templateContent: string): boolean => {
return (hasItemInTemplate(TAGS, templateContent)
|| hasItemInTemplate(YAMLARRAYTAGS, templateContent));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the various bits of code for array tags now? It looks like they are unused?

Copy link
Contributor Author

@akosbalasko akosbalasko Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, yeah, I was thinking on it, as you wish, I think the whole array tags in yaml together with its templates is currently not used. @lishid any suggestions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think removing it would be best, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lishid removed

|| hasItemInTemplate(YAMLARRAYTAGS, templateContent)
|| hasItemInTemplate(YAMLLISTTAGS, templateContent));
};

export const hasMetadataInTemplate = (templateContent: string): boolean => {
Expand Down
4 changes: 2 additions & 2 deletions src/formats/yarle/utils/templates/default-template.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const frontmatterDelimiter = '---\n';
const sourceBlock = '{source-url-block}\nsource: {source-url}\n\n{end-source-url-block}';
const tagBlock = '{tags-array-block}\ntags: {tags-array}\n\n{end-tags-array-block}';
const sourceBlock = '{source-url-block}source: {source-url}{end-source-url-block}\n';
const tagBlock = '{tags-yaml-list-block}\ntags: {tags-yaml-list}\n\n{end-tags-yaml-list-block}';
const titleBlock = '{title-block}# {title}\n\n{end-title-block}';
tgrosinger marked this conversation as resolved.
Show resolved Hide resolved
const contentBlock = '{content-block}{content}{end-content-block}\n';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CONTENT_PLACEHOLDER = '{tags-yaml-list}';
export const START_BLOCK = '{tags-yaml-list-block}';
export const END_BLOCK = '{end-tags-yaml-list-block}';
4 changes: 2 additions & 2 deletions src/formats/yarle/utils/templates/templates.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NoteData } from '../../models/NoteData';

import { YarleOptions } from '../../options';
import { applyContentTemplate, applyCreatedAtTemplate, applyLocationTemplate, applyNotebookTemplate, applyReminderDoneTimeTemplate, applyReminderOrderTemplate, applyReminderTimeTemplate, applySourceUrlTemplate, applyTagsArrayTemplate, applyTagsTemplate, applyTitleTemplate, applyUpdatedAtTemplate } from './apply-functions';
import { applyContentTemplate, applyCreatedAtTemplate, applyLocationTemplate, applyNotebookTemplate, applyReminderDoneTimeTemplate, applyReminderOrderTemplate, applyReminderTimeTemplate, applySourceUrlTemplate, applyTagsArrayTemplate,applyTagsYamlListTemplate, applyTagsTemplate, applyTitleTemplate, applyUpdatedAtTemplate } from './apply-functions';

import * as T from './placeholders/metadata-placeholders';
import { removeCreatedAtPlaceholder, removeLinkToOriginalTemplate, removeLocationPlaceholder, removeNotebookPlaceholder, removeReminderDoneTimePlaceholder, removeReminderOrderPlaceholder, removeReminderTimePlaceholder, removeSourceUrlPlaceholder, removeUpdatedAtPlaceholder } from './remove-functions';
Expand All @@ -13,7 +13,7 @@ export const applyTemplate = (noteData: NoteData, yarleOptions: YarleOptions) =>
result = applyTitleTemplate(noteData, result, () => noteData.title);
result = applyTagsTemplate(noteData, result, () => !yarleOptions.skipTags);
result = applyTagsArrayTemplate(noteData, result, () => !yarleOptions.skipTags);

result = applyTagsYamlListTemplate(noteData, result, () => !yarleOptions.skipTags);
result = applyContentTemplate(noteData, result, () => noteData.content);

result = removeLinkToOriginalTemplate(result);
Expand Down