Some checks failed
Deploy / deploy (push) Has been cancelled
学生端:目录 + 居中限宽正文 + 可收起的示例代码栏;目录改成三态圆点, 顶部加总进度;上一课/下一课栏桌面端固定在底部。 教师端:汇总卡片、学生状态标签与筛选(未开始/7 天没学/只读不练等)、 最后学习补「N 天前」、按练习表加「没人一次对/多数人卡住」提示。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
37 lines
950 B
TypeScript
37 lines
950 B
TypeScript
import type { Exercise } from "utils/types"
|
|
|
|
export type Segment =
|
|
{ type: "md"; content: string } | { type: "exercise"; exercise: Exercise }
|
|
|
|
export function parseExercises(
|
|
content: string,
|
|
exercises: Exercise[],
|
|
): Segment[] {
|
|
const exerciseMap = new Map(exercises.map((e) => [e.id, e]))
|
|
const segments: Segment[] = []
|
|
const regex = /\[\[exercise:(\d+)\]\]/g
|
|
let lastIndex = 0
|
|
let match: RegExpExecArray | null
|
|
|
|
while ((match = regex.exec(content)) !== null) {
|
|
if (match.index > lastIndex) {
|
|
segments.push({
|
|
type: "md",
|
|
content: content.slice(lastIndex, match.index),
|
|
})
|
|
}
|
|
const id = parseInt(match[1])
|
|
const exercise = exerciseMap.get(id)
|
|
if (exercise) {
|
|
segments.push({ type: "exercise", exercise })
|
|
}
|
|
lastIndex = regex.lastIndex
|
|
}
|
|
|
|
if (lastIndex < content.length) {
|
|
segments.push({ type: "md", content: content.slice(lastIndex) })
|
|
}
|
|
|
|
return segments
|
|
}
|