Skip to content

Commit 32fbada

Browse files
authored
LivePreview - Normalize spaces in get setting (#508)
* Refactor get setting function to normalize spaces in setting text. This improves the accuracy of setting retrieval by removing unwanted whitespace and zero-width characters. * 1.7.2
1 parent e890c89 commit 32fbada

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@types/mozilla-readability": "^0.2.0",
2424
"@types/turndown": "^5.0.1"
2525
},
26-
"version": "1.7.1",
26+
"version": "1.7.2",
2727
"samepage": {
2828
"extends": "node_modules/roamjs-components/package.json"
2929
}

src/settings.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33

44
import getBlockUidsAndTextsReferencingPage from "roamjs-components/queries/getBlockUidsAndTextsReferencingPage";
55

6+
const normalizeSpaces = (value: string) =>
7+
value.replace(/[\u200B\u200C\u200D\uFEFF]/gu, "").replace(/\s+/gu, " ");
8+
69
export const get = (settingName: string) => {
710
let customTrigger = getBlockUidsAndTextsReferencingPage("42Setting");
8-
var result = null;
11+
let result = null;
12+
913
for (let s of customTrigger) {
10-
if (s.text.includes(settingName)) {
11-
result = s.text
14+
const normalizedText = normalizeSpaces(s.text);
15+
if (normalizedText.includes(settingName)) {
16+
result = normalizedText
1217
.replace("#42Setting ", "")
1318
.replace("#[[42Setting]] ", "")
1419
.replace("[[42Setting]] ", "")

0 commit comments

Comments
 (0)