Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit a29f6f3

Browse files
committed
stringifyReplacer skeleton
1 parent 7a4c94a commit a29f6f3

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/services/parseServiceHelpers/MarkdownParser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { parseLuxonDatetimeToString, parseLuxonDateToString } from "helpers/Luxo
33
import { Literal, WrappedLiteral } from "obsidian-dataview";
44
import { DataviewService } from "services/DataviewService";
55
import { DateTime } from "luxon";
6-
import { MarkdownBreakerRules } from "helpers/Constants";
6+
import { InputType, MarkdownBreakerRules } from "helpers/Constants";
7+
import stringifyReplacer from "./StringifyReplacer";
78

89
class MarkdownParser extends TypeParser<Literal> {
910
private isInline = false;
@@ -50,7 +51,7 @@ class MarkdownParser extends TypeParser<Literal> {
5051
if (DateTime.isDateTime(wrapped.value)) {
5152
auxMarkdown = this.parse({ type: 'date', value: wrapped.value });
5253
} else {
53-
auxMarkdown = JSON.stringify(wrapped.value);
54+
auxMarkdown = JSON.stringify(wrapped.value, stringifyReplacer);
5455
}
5556
break;
5657
default:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { LocalSettings } from "cdm/SettingsModel";
2+
import { InputType } from "helpers/Constants";
3+
import { Literal } from "obsidian-dataview";
4+
import { DataviewService } from "services/DataviewService";
5+
import { ParseService } from "services/ParseService";
6+
7+
/**
8+
* Custom replacer for JSON.stringify to handle DB Folder types
9+
* @param key
10+
* @param value
11+
* @returns
12+
*/
13+
const stringifyReplacer = (key: string, value: Literal) => {
14+
let wrappedLiteral = DataviewService.wrapLiteral(value);
15+
switch (wrappedLiteral.type) {
16+
case 'link':
17+
return wrappedLiteral.value.markdown();
18+
default:
19+
return value;
20+
}
21+
};
22+
23+
export default stringifyReplacer;

src/services/parseServiceHelpers/TextParser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { DataviewService } from "services/DataviewService";
33
import { DateTime } from "luxon";
44
import { parseLuxonDatetimeToString } from "helpers/LuxonHelper";
55
import { TypeParser } from "cdm/ServicesModel";
6+
import stringifyReplacer from "./StringifyReplacer";
67

78
class TextParser extends TypeParser<string | DataObject> {
89
/**
@@ -24,7 +25,7 @@ class TextParser extends TypeParser<string | DataObject> {
2425
}
2526
try {
2627
// Try to parse to JSON
27-
return JSON.stringify(wrapped.value);
28+
return JSON.stringify(wrapped.value, stringifyReplacer);
2829
} catch (e) {
2930
// Do nothing
3031
}

0 commit comments

Comments
 (0)