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);
|
const ARGS = parseArgs(process.argv);
|
||||||
if (!ARGS.in || !ARGS.out) { console.error('缺少 --in / --out'); process.exit(1); }
|
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(内联字体) ------------------------------ */
|
/* ------------------------------ KaTeX CSS(内联字体) ------------------------------ */
|
||||||
function buildKatexCss() {
|
function buildKatexCss() {
|
||||||
@@ -211,6 +211,55 @@ function buildAnswerBody(rawMd) {
|
|||||||
return out.join('\n');
|
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) {
|
function buildPlainBody(rawMd) {
|
||||||
const { text, store } = protectMath(unlinkWikilinks(stripFrontmatter(rawMd)));
|
const { text, store } = protectMath(unlinkWikilinks(stripFrontmatter(rawMd)));
|
||||||
@@ -224,7 +273,9 @@ function buildPlainBody(rawMd) {
|
|||||||
const raw = fs.readFileSync(inPath, 'utf8');
|
const raw = fs.readFileSync(inPath, 'utf8');
|
||||||
const title = ARGS.title || path.basename(inPath, '.md');
|
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 html = htmlShell(title, body);
|
||||||
|
|
||||||
const buildDir = path.join(__dirname, 'build');
|
const buildDir = path.join(__dirname, 'build');
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""prep_exam.py —— 模拟卷 Markdown 预处理,产出可直接打印的干净稿
|
||||||
|
|
||||||
|
把「第三次模拟-数学一」这类目录下的
|
||||||
|
01-模拟卷.md / 02a-答案与解析-客观题.md / 02b-答案与解析-解答题.md
|
||||||
|
清洗成两份:
|
||||||
|
paper.md —— 只留试卷(去掉每题末尾的考点行与 △ 预测标记,否则等于泄题)
|
||||||
|
full.md —— 试卷 + 两册解析,供对答案时通读
|
||||||
|
|
||||||
|
用法:
|
||||||
|
python prep_exam.py <模拟卷目录> [--outdir <输出目录>]
|
||||||
|
|
||||||
|
默认输出到 <仓库>/.workbuddy/tools/md2pdf/build/<目录名>/
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import io
|
||||||
|
|
||||||
|
FM_RE = re.compile(r'^---\r?\n[\s\S]*?\r?\n---\r?\n?')
|
||||||
|
KP_RE = re.compile(r'^>\s*\*\*考点\*\*\s*·') # 每题末尾的考点跳转行
|
||||||
|
TRI_NOTE_RE = re.compile(r'带\s*\*\*△\*\*\s*的是[^\n]*') # △ 图例说明
|
||||||
|
LINK_RE = re.compile(r'(?<!\!)\[([^\]]*)\]\((?!https?:)[^)]*\)')
|
||||||
|
|
||||||
|
|
||||||
|
def strip_frontmatter(md):
|
||||||
|
m = FM_RE.match(md)
|
||||||
|
return md[m.end():] if m else md
|
||||||
|
|
||||||
|
|
||||||
|
def clean(md, drop_kp=True, drop_tri=True, drop_tail=False):
|
||||||
|
"""drop_kp: 去掉考点行(做题版必须去掉);drop_tri: 去掉 △ 预测标记;drop_tail: 去掉「交卷后」收尾段"""
|
||||||
|
md = strip_frontmatter(md)
|
||||||
|
lines = [ln for ln in md.split('\n')
|
||||||
|
if not (drop_kp and KP_RE.match(ln.strip()))]
|
||||||
|
md = '\n'.join(lines)
|
||||||
|
if drop_tri:
|
||||||
|
md = TRI_NOTE_RE.sub('', md)
|
||||||
|
md = md.replace('△ ', '').replace('△', '')
|
||||||
|
if drop_tail:
|
||||||
|
md = re.split(r'^##\s*交卷后\s*$', md, flags=re.M)[0]
|
||||||
|
md = re.sub(r'\n*-{3,}\s*$', '', md.rstrip()) + '\n'
|
||||||
|
md = LINK_RE.sub(r'\1', md) # 相对链接降级成纯文字,PDF 里点不动
|
||||||
|
md = re.sub(r'[ \t]+\n', '\n', md) # 行尾空白
|
||||||
|
md = re.sub(r'\n{3,}', '\n\n', md) # 压掉连续空行
|
||||||
|
return md.strip() + '\n'
|
||||||
|
|
||||||
|
|
||||||
|
def build(volume_dir, outdir=None):
|
||||||
|
volume_dir = os.path.abspath(volume_dir)
|
||||||
|
name = os.path.basename(volume_dir.rstrip('/\\'))
|
||||||
|
repo = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
|
||||||
|
outdir = outdir or os.path.join(repo, '.workbuddy', 'tools', 'md2pdf', 'build', name)
|
||||||
|
os.makedirs(outdir, exist_ok=True)
|
||||||
|
|
||||||
|
def read(fn):
|
||||||
|
p = os.path.join(volume_dir, fn)
|
||||||
|
if not os.path.exists(p):
|
||||||
|
return None
|
||||||
|
return io.open(p, encoding='utf-8').read()
|
||||||
|
|
||||||
|
paper = read('01-模拟卷.md')
|
||||||
|
if paper is None:
|
||||||
|
raise SystemExit('找不到 01-模拟卷.md:%s' % volume_dir)
|
||||||
|
|
||||||
|
paper_clean = clean(paper, drop_tail=True)
|
||||||
|
p_paper = os.path.join(outdir, 'paper.md')
|
||||||
|
io.open(p_paper, 'w', encoding='utf-8').write(paper_clean)
|
||||||
|
|
||||||
|
parts = [paper_clean]
|
||||||
|
for fn, head in (('02a-答案与解析-客观题.md', '答案与解析 · 客观题'),
|
||||||
|
('02b-答案与解析-解答题.md', '答案与解析 · 解答题')):
|
||||||
|
raw = read(fn)
|
||||||
|
if raw is None:
|
||||||
|
continue
|
||||||
|
parts.append('<div style="break-before: page"></div>\n')
|
||||||
|
parts.append(clean(raw, drop_kp=False, drop_tri=False))
|
||||||
|
p_full = os.path.join(outdir, 'full.md')
|
||||||
|
io.open(p_full, 'w', encoding='utf-8').write('\n'.join(parts))
|
||||||
|
|
||||||
|
print('OK %s' % p_paper)
|
||||||
|
print('OK %s' % p_full)
|
||||||
|
return p_paper, p_full
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print(__doc__)
|
||||||
|
sys.exit(1)
|
||||||
|
args = sys.argv[1:]
|
||||||
|
outdir = None
|
||||||
|
if '--outdir' in args:
|
||||||
|
i = args.index('--outdir')
|
||||||
|
outdir = args[i + 1]
|
||||||
|
del args[i:i + 2]
|
||||||
|
build(args[0], outdir)
|
||||||
Binary file not shown.
Binary file not shown.
@@ -33,6 +33,10 @@ tags: [数学一, 模拟卷, 说明]
|
|||||||
| | [04 线代](04-考点手册-线性代数.md) | L01—L06 |
|
| | [04 线代](04-考点手册-线性代数.md) | L01—L06 |
|
||||||
| | [05 概率](05-考点手册-概率论与数理统计.md) | P01—P06 |
|
| | [05 概率](05-考点手册-概率论与数理统计.md) | P01—P06 |
|
||||||
| **依据** | [06-考点预测与分布](06-考点预测与分布.md) | 十年统计、逐题来源、四条规律、空缺、三卷互补表 |
|
| **依据** | [06-考点预测与分布](06-考点预测与分布.md) | 十年统计、逐题来源、四条规律、空缺、三卷互补表 |
|
||||||
|
| **打印** | [做题版 PDF](PDF/第三次模拟-做题版.pdf) | 10 页。选择题/填空题连排(答案写在括号与横线里),解答题**每题独占一页**,留白框撑满纸面 |
|
||||||
|
| | [题目与解析 PDF](PDF/第三次模拟-题目与解析.pdf) | 16 页。试卷 + 两册解析合订,平板通读用 |
|
||||||
|
|
||||||
|
> 做题版 PDF 已去掉每题的"考点"行与 △ 标记——纸上做题不该被提示。要考点跳转,回网页版。
|
||||||
|
|
||||||
## 三、三轮用法
|
## 三、三轮用法
|
||||||
|
|
||||||
@@ -70,3 +74,4 @@ tags: [数学一, 模拟卷, 说明]
|
|||||||
| 日期 | 变更 |
|
| 日期 | 变更 |
|
||||||
|---|---|
|
|---|---|
|
||||||
| 2026-10-31 | 建文件夹,8 个文件(README + 试卷 + 客观题解析 + 解答题解析 + 三册手册 + 预测),22 题 150 分 |
|
| 2026-10-31 | 建文件夹,8 个文件(README + 试卷 + 客观题解析 + 解答题解析 + 三册手册 + 预测),22 题 150 分 |
|
||||||
|
| 2026-10-31 | 出 PDF 两版:做题版 10 页(解答题每题一页留白)、题目与解析合订 16 页 |
|
||||||
|
|||||||
Reference in New Issue
Block a user