feat: inline md-table

This commit is contained in:
2026-03-21 17:48:30 +08:00
parent 3d9617f06c
commit 6b411c2f24
2 changed files with 84 additions and 10 deletions
+6 -6
View File
@@ -1,8 +1,8 @@
import { customElement, noShadowDOM } from 'solid-element';
import { createSignal, For, Show, createEffect, createMemo, createResource } from 'solid-js';
import { marked } from '../markdown';
import { loadCSV, CSV, processVariables, isCSV } from './utils/csv-loader';
import { resolvePath } from './utils/path';
import {loadCSV, CSV, processVariables} from './utils/csv-loader';
export interface TableProps {
roll?: boolean;
@@ -23,8 +23,8 @@ customElement('md-table', { roll: false, remix: false }, (props, { element }) =>
const [bodyHtml, setBodyHtml] = createSignal('');
let tabsContainer: HTMLDivElement | undefined;
// 从 element 的 textContent 获取 CSV 路径
const src = element?.textContent?.trim() || '';
// 从 element 的 textContent 获取 CSV 路径或 inline CSV 数据
const rawContent = element?.textContent?.trim() || '';
// 隐藏原始文本内容
if (element) {
@@ -35,11 +35,11 @@ customElement('md-table', { roll: false, remix: false }, (props, { element }) =>
const articleEl = element?.closest('article[data-src]');
const articlePath = articleEl?.getAttribute('data-src') || '';
// 解析相对路径
const resolvedSrc = resolvePath(articlePath, src);
// 如果是 inline CSV,直接使用;否则解析相对路径
const contentOrPath = isCSV(rawContent) ? rawContent : resolvePath(articlePath, rawContent);
// 使用 createResource 加载 CSV,自动响应路径变化并避免重复加载
const [csvData] = createResource(() => resolvedSrc, loadCSV);
const [csvData] = createResource(() => contentOrPath, loadCSV);
// 当数据加载完成后更新 rows
createEffect(() => {