Skip to content

Commit 81bb79b

Browse files
authored
Merge pull request #2529 from holroy/feat-add-attributes-to-standalone-inline-field
Add attributes on inline field to standalone inline field
2 parents d95f20b + 233c7a4 commit 81bb79b

File tree

6 files changed

+33
-21
lines changed

6 files changed

+33
-21
lines changed

package-lock.json

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

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@
2323
"author": "Michael Brenan",
2424
"license": "MIT",
2525
"devDependencies": {
26+
"@rollup/plugin-commonjs": "^25.0.4",
27+
"@rollup/plugin-node-resolve": "^15.2.1",
28+
"@rollup/plugin-typescript": "^11.1.3",
2629
"@types/jest": "^27.0.1",
2730
"@types/luxon": "^3.2.0",
2831
"@types/node": "^16.7.13",
2932
"@types/papaparse": "^5.2.6",
3033
"@types/parsimmon": "^1.10.6",
31-
"@rollup/plugin-commonjs": "^25.0.4",
32-
"@rollup/plugin-node-resolve": "^15.2.1",
33-
"@rollup/plugin-typescript": "^11.1.3",
3434
"@zerollup/ts-transform-paths": "^1.7.18",
3535
"compare-versions": "^4.1.1",
3636
"jest": "^29.7.0",
3737
"jest-environment-jsdom": "^29.7.0",
3838
"obsidian": "^1.4.0",
3939
"prettier": "2.3.2",
40-
"ts-jest": "^29.1.1",
41-
"tslib": "^2.6.2",
42-
"typescript": "^5.2.2",
4340
"rollup": "^2.79.1",
4441
"rollup-jest": "^3.1.0",
4542
"rollup-plugin-copy": "^3.5.0",
4643
"rollup-plugin-typescript2": "^0.35.0",
47-
"rollup-plugin-web-worker-loader": "^1.6.1"
44+
"rollup-plugin-web-worker-loader": "^1.6.1",
45+
"ts-jest": "^29.1.1",
46+
"tslib": "^2.6.2",
47+
"typescript": "^5.2.2"
4848
},
4949
"dependencies": {
5050
"@codemirror/language": "https://github.com/lishid/cm-language",

src/expression/functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,14 +705,14 @@ export namespace DefaultFunctions {
705705
export const display = new FunctionBuilder("display")
706706
.add1("null", (): Literal => "")
707707
.add1("array", (a: Literal[], ctx: Context): Literal => {
708-
return a.map(e => display(ctx, e)).join(", ");
708+
return a.map(e => display(ctx, e)).join(", ");
709709
})
710710
.add1("string", (str: string): Literal => normalizeMarkdown(str))
711711
.add1("link", (a: Link, ctx: Context): Literal => {
712712
if (a.display) {
713713
return display(ctx, a.display);
714714
} else {
715-
return Values.toString(a, ctx.settings).replace(/\[\[.*\|(.*)\]\]/, "$1")
715+
return Values.toString(a, ctx.settings).replace(/\[\[.*\|(.*)\]\]/, "$1");
716716
}
717717
})
718718
.add1("*", (a: Literal, ctx: Context): Literal => {

src/test/function/functions.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,19 @@ test("Evaluate display()", () => {
111111
expect(parseEval('display("[displayname](http://example.com)")')).toEqual("displayname");
112112
expect(parseEval('display("[[test]]")')).toEqual("test");
113113
expect(parseEval('display("[[test|displayname]]")')).toEqual("displayname");
114-
expect(parseEval('display("long [[test]] **with** [[test2|multiple]] [links](http://example.com)")')).toEqual("long test with multiple links");
115-
expect(parseEval('display(1)')).toEqual("1");
116-
expect(parseEval('display(true)')).toEqual("true");
117-
expect(parseEval('display(null)')).toEqual("");
114+
expect(parseEval('display("long [[test]] **with** [[test2|multiple]] [links](http://example.com)")')).toEqual(
115+
"long test with multiple links"
116+
);
117+
expect(parseEval("display(1)")).toEqual("1");
118+
expect(parseEval("display(true)")).toEqual("true");
119+
expect(parseEval("display(null)")).toEqual("");
118120
expect(parseEval('display(date("2024-11-18"))')).toEqual("November 18, 2024");
119121
expect(parseEval('display(dur("7 hours"))')).toEqual("7 hours");
120122
expect(parseEval('display(link("path/to/file.md"))')).toEqual("file");
121123
expect(parseEval('display(link("path/to/file.md", "displayname"))')).toEqual("displayname");
122-
expect(parseEval('display(list("test", 2, link("file.md")))')).toEqual('test, 2, file');
124+
expect(parseEval('display(list("test", 2, link("file.md")))')).toEqual("test, 2, file");
123125
});
124126

125-
126127
// <-- default() -->
127128

128129
test("Evaluate default()", () => {

src/ui/views/inline-field-live-preview.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ class InlineFieldWidget extends WidgetType {
237237

238238
const value = renderContainer.createSpan({
239239
cls: ["dataview", "inline-field-value"],
240+
attr: {
241+
"data-dv-key": this.field.key,
242+
"data-dv-norm-key": canonicalizeVarName(this.field.key),
243+
},
240244
});
241245
renderValue(
242246
this.app,

src/util/normalize.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ export function setsEqual<T>(first: Set<T>, second: Set<T>): boolean {
164164
/** Normalize a markdown string. Removes all markdown tags and obsidian links. */
165165
export function normalizeMarkdown(str: string): string {
166166
// [[test]] -> test
167-
let interim = str.replace(/\[\[([^\|]*?)\]\]/g, "$1")
167+
let interim = str.replace(/\[\[([^\|]*?)\]\]/g, "$1");
168168

169169
// [[test|test]] -> test
170-
interim = interim.replace(/\[\[.*?\|(.*?)\]\]/, "$1")
171-
170+
interim = interim.replace(/\[\[.*?\|(.*?)\]\]/, "$1");
171+
172172
// remove markdown tags
173173
interim = removeMd(interim);
174174

175-
return interim
176-
}
175+
return interim;
176+
}

0 commit comments

Comments
 (0)