feat: {{prop}} in cards

This commit is contained in:
hyper 2026-02-27 20:29:48 +08:00
parent f32bbe59b3
commit 082007cf9b
2 changed files with 26 additions and 5 deletions

View File

@ -4,18 +4,28 @@ import { getLayerStyle } from './hooks/dimensions';
import { useCardSelection } from './hooks/useCardSelection';
import { getSelectionBoxStyle } from './hooks/useCardSelection';
import type { DeckStore } from './hooks/deckStore';
import type { CardData } from '../types';
import type { CardData } from './types';
export interface CardPreviewProps {
store: DeckStore;
}
/**
* layer
* body {{prop}} markdown
*/
function processBody(body: string, currentRow: CardData): string {
// 替换 {{prop}} 为对应列的内容
const processedBody = body.replace(/\{\{(\w+)\}\}/g, (_, key) => currentRow[key] || '');
// 使用 marked 解析 markdown
return marked.parse(processedBody) as string;
}
/**
* layer
*/
function renderLayerContent(layer: { prop: string }, cardData: CardData): string {
const content = cardData[layer.prop] || '';
return marked.parse(content) as string;
return processBody(content, cardData);
}
/**

View File

@ -2,6 +2,7 @@ import { For, createMemo } from 'solid-js';
import { marked } from '../../markdown';
import { getLayerStyle } from './hooks/dimensions';
import type { DeckStore } from './hooks/deckStore';
import type { CardData } from './types';
import jsPDF from 'jspdf';
export interface PrintPreviewProps {
@ -10,12 +11,22 @@ export interface PrintPreviewProps {
onExport: () => void;
}
/**
* body {{prop}} markdown
*/
function processBody(body: string, currentRow: CardData): string {
// 替换 {{prop}} 为对应列的内容
const processedBody = body.replace(/\{\{(\w+)\}\}/g, (_, key) => currentRow[key] || '');
// 使用 marked 解析 markdown
return marked.parse(processedBody) as string;
}
/**
* layer
*/
function renderLayerContent(layer: { prop: string }, cardData: { [key: string]: string }): string {
function renderLayerContent(layer: { prop: string }, cardData: CardData): string {
const content = cardData[layer.prop] || '';
return marked.parse(content) as string;
return processBody(content, cardData);
}
/**