Skip to content

Commit 1696734

Browse files
committed
remove old parser
1 parent d352da5 commit 1696734

File tree

8 files changed

+40
-750
lines changed

8 files changed

+40
-750
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Obsidian Meta Bind Changelog
22

3+
# Unreleased
4+
5+
Breaking Changes
6+
7+
- removed setting migrations for settings from plugin versions earlier than `0.6.0`
8+
39
# 0.7.2
410

511
Changes

exampleVault/Input Fields/List.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ list:
33
- apple
44
- banana
55
- berries
6+
- "[[file]]"
67
list2:
78
- "[[Other/Example Notes/Example Note with Image.md|Example Note with Image]]"
89
- "[[Other/Example Notes/Example Note with Callouts.md|Example Note with Callouts]]"

src/main.ts

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ import { API } from './api/API';
77
import { setFirstWeekday } from './utils/DatePickerUtils';
88
import { createMarkdownRenderChildWidgetEditorPlugin } from './cm6/Cm6_ViewPlugin';
99
import { MDRCManager } from './MDRCManager';
10-
import { DEFAULT_SETTINGS, type InputFieldTemplate, type MetaBindPluginSettings } from './settings/Settings';
10+
import { DEFAULT_SETTINGS, type MetaBindPluginSettings } from './settings/Settings';
1111
import { type IPlugin } from './IPlugin';
12-
import { EnclosingPair, ParserUtils } from './utils/ParserUtils';
13-
import { ErrorLevel, MetaBindParsingError } from './utils/errors/MetaBindErrors';
1412
import { ObsidianMetadataAdapter } from './metadata/ObsidianMetadataAdapter';
1513
import { FaqView, MB_FAQ_VIEW_TYPE } from './utils/faq/FaqView';
1614

@@ -128,26 +126,6 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
128126
const bestLinkPath = this.app.metadataCache.getFirstLinkpathDest(name, '');
129127

130128
return bestLinkPath === null ? [] : [bestLinkPath.path];
131-
132-
// const fileNameIsPath = isPath(name);
133-
// const processedFileName = fileNameIsPath ? removeFileEnding(name) : getFileName(removeFileEnding(name));
134-
//
135-
// const allFiles = this.app.vault.getMarkdownFiles();
136-
// const filePaths: string[] = [];
137-
// for (const file of allFiles) {
138-
// // console.log(removeFileEnding(file.path));
139-
// if (fileNameIsPath) {
140-
// if (removeFileEnding(file.path) === processedFileName) {
141-
// filePaths.push(file.path);
142-
// }
143-
// } else {
144-
// if (getFileName(removeFileEnding(file.name)) === processedFileName) {
145-
// filePaths.push(file.path);
146-
// }
147-
// }
148-
// }
149-
//
150-
// return filePaths;
151129
}
152130

153131
isFilePathExcluded(path: string): boolean {
@@ -176,45 +154,11 @@ export default class MetaBindPlugin extends Plugin implements IPlugin {
176154
console.log(`meta-bind | Main >> settings save`);
177155

178156
DateParser.dateFormat = this.settings.preferredDateFormat;
179-
// this.api.inputFieldParser.parseTemplates(this.settings.inputTemplates);
180157
setFirstWeekday(this.settings.firstWeekday);
181158
await this.saveData(this.settings);
182159
}
183160

184161
applyTemplatesMigration(oldSettings: MetaBindPluginSettings): MetaBindPluginSettings {
185-
if (oldSettings.inputTemplates !== undefined) {
186-
const templates = oldSettings.inputTemplates;
187-
const newTemplates: InputFieldTemplate[] = [];
188-
189-
try {
190-
let templateDeclarations = templates ? ParserUtils.split(templates, '\n', new EnclosingPair('[', ']')) : [];
191-
templateDeclarations = templateDeclarations.map(x => x.trim()).filter(x => x.length > 0);
192-
193-
for (const templateDeclaration of templateDeclarations) {
194-
let templateDeclarationParts: string[] = ParserUtils.split(templateDeclaration, '->', new EnclosingPair('[', ']'));
195-
templateDeclarationParts = templateDeclarationParts.map(x => x.trim());
196-
197-
if (templateDeclarationParts.length === 1) {
198-
throw new MetaBindParsingError({
199-
errorLevel: ErrorLevel.CRITICAL,
200-
effect: 'failed to parse template declaration',
201-
cause: `template must include one "->"`,
202-
});
203-
} else if (templateDeclarationParts.length === 2) {
204-
newTemplates.push({
205-
name: templateDeclarationParts[0],
206-
declaration: templateDeclarationParts[1],
207-
});
208-
}
209-
}
210-
} catch (e) {
211-
console.warn('failed to migrate templates', e);
212-
}
213-
214-
delete oldSettings.inputTemplates;
215-
oldSettings.inputFieldTemplates = newTemplates;
216-
}
217-
218162
return oldSettings;
219163
}
220164

src/parsers/MarkdownLinkParser.ts

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,36 @@
1-
import { EnclosingPair, ParserUtils } from '../utils/ParserUtils';
2-
import { ErrorLevel, MetaBindParsingError } from '../utils/errors/MetaBindErrors';
1+
import { P } from '@lemons_dev/parsinom/lib/ParsiNOM';
2+
import { filePath } from './nomParsers/BindTargetParsers';
3+
import { type Parser } from '@lemons_dev/parsinom/lib/Parser';
4+
import { runParser } from './ParsingError';
5+
6+
const mdLinkInnerParser = P.sequence(
7+
filePath, // the file path
8+
P.string('#').then(P.manyNotOf('[]#|^:')).optional(), // the optional heading
9+
P.string('|').then(P.manyNotOf('[]').optional()), // the optional alias
10+
);
11+
12+
const mdLinkParser: Parser<MarkdownLink> = P.sequenceMap(
13+
(a, b) => {
14+
return {
15+
isEmbed: a !== undefined,
16+
target: b[0],
17+
block: b[1],
18+
alias: b[2],
19+
};
20+
},
21+
P.string('!').optional(),
22+
mdLinkInnerParser.wrapString('[[', ']]'),
23+
);
324

425
export interface MarkdownLink {
526
isEmbed: boolean;
627
target: string;
7-
block: string;
8-
alias: string;
28+
block?: string;
29+
alias?: string;
930
}
1031

11-
// TODO: rebuild this with parsinom
1232
export function parseMdLink(link: string): MarkdownLink {
13-
if (!link) {
14-
throw new MetaBindParsingError({ errorLevel: ErrorLevel.ERROR, effect: 'failed to parse md link', cause: 'invalid link, link is empty' });
15-
}
16-
17-
const mdLink: MarkdownLink = {} as MarkdownLink;
18-
mdLink.isEmbed = link.startsWith('!');
19-
const linkContent = ParserUtils.getInBetween(link, new EnclosingPair('[[', ']]'));
20-
21-
if (!linkContent) {
22-
throw new MetaBindParsingError({ errorLevel: ErrorLevel.ERROR, effect: 'failed to parse md link', cause: 'invalid link, link is empty' });
23-
}
24-
25-
if (typeof linkContent !== 'string') {
26-
throw new MetaBindParsingError({ errorLevel: ErrorLevel.ERROR, effect: 'failed to parse md link', cause: 'invalid link, link format is invalid' });
27-
}
28-
29-
const linkParts = linkContent.split('|');
30-
if (linkParts.length === 2) {
31-
mdLink.alias = linkParts[1];
32-
} else if (linkParts.length > 2) {
33-
throw new MetaBindParsingError({
34-
errorLevel: ErrorLevel.ERROR,
35-
effect: 'failed to parse md link',
36-
cause: "invalid link, link may only contain a maximum of one '|'",
37-
});
38-
}
39-
40-
const targetParts = linkParts[0].split('#');
41-
if (targetParts.length === 1) {
42-
mdLink.target = targetParts[0];
43-
} else if (targetParts.length === 2) {
44-
mdLink.target = targetParts[0];
45-
mdLink.block = targetParts[1];
46-
} else {
47-
throw new MetaBindParsingError({
48-
errorLevel: ErrorLevel.ERROR,
49-
effect: 'failed to parse md link',
50-
cause: "invalid link, link target may only contain a maximum of one '#'",
51-
});
52-
}
53-
54-
return mdLink;
33+
return runParser(mdLinkParser, link);
5534
}
5635

5736
export function isMdLink(str: string): boolean {

src/parsers/nomParsers/BindTargetParsers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { P_UTILS } from '@lemons_dev/parsinom/lib/ParserUtils';
44
import { type UnvalidatedBindTargetDeclaration } from '../inputFieldParser/InputFieldDeclaration';
55
import { createResultNode, doubleQuotedString, ident, type ParsingResultNode } from './GeneralParsers';
66

7-
const filePath: Parser<string> = P.manyNotOf('{}[]#^|:?').box('file path');
7+
export const filePath: Parser<string> = P.manyNotOf('{}[]#^|:?').box('file path');
88

99
const metadataPathPartIdent: Parser<ParsingResultNode> = ident.node(createResultNode);
1010

0 commit comments

Comments
 (0)