diff --git a/README.md b/README.md index e01baa9e..85c0ab63 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,7 @@ The following configurational properties are available: | ```sanitizeResourceNameSpaces``` | true or false | Replace spaces in resource names with the `replacementChar`. e.g "linked file.jpg" will be converted to "linked_file.jpg" | ```replacementChar``` | string | the replacement character. e.g "linked*file.jpg" will be converted to "linked_file.jpg". It defaults to "_" | ```replacementCharacterMap``` | JSON Object | it contains character key-value pairs, the keys will be replaced by the proper values in the filename -| ```globalReplacementSettings``` | JSON Array | it contains search and replace pairs, the keys will be replaced by the proper values according to the given type (title or content). Please note: this property has to be in valid JSON Array format, and each item has to have type ('title' or 'content'), regex (what you want to replace as a valid regular expression) and replace (what you want to push instead of the matched text) properties) +| ```globalReplacementSettings``` | JSON Array | it contains search and replace pairs, the keys will be replaced by the proper values according to the given type (title or content). Please note: this property has to be in valid JSON Array format, and each item has to have type ('title', 'content' or 'tag'), regex (what you want to replace as a valid regular expression) and replace (what you want to push instead of the matched text) properties) | ```keepOriginalAmountOfNewlines``` | true or false | keep the original amount of newlines, default is false, when the multiple newlines are collapsed to one. | ```generateNakedUrls``` | true or false | if it's true, Yarle generates 'naked' external Urls without any extra characters. If its false, external Urls are wrapped by '<' and '>' characters | ```addExtensionToInternalLinks``` | true or false | adds '.md' extensions at the end of internal file links, to make them recognizable by DevonThink and other tools diff --git a/config.json b/config.json index 1be42adb..9714d18a 100644 --- a/config.json +++ b/config.json @@ -59,6 +59,11 @@ "type": "content", "regex": "", "replace": "" + }, + { + "type": "tag", + "regex": "", + "replace": "" } ], "logseqSettings": { diff --git a/src/models/ReplaceType.ts b/src/models/ReplaceType.ts index c64002aa..eeacfec9 100644 --- a/src/models/ReplaceType.ts +++ b/src/models/ReplaceType.ts @@ -1,4 +1,5 @@ export enum ReplaceType { title = 'title', - content = 'content' + content = 'content', + tag = 'tag' } \ No newline at end of file diff --git a/src/ui/index.html b/src/ui/index.html index fbf28e42..cab94678 100644 --- a/src/ui/index.html +++ b/src/ui/index.html @@ -536,7 +536,7 @@
Attachments
diff --git a/src/utils/content-utils.ts b/src/utils/content-utils.ts index be92284f..e1eacc99 100644 --- a/src/utils/content-utils.ts +++ b/src/utils/content-utils.ts @@ -7,6 +7,7 @@ import { EvernoteNoteData, NoteData } from './../models'; import { getHtmlFileLink } from './folder-utils'; import { escapeStringRegexp } from './escape-string-regexp'; import { OutputFormat } from './../output-format'; +import { performRegexpOnTag } from './get-title'; export const getMetadata = (note: EvernoteNoteData, notebookName: string): MetaData => { @@ -97,10 +98,13 @@ export const logTags = (note: EvernoteNoteData): string => { let cleanTag = tag .toString() .replace(/^#/, ''); + + cleanTag = performRegexpOnTag(yarleOptions, cleanTag) if (tagOptions) { cleanTag = cleanTag.replace(new RegExp(escapeStringRegexp(tagOptions.separatorInEN), 'g'), tagOptions.replaceSeparatorWith); } + const replaceSpaceWith = (tagOptions && tagOptions.replaceSpaceWith) || '-'; cleanTag = cleanTag.replace(/ /g, replaceSpaceWith); diff --git a/src/utils/get-title.ts b/src/utils/get-title.ts index 2cce70ed..0ba1eac2 100644 --- a/src/utils/get-title.ts +++ b/src/utils/get-title.ts @@ -25,4 +25,8 @@ export const performRegexpOnTitle = (options: YarleOptions, title: string): stri export const performRegexpOnContent = (options: YarleOptions, content: string): string => { return regexpProcess(options, content, ReplaceType.content); +} + +export const performRegexpOnTag = (options: YarleOptions, tag: string): string => { + return regexpProcess(options, tag, ReplaceType.tag) } \ No newline at end of file diff --git a/test/data/test-noteWithNestedTagsWithGlobalRegex.enex b/test/data/test-noteWithNestedTagsWithGlobalRegex.enex new file mode 100644 index 00000000..49f2b0b6 --- /dev/null +++ b/test/data/test-noteWithNestedTagsWithGlobalRegex.enex @@ -0,0 +1,5 @@ + + + +test -note with text only
This is the content
]]>
20181006T084349Z20181006T084411Ztag1_nestedTag1tag2_nestedTag2akosdesktop.mac0
+
diff --git a/test/data/test-noteWithNestedTagsWithGlobalRegex.md b/test/data/test-noteWithNestedTagsWithGlobalRegex.md new file mode 100644 index 00000000..23d3c302 --- /dev/null +++ b/test/data/test-noteWithNestedTagsWithGlobalRegex.md @@ -0,0 +1,12 @@ +# test -note with text only + +--- +Tag(s): #tag1/nestedTag1 #tag2/nestedTag2 + +--- + +This is the content + + Created at: 2018-10-06T09:43:49+01:00 + Updated at: 2018-10-06T09:44:11+01:00 + diff --git a/test/yarle-tests.ts b/test/yarle-tests.ts index ef59db99..53d49cbc 100644 --- a/test/yarle-tests.ts +++ b/test/yarle-tests.ts @@ -2,6 +2,7 @@ import { YarleTest } from './yarle-test'; import { OutputFormat } from "../src/output-format"; import * as path from 'path'; import { YarleTestModifierOptions } from './yarle-test-modifier-options'; +import { ReplaceType } from '../src/models'; const dataFolder = `${path.sep}data${path.sep}`; const testDataFolder = `${path.sep}test${dataFolder}`; @@ -95,6 +96,24 @@ export const yarleTests: Array = [ expectedOutputPath: `${dataFolder}test-noteWithNestedTags.md`, }, + { + name: 'Note with nested tags with global regexp', + options: { + enexSources: [ `.${testDataFolder}test-noteWithNestedTagsWithGlobalRegex.enex` ], + outputDir: 'out', + isMetadataNeeded: true, + globalReplacementSettings: [ + { + type: ReplaceType.tag, + regex: "_+", + replace: "/" + } + ], + useHashTags: true + }, + testOutputPath: `notes${path.sep}test-noteWithNestedTagsWithGlobalRegex${path.sep}test -note with text only.md`, + expectedOutputPath: `${dataFolder}test-noteWithNestedTagsWithGlobalRegex.md`, + }, { name: 'Note with nested tags containing spaces', options: {