Skip to content

Commit c8d63f5

Browse files
authored
feat: adding tags to global regexp (#649)
1 parent 795d900 commit c8d63f5

12 files changed

+65
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ The following configurational properties are available:
213213
| ```sanitizeResourceNameSpaces``` | true or false | Replace spaces in resource names with the `replacementChar`. e.g "linked file.jpg" will be converted to "linked_file.jpg"
214214
| ```replacementChar``` | string | the replacement character. e.g "linked*file.jpg" will be converted to "linked_file.jpg". It defaults to "_"
215215
| ```replacementCharacterMap``` | JSON Object | it contains character key-value pairs, the keys will be replaced by the proper values in the filename
216-
| ```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 <b>type</b> ('title' or 'content'), <b>regex</b> (what you want to replace as a valid regular expression) and <b>replace</b> (what you want to push instead of the matched text) properties)
216+
| ```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 <b>type</b> ('title', 'content' or 'tag'), <b>regex</b> (what you want to replace as a valid regular expression) and <b>replace</b> (what you want to push instead of the matched text) properties)
217217
| ```keepOriginalAmountOfNewlines``` | true or false | keep the original amount of newlines, default is false, when the multiple newlines are collapsed to one.
218218
```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
219219
| ```addExtensionToInternalLinks``` | true or false | adds '.md' extensions at the end of internal file links, to make them recognizable by DevonThink and other tools

config.json

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
"type": "content",
6060
"regex": "",
6161
"replace": ""
62+
},
63+
{
64+
"type": "tag",
65+
"regex": "",
66+
"replace": ""
6267
}
6368
],
6469
"logseqSettings": {

config.logseq.json

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
"type": "content",
4444
"regex": "",
4545
"replace": ""
46+
},
47+
{
48+
"type": "tag",
49+
"regex": "",
50+
"replace": ""
4651
}
4752
],
4853
"pathSeparator": "/",

config.tana.json

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
"type": "content",
5959
"regex": "",
6060
"replace": ""
61+
},
62+
{
63+
"type": "tag",
64+
"regex": "",
65+
"replace": ""
6166
}
6267
],
6368
"generateNakedUrls": true,

src/models/ReplaceType.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum ReplaceType {
22
title = 'title',
3-
content = 'content'
3+
content = 'content',
4+
tag = 'tag'
45
}

src/ui/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,9 @@ <h5 class="info-text">Attachments</h5>
536536
</div>
537537
<div class="form-group">
538538
<label for="globalReplacementSettings">
539-
Global search and replace (regexp) in note title and content
539+
Global search and replace (regexp) in note title, content and tags
540540
<br><div style='font-size: 12px;'><i>(
541-
Please provide settings in valid JSON Array format, each item has to have <b>type</b> ('title' or 'content'), <b>regex</b> (what you want to replace as a valid regular expression) and <b>replace</b> (what you want to push instead of the matched text) properties)</i></div>
541+
Please provide settings in valid JSON Array format, each item has to have <b>type</b> ('title', 'content' or 'tag'), <b>regex</b> (what you want to replace as a valid regular expression) and <b>replace</b> (what you want to push instead of the matched text) properties)</i></div>
542542
</label>
543543
<textarea class="form-control configurationItem" name="globalReplacementSettings" id="globalReplacementSettings" rows="15"></textarea>
544544

src/ui/renderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const updateDomAndConfig = (configItem, disable) => {
177177
if (domItem.getAttribute('type') === 'checkbox'){
178178
document.getElementById(configItem.name).checked = configItem.value;
179179
} else {
180-
if (isObject(itemValueToStore)){
180+
if (isObject(itemValueToStore) || Array.isArray(itemValueToStore)){
181181
itemValueToStore = JSON.stringify(configItem.value)
182182
document.getElementById(configItem.name).value = JSON.stringify(configItem.value, undefined, 2);;
183183
}

src/utils/content-utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { EvernoteNoteData, NoteData } from './../models';
77
import { getHtmlFileLink } from './folder-utils';
88
import { escapeStringRegexp } from './escape-string-regexp';
99
import { OutputFormat } from './../output-format';
10+
import { performRegexpOnTag } from './get-title';
1011

1112
export const getMetadata = (note: EvernoteNoteData, notebookName: string): MetaData => {
1213

@@ -97,10 +98,13 @@ export const logTags = (note: EvernoteNoteData): string => {
9798
let cleanTag = tag
9899
.toString()
99100
.replace(/^#/, '');
101+
102+
cleanTag = performRegexpOnTag(yarleOptions, cleanTag)
100103
if (tagOptions) {
101104
cleanTag = cleanTag.replace(new RegExp(escapeStringRegexp(tagOptions.separatorInEN), 'g'), tagOptions.replaceSeparatorWith);
102105
}
103106

107+
104108
const replaceSpaceWith = (tagOptions && tagOptions.replaceSpaceWith) || '-';
105109

106110
cleanTag = cleanTag.replace(/ /g, replaceSpaceWith);

src/utils/get-title.ts

+4
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ export const performRegexpOnTitle = (options: YarleOptions, title: string): stri
2525

2626
export const performRegexpOnContent = (options: YarleOptions, content: string): string => {
2727
return regexpProcess(options, content, ReplaceType.content);
28+
}
29+
30+
export const performRegexpOnTag = (options: YarleOptions, tag: string): string => {
31+
return regexpProcess(options, tag, ReplaceType.tag)
2832
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export3.dtd">
3+
<en-export export-date="20181006T112423Z" application="Evernote" version="Evernote Mac 7.5 (457109)">
4+
<note><title>test -note with text only</title><content><![CDATA[<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note><div>This is the content</div></en-note>]]></content><created>20181006T084349Z</created><updated>20181006T084411Z</updated><tag>tag1_nestedTag1</tag><tag>tag2_nestedTag2</tag><note-attributes><author>akos</author><source>desktop.mac</source><reminder-order>0</reminder-order></note-attributes></note>
5+
</en-export>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# test -note with text only
2+
3+
---
4+
Tag(s): #tag1/nestedTag1 #tag2/nestedTag2
5+
6+
---
7+
8+
This is the content
9+
10+
Created at: 2018-10-06T09:43:49+01:00
11+
Updated at: 2018-10-06T09:44:11+01:00
12+

test/yarle-tests.ts

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { YarleTest } from './yarle-test';
22
import { OutputFormat } from "../src/output-format";
33
import * as path from 'path';
44
import { YarleTestModifierOptions } from './yarle-test-modifier-options';
5+
import { ReplaceType } from '../src/models';
56

67
const dataFolder = `${path.sep}data${path.sep}`;
78
const testDataFolder = `${path.sep}test${dataFolder}`;
@@ -95,6 +96,24 @@ export const yarleTests: Array<YarleTest> = [
9596

9697
expectedOutputPath: `${dataFolder}test-noteWithNestedTags.md`,
9798
},
99+
{
100+
name: 'Note with nested tags with global regexp',
101+
options: {
102+
enexSources: [ `.${testDataFolder}test-noteWithNestedTagsWithGlobalRegex.enex` ],
103+
outputDir: 'out',
104+
isMetadataNeeded: true,
105+
globalReplacementSettings: [
106+
{
107+
type: ReplaceType.tag,
108+
regex: "_+",
109+
replace: "/"
110+
}
111+
],
112+
useHashTags: true
113+
},
114+
testOutputPath: `notes${path.sep}test-noteWithNestedTagsWithGlobalRegex${path.sep}test -note with text only.md`,
115+
expectedOutputPath: `${dataFolder}test-noteWithNestedTagsWithGlobalRegex.md`,
116+
},
98117
{
99118
name: 'Note with nested tags containing spaces',
100119
options: {

0 commit comments

Comments
 (0)