Initial commit

This commit is contained in:
Leon Mika 2025-07-07 22:22:28 +10:00
commit 26de64d667
3 changed files with 77 additions and 0 deletions

50
main.js Normal file
View file

@ -0,0 +1,50 @@
const { Plugin } = require('obsidian');
class CsvParser {
constructor(lines) {
let rows = lines.split("\n");
this._cells = rows.map((l) => l.split(","));
}
cells() {
return this._cells;
}
}
class CsvPlugin extends Plugin {
async onload() {
this.addStyle();
this.registerMarkdownCodeBlockProcessor('csv', (source, el, ctx) => {
const wrapper = el.createEl('div');
wrapper.addClass('csv-table-wrapper');
const table = wrapper.createEl('table');
table.addClass('csv-table');
let cp = new CsvParser(source);
let twrap = null;
for (let row of cp.cells()) {
if (twrap == null) {
twrap = table.createEl('thead');
} else if (twrap.nodeName == 'THEAD') {
twrap = table.createEl('tbody');
}
let rowElem = twrap.createEl('tr');
for (let col of row) {
rowElem.createEl('td', { text: col });
}
}
});
}
addStyle() {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = this.app.vault.adapter.getResourcePath('styles.css');
document.head.appendChild(link);
}
}
module.exports = CsvPlugin;

10
manifest.json Normal file
View file

@ -0,0 +1,10 @@
{
"id": "csv-blocks",
"name": "CSV Blocks",
"version": "1.0.0",
"minAppVersion": "0.15.0",
"description": "A plugin that renders CSV code blocks as a table",
"author": "Leon Mika",
"authorUrl": "",
"isDesktopOnly": false
}

17
styles.css Normal file
View file

@ -0,0 +1,17 @@
div.csv-table-wrapper {
max-height: 300px;
overflow-y: auto;
}
.csv-table {
border-collapse: collapse;
}
.csv-table thead td {
font-weight: bold;
}
.csv-table td {
border: 1px solid var(--background-modifier-border);
padding: 4px 8px;
}