Skip to content

Commit

Permalink
Capture hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
chhoumann committed Jul 15, 2021
1 parent 3e71023 commit 2deeeeb
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ Quickly add new pages or content to your vault.
You can also do a [manual installation](docs/ManualInstallation.md).

## What's new?
### 0.3.6
### 0.3.6 - 0.3.7
- Added setting to create the 'Insert After' line if it isn't found.
- (HOTFIX) Escape regular expression special characters in Insert After when searching for it

### 0.3.5
- You can now execute [inline JavaScript](docs/InlineScripts.md) in templates or captures.
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "quickadd",
"name": "QuickAdd",
"version": "0.3.6",
"version": "0.3.7",
"minAppVersion": "0.12.5",
"description": "Quickly add new pages or content to your vault.",
"author": "Christian B. B. Houmann",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quickadd",
"version": "0.3.6",
"version": "0.3.7",
"description": "Quickly add new pages or content to your vault.",
"main": "main.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/formatters/captureChoiceFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {App, TFile} from "obsidian";
import {log} from "../logger/logManager";
import type QuickAdd from "../main";
import type {IChoiceExecutor} from "../IChoiceExecutor";
import {getLinesInString, templaterParseTemplate} from "../utility";
import {escapeRegExp, getLinesInString, templaterParseTemplate} from "../utility";
import {CREATE_IF_NOT_FOUND_TOP} from "../constants";

export class CaptureChoiceFormatter extends CompleteFormatter {
Expand Down Expand Up @@ -48,7 +48,7 @@ export class CaptureChoiceFormatter extends CompleteFormatter {

if (this.choice.insertAfter.enabled) {
const target: string = await this.format(this.choice.insertAfter.after);
const targetRegex = new RegExp(`\s*${target}\s*`)
const targetRegex = new RegExp(`\s*${escapeRegExp(target)}\s*`)
let fileContentLines: string[] = getLinesInString(this.fileContent);

const targetPosition = fileContentLines.findIndex(line => targetRegex.test(line));
Expand Down
5 changes: 5 additions & 0 deletions src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,9 @@ export function getLinesInString(input: string) {
lines.push(tempString);

return lines;
}

// https://stackoverflow.com/questions/3115150/how-to-escape-regular-expression-special-characters-using-javascript
export function escapeRegExp(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"0.2.16": "0.12.4",
"0.3.6": "0.12.5"
"0.3.7": "0.12.5"
}

0 comments on commit 2deeeeb

Please sign in to comment.