Skip to content

Commit b12bf5c

Browse files
committed
支持 grid 子选项内容解析
1 parent 9095750 commit b12bf5c

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

docs/content/usage/grid.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ PageForge 支持网格布局语法。
159159
```
160160

161161
::: grid cols-3 gap-6
162-
- __🚀 快速上手__
162+
- ### 🚀 快速上手
163163
零配置,开箱即用,
164164
支持 Markdown 所有基础语法。
165165

@@ -168,6 +168,10 @@ PageForge 支持网格布局语法。
168168
支持自定义扩展。
169169

170170
- ### 🎨 主题系统
171-
提供多套主题,
172-
支持自定义主题。
171+
提供多套主题,
172+
支持自定义主题。
173+
174+
```java
175+
console.log(1)
176+
```
173177
:::

lib/extension/marked/pageforge-grid.js

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,61 @@ const PageForgeGridExtension = {
5454
const content = src.slice(headerLength, endIndex);
5555
const raw = src.slice(0, endIndex + 4);
5656

57-
const items = content.split(/\n(?=\s*[-*+]|\s*\d+\.)/g)
58-
.map(item => item.trim())
57+
// 分割列表项并保持原始格式
58+
const items = [];
59+
let currentItem = '';
60+
let inItem = false;
61+
62+
content.split('\n').forEach(line => {
63+
const listMarkerMatch = line.match(/^(\s*)([-*+]|\d+\.)\s/);
64+
65+
if (listMarkerMatch) {
66+
// 如果已经在处理一个项目,保存它
67+
if (currentItem) {
68+
items.push(currentItem.trim());
69+
}
70+
// 开始新的项目,移除列表标记
71+
currentItem = line.slice(listMarkerMatch[0].length);
72+
inItem = true;
73+
}
74+
else if (inItem) {
75+
// 对于项目的后续行,直接添加
76+
currentItem += '\n' + line;
77+
}
78+
});
79+
80+
// 添加最后一个项目
81+
if (currentItem) {
82+
items.push(currentItem.trim());
83+
}
84+
85+
// 为每个项目创建 tokens
86+
const processedItems = items
5987
.filter(item => item)
6088
.map(item => {
61-
return item.replace(/^[-*+]\s+|^\d+\.\s+/, '');
89+
const itemTokens = this.lexer.blockTokens(item, []);
90+
return {
91+
content: item,
92+
tokens: itemTokens
93+
};
6294
});
6395

6496
return {
6597
type: 'pageforgeGrid',
6698
raw,
67-
content: items,
99+
items: processedItems,
68100
options: gridOptions,
69101
tokens: []
70102
};
71103
},
72104

73105
renderer(token) {
106+
const processedItems = token.items.map(item => {
107+
return this.parser.parse(item.tokens);
108+
});
109+
74110
return loadComponent('grid', {
75-
content: token.content,
111+
content: processedItems,
76112
options: token.options,
77113
config: config.feature?.grid?.options || {}
78114
});

0 commit comments

Comments
 (0)