feat(模拟卷三): 出做题版与题目解析合订版 PDF
- 新增 prep_exam.py:清洗试卷(去考点行、去 △ 预测标记、相对链接降级为文字、切掉收尾段),做题版不泄题 - md2pdf.js 增 exam 模式:客观题连排不留白,解答题每题独占一页、留白框 flex 撑满纸面;部分标题与首题同页 - 做题版 10 页 545KB,合订版 16 页 638KB - README 补 PDF 两行与版本记录
This commit is contained in:
@@ -32,7 +32,7 @@ function parseArgs(argv) {
|
||||
}
|
||||
const ARGS = parseArgs(process.argv);
|
||||
if (!ARGS.in || !ARGS.out) { console.error('缺少 --in / --out'); process.exit(1); }
|
||||
const MODE = ARGS.mode === 'answer' ? 'answer' : 'plain';
|
||||
const MODE = ARGS.mode === 'answer' ? 'answer' : (ARGS.mode === 'exam' ? 'exam' : 'plain');
|
||||
|
||||
/* ------------------------------ KaTeX CSS(内联字体) ------------------------------ */
|
||||
function buildKatexCss() {
|
||||
@@ -211,6 +211,55 @@ function buildAnswerBody(rawMd) {
|
||||
return out.join('\n');
|
||||
}
|
||||
|
||||
/* 模拟卷打印版:客观题不留白(答案写在括号/横线里),解答题按分值留白并独占一页 */
|
||||
function buildExamBody(rawMd) {
|
||||
const lines = unlinkWikilinks(stripFrontmatter(rawMd)).split(/\r?\n/);
|
||||
const blocks = [];
|
||||
let buf = [];
|
||||
let group = { title: '' };
|
||||
let cur = null;
|
||||
const flushMd = () => { if (buf.join('\n').trim()) blocks.push({ type: 'md', text: buf.join('\n') }); buf = []; };
|
||||
const flushQ = () => { if (cur) { cur.text = cur.text.join('\n').trim(); blocks.push(cur); cur = null; } };
|
||||
|
||||
for (const line of lines) {
|
||||
const gh = line.match(/^##\s+(.*)$/);
|
||||
const qh = line.match(/^\*\*(\d+)\.\*\*\s*(.*)$/);
|
||||
if (gh) { flushQ(); flushMd(); group = { title: gh[1] }; buf.push(line); continue; }
|
||||
if (qh) { flushQ(); flushMd(); cur = { type: 'q', group: group.title, num: +qh[1], text: [line] }; continue; }
|
||||
if (cur) cur.text.push(line); else buf.push(line);
|
||||
}
|
||||
flushQ(); flushMd();
|
||||
|
||||
const BRK = 'break-before:page;page-break-before:always;';
|
||||
const out = [];
|
||||
let pendingBreak = false;
|
||||
for (const b of blocks) {
|
||||
const { text, store } = protectMath(b.text);
|
||||
if (b.type === 'md') {
|
||||
const html = mdToHtml(text, store);
|
||||
// 部分边界(解答题、交卷后)另起一页;标题与紧接着的首题留在同一页
|
||||
if (/^##\s/.test(b.text.trim()) && /解答题|交卷后/.test(b.text)) {
|
||||
out.push(`<div style="${BRK}">${html}</div>`);
|
||||
pendingBreak = true;
|
||||
} else {
|
||||
out.push(html);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const html = mdToHtml(text, store);
|
||||
if (/选择题/.test(b.group)) { out.push(`<section class="q">${html}</section>`); continue; }
|
||||
if (/填空题/.test(b.group)) { out.push(`<section class="q" style="min-height:10mm">${html}</section>`); continue; }
|
||||
const brk = pendingBreak ? '' : BRK;
|
||||
pendingBreak = false;
|
||||
// 解答题:每题独占一页,留白框弹性撑满剩余高度(短题干就多给纸)
|
||||
out.push(
|
||||
`<section class="q" style="${brk}display:flex;flex-direction:column;min-height:245mm;">${html}` +
|
||||
`<div class="q-space" style="flex:1 1 auto;min-height:70mm"></div></section>`
|
||||
);
|
||||
}
|
||||
return out.join('\n');
|
||||
}
|
||||
|
||||
/* 普通版 */
|
||||
function buildPlainBody(rawMd) {
|
||||
const { text, store } = protectMath(unlinkWikilinks(stripFrontmatter(rawMd)));
|
||||
@@ -224,7 +273,9 @@ function buildPlainBody(rawMd) {
|
||||
const raw = fs.readFileSync(inPath, 'utf8');
|
||||
const title = ARGS.title || path.basename(inPath, '.md');
|
||||
|
||||
const body = MODE === 'answer' ? buildAnswerBody(raw) : buildPlainBody(raw);
|
||||
const body = MODE === 'answer' ? buildAnswerBody(raw)
|
||||
: MODE === 'exam' ? buildExamBody(raw)
|
||||
: buildPlainBody(raw);
|
||||
const html = htmlShell(title, body);
|
||||
|
||||
const buildDir = path.join(__dirname, 'build');
|
||||
|
||||
Reference in New Issue
Block a user