Skip to content

Commit 0a09194

Browse files
committed
properly handle block refs in links
1 parent a8e23ef commit 0a09194

File tree

6 files changed

+74
-11
lines changed

6 files changed

+74
-11
lines changed

automation/build/esbuild.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const build = await esbuild.build({
3535
outfile: 'main.js',
3636
minify: true,
3737
metafile: true,
38+
conditions: ['browser', 'production'],
3839
define: {
3940
MB_DEV_BUILD: 'false',
4041
MB_DEBUG: 'false',

automation/build/esbuild.dev.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const context = await esbuild.context({
3434
treeShaking: true,
3535
outdir: `exampleVault/.obsidian/plugins/${manifest.id}/`,
3636
outbase: 'packages/obsidian/src',
37+
conditions: ['browser', 'development'],
3738
define: {
3839
MB_DEV_BUILD: 'false',
3940
MB_DEBUG: 'true',

exampleVault/View Fields/View Field.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ object:
1212
key: value
1313
file: Example Note with Embeds
1414
image: Other/Images/subfolder/img_frozen_branch.jpg
15-
someInputValue: 2
16-
someComputedValue: 4
15+
someInputValue: 1
16+
someComputedValue: 2
1717
images:
1818
- Other/Images/img_flower.webp
1919
- Other/Images/img_butterfly.webp

packages/core/src/fields/button/ButtonActionRunner.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,17 @@ export class ButtonActionRunner {
5454
};
5555
}
5656

57-
resolveFilePath(filePath: string, relativeFilePath?: string): string {
57+
/**
58+
* Resolves a file name, path or link to a file path.
59+
*/
60+
resolveFilePath(filePath: string, relativeTo?: string): string {
5861
const targetFilePath = MDLinkParser.isLink(filePath) ? MDLinkParser.parseLink(filePath).target : filePath;
59-
const resolvedFilePath = this.plugin.internal.file.getPathByName(targetFilePath, relativeFilePath);
62+
const resolvedFilePath = this.plugin.internal.file.getPathByName(targetFilePath, relativeTo);
6063
if (resolvedFilePath === undefined) {
6164
throw new MetaBindParsingError({
6265
errorLevel: ErrorLevel.ERROR,
6366
cause: `Could not find a file that matches "${filePath}".`,
64-
effect: `Could not resolve path or link "${filePath}" relative to "${relativeFilePath}".`,
67+
effect: `Could not resolve path or link "${filePath}" relative to "${relativeTo}".`,
6568
});
6669
}
6770

packages/core/src/parsers/MarkdownLinkParser.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ import { isUrl, openURL } from 'packages/core/src/utils/Utils';
99
const P_MDLinkInner: Parser<[string, string | undefined, string | undefined]> = P.sequence(
1010
P_FilePath, // the file path
1111
P.or(
12-
P.string('#^')
13-
.then(P.manyNotOf('[]#|^:'))
14-
.map(x => '^' + x), // the optional block
15-
P.string('#').then(P.manyNotOf('[]#|^:')), // the optional heading
16-
P.succeed(undefined),
12+
P.string('#').then(P.manyNotOf('[]#|:')), // either a heading with maybe a block
13+
P.string('#').result(undefined), // or an empty heading
14+
P.succeed(undefined), // or no heading at all
1715
),
1816
P.string('|').then(P.manyNotOf('[]')).optional(), // the optional alias
1917
);

tests/parserTests/MarkdownLinkParser.test.ts

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('markdown link parser', () => {
4141
);
4242
});
4343

44-
test('should parse wiki with block', () => {
44+
test('should parse wiki with heading', () => {
4545
expect(MDLinkParser.parseLink('[[test#123]]')).toEqual(
4646
toLink({
4747
isEmbed: false,
@@ -53,6 +53,66 @@ describe('markdown link parser', () => {
5353
);
5454
});
5555

56+
test('should parse wiki with only heading', () => {
57+
expect(MDLinkParser.parseLink('[[#123]]')).toEqual(
58+
toLink({
59+
isEmbed: false,
60+
target: '',
61+
block: '123',
62+
alias: undefined,
63+
internal: true,
64+
}),
65+
);
66+
});
67+
68+
test('should parse wiki with block', () => {
69+
expect(MDLinkParser.parseLink('[[test#^123]]')).toEqual(
70+
toLink({
71+
isEmbed: false,
72+
target: 'test',
73+
block: '^123',
74+
alias: undefined,
75+
internal: true,
76+
}),
77+
);
78+
});
79+
80+
test('should parse wiki only block', () => {
81+
expect(MDLinkParser.parseLink('[[#^123]]')).toEqual(
82+
toLink({
83+
isEmbed: false,
84+
target: '',
85+
block: '^123',
86+
alias: undefined,
87+
internal: true,
88+
}),
89+
);
90+
});
91+
92+
test('should parse wiki with heading and block', () => {
93+
expect(MDLinkParser.parseLink('[[test#123^456]]')).toEqual(
94+
toLink({
95+
isEmbed: false,
96+
target: 'test',
97+
block: '123^456',
98+
alias: undefined,
99+
internal: true,
100+
}),
101+
);
102+
});
103+
104+
test('should parse wiki with only heading and block', () => {
105+
expect(MDLinkParser.parseLink('[[#123^456]]')).toEqual(
106+
toLink({
107+
isEmbed: false,
108+
target: '',
109+
block: '123^456',
110+
alias: undefined,
111+
internal: true,
112+
}),
113+
);
114+
});
115+
56116
test('should parse wiki with alias', () => {
57117
expect(MDLinkParser.parseLink('[[test|something]]')).toEqual(
58118
toLink({

0 commit comments

Comments
 (0)