feat: md icon prefix
This commit is contained in:
parent
346b97153f
commit
9e8d4e6388
|
|
@ -1,5 +1,5 @@
|
|||
import {createMemo, For} from 'solid-js';
|
||||
import { marked } from '../../markdown';
|
||||
import {parseMarkdown} from '../../markdown';
|
||||
import { getLayerStyle } from './hooks/dimensions';
|
||||
import type { CardData } from './types';
|
||||
import {DeckStore} from "./hooks/deckStore";
|
||||
|
|
@ -16,7 +16,7 @@ export function CardLayer(props: CardLayerProps) {
|
|||
const showBounds = () => props.store.state.isEditing;
|
||||
|
||||
function renderLayerContent(content: string) {
|
||||
return marked.parse(processVariables(content, props.cardData, props.store.state.cards)) as string;
|
||||
return parseMarkdown(processVariables(content, props.cardData, props.store.state.cards), props.cardData.iconPath) as string;
|
||||
}
|
||||
return (
|
||||
<For each={layers()}>
|
||||
|
|
|
|||
|
|
@ -269,7 +269,22 @@ export function createDeckStore(
|
|||
|
||||
const generateCode = () => {
|
||||
const layersStr = formatLayers(state.layerConfigs);
|
||||
return `:md-deck[${state.rawSrc || state.src}]{size="${state.sizeW}x${state.sizeH}" grid="${state.gridW}x${state.gridH}" bleed="${state.bleed}" padding="${state.padding}" layers="${layersStr}"}`;
|
||||
const parts = [
|
||||
`:md-deck[${state.rawSrc || state.src}]`,
|
||||
`{size="${state.sizeW}x${state.sizeH}"`,
|
||||
`grid="${state.gridW}x${state.gridH}"`
|
||||
];
|
||||
|
||||
// 仅在非默认值时添加 bleed 和 padding
|
||||
if (state.bleed !== DECK_DEFAULTS.BLEED) {
|
||||
parts.push(`bleed="${state.bleed}"`);
|
||||
}
|
||||
if (state.padding !== DECK_DEFAULTS.PADDING) {
|
||||
parts.push(`padding="${state.padding}"`);
|
||||
}
|
||||
|
||||
parts.push(`layers="${layersStr}"}`);
|
||||
return parts.join(' ');
|
||||
};
|
||||
|
||||
const copyCode = async () => {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,15 @@ import markedAlert from "marked-alert";
|
|||
import markedMermaid from "./mermaid";
|
||||
import {gfmHeadingId} from "marked-gfm-heading-id";
|
||||
|
||||
let globalIconPrefix: string | undefined = undefined;
|
||||
function overrideIconPrefix(path?: string){
|
||||
globalIconPrefix = path;
|
||||
return {
|
||||
[Symbol.dispose](){
|
||||
globalIconPrefix = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 使用 marked-directive 来支持指令语法
|
||||
const marked = new Marked()
|
||||
.use(gfmHeadingId())
|
||||
|
|
@ -26,7 +35,8 @@ const marked = new Marked()
|
|||
// :[blah] becomes <i class="icon icon-blah"></i>
|
||||
renderer(token) {
|
||||
if (!token.meta.name) {
|
||||
return `<icon class="icon-${token.text}"></icon>`;
|
||||
const style = globalIconPrefix ? `style="--icon-src: url('${globalIconPrefix}${token.text}.png')"` : '';
|
||||
return `<icon ${style} class="icon-${token.text}"></icon>`;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -89,8 +99,9 @@ const marked = new Marked()
|
|||
}]
|
||||
});
|
||||
|
||||
export function parseMarkdown(content: string): string {
|
||||
return marked.parse(content.trimStart()) as string;
|
||||
export function parseMarkdown(content: string, iconPrefix?: string): string {
|
||||
using prefix = overrideIconPrefix(iconPrefix);
|
||||
return marked.parse(content.trimStart()) as string;
|
||||
}
|
||||
|
||||
export { marked };
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ icon{
|
|||
width: 1em;
|
||||
height: 1em;
|
||||
--icon-src: '';
|
||||
background: var(--icon-src);
|
||||
background-image: var(--icon-src);
|
||||
background-size: contain;
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
|
|
|
|||
Loading…
Reference in New Issue