implemented basic table reading and trigger for expenseManipulation
This commit is contained in:
parent
7b8b9309ef
commit
efee00c529
|
@ -0,0 +1,31 @@
|
|||
import { App, TFile } from "obsidian";
|
||||
|
||||
export async function playWithTable(app: App) {
|
||||
const file = await this.app.workspace.getActiveFile();
|
||||
// trigger if something changed in the file (ex. new expense added)
|
||||
app.vault.on("modify", async (changedFile: TFile) => {
|
||||
if (changedFile.path === file.path) {
|
||||
if (file) {
|
||||
const fileContent = await this.app.vault.read(file);
|
||||
const lines = fileContent.split("\n");
|
||||
let inTable = false;
|
||||
lines.forEach((line) => {
|
||||
if (line.startsWith("|")) {
|
||||
if (line.includes("---")) {
|
||||
// This is the header line, start reading from next line
|
||||
inTable = true;
|
||||
} else if (inTable) {
|
||||
// This is a table line, read the cells
|
||||
const cells = line
|
||||
.split("|")
|
||||
.map((cell) => cell.trim());
|
||||
console.log(cells);
|
||||
}
|
||||
} else {
|
||||
inTable = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
7
main.ts
7
main.ts
|
@ -1,6 +1,7 @@
|
|||
import test from "node:test";
|
||||
import { App, Notice, Plugin, PluginSettingTab, Setting } from "obsidian";
|
||||
import { ExpenseModal } from "./expenseModal";
|
||||
import { playWithTable } from "./expenseManipulation";
|
||||
|
||||
interface BudgetSettings {
|
||||
expenseCategories: object;
|
||||
|
@ -56,8 +57,14 @@ export default class budgetPlugin extends Plugin {
|
|||
// need to set active md file to budget
|
||||
console.log("Debug: trigger new expense modal from ribbon");
|
||||
});
|
||||
|
||||
// Adds a setting tag so the user can configure the aspects of the plugin
|
||||
this.addSettingTab(new ExpenseSettingTab(this.app, this));
|
||||
|
||||
// Adds a listener to the layout-ready event to trigger the playWithTable function
|
||||
this.app.workspace.on("layout-ready", async () => {
|
||||
await playWithTable(this.app);
|
||||
});
|
||||
}
|
||||
|
||||
async loadSettings(): Promise<void> {
|
||||
|
|
Loading…
Reference in New Issue