Skip to content

Commit 50b853a

Browse files
committed
这个版本看上去很正常
1 parent 7a38e29 commit 50b853a

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

script.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,15 @@ D. (1) 为假命题, (2) 为假命题。
147147

148148
const flushCurrent = () => {
149149
if (!current) return;
150-
const content = fixFont(current.rawContent);
150+
// fixFont: Markdown 加粗(通用)
151+
let content = fixFont(current.rawContent);
152+
153+
// 中文修复:仅限题目正文部分
154+
const isHeaderOrNote = ['title', 'title2', 'title3', 'title0a', 'title0b', 'note'].includes(current.type);
155+
if (!isHeaderOrNote) {
156+
content = content.replace(/([\u4e00-\u9fa5\u3002\uff1f\uff01\uff0c\u3001\uff1b\uff1a\u201c\u201d\u2018\u2019\uff08\uff09\u300a\u300b\u3008\u3009\u3010\u3011\u300e\u300f\u300c\u300d\u3014\u3015\u2026\u2014\uff5e\uff0e]+)/g, '<span class="chinese-fix">$1</span>');
157+
}
158+
151159
const config = Object.values(FORMAT_CONFIG).find(c => c.type === current.type);
152160
if (config) { // 匹配到特殊格式
153161
current.html = config.render(content);
@@ -160,9 +168,9 @@ D. (1) 为假命题, (2) 为假命题。
160168
};
161169

162170
lines.forEach(line => {
163-
const trim0 = line.trim().replace('___', '_________').replace('(_)', '($\\hspace{0.8cm}$)');
171+
const trim0 = line.trim().replace('___', '________').replace('(_)', '($\\hspace{0.8cm}$)');
164172
// 处理中文字体包裹
165-
const trim = trim0.replace(/([\u4e00-\u9fa5\u3002\uff1f\uff01\uff0c\u3001\uff1b\uff1a\u201c\u201d\u2018\u2019\uff08\uff09\u300a\u300b\u3008\u3009\u3010\u3011\u300e\u300f\u300c\u300d\u3014\u3015\u2026\u2014\uff5e\uff0e]+)/g, '<span class="chinese-fix">$1</span>');
173+
// const trim = trim0.replace(/([\u4e00-\u9fa5\u3002\uff1f\uff01\uff0c\u3001\uff1b\uff1a\u201c\u201d\u2018\u2019\uff08\uff09\u300a\u300b\u3008\u3009\u3010\u3011\u300e\u300f\u300c\u300d\u3014\u3015\u2026\u2014\uff5e\uff0e]+)/g, '<span class="chinese-fix">$1</span>');
166174

167175
// -1. 解析 meta 信息(字体大小等)
168176
// 匹配字体设置
@@ -184,7 +192,7 @@ D. (1) 为假命题, (2) 为假命题。
184192
// 估算长度:去掉匹配头,并粗略去掉 $ 和 \ 以评估排版空间
185193
text: mcqMatch[2].replace(/[\$\\]/g, ''),
186194
// HTML本体使用已经包裹过中文字体的 trim 结果
187-
rawHtml: trim.replace(/^([A-D])[.]\s*/, '')
195+
rawHtml: trim0.replace(/^([A-D])[.]\s*/, '')
188196
});
189197
return; // 被判定为选项,直接进入下一循环
190198
} else {
@@ -211,15 +219,15 @@ D. (1) 为假命题, (2) 为假命题。
211219
}
212220

213221
// 2. 题目解析
214-
const matchQ = trim.match(/^(\d+)[.]\s*(.*)/); // 强化正则,容错句号
222+
const matchQ = trim0.match(/^(\d+)[.]\s*(.*)/); // 强化正则,容错句号
215223
if (matchQ) {
216224
flushCurrent();
217225
current = { id: idSeq++, type: 'question', number: matchQ[1], rawContent: matchQ[2].trim(), spacing: 10, forcePageBreak: false };
218226
return;
219227
}
220228

221229
// 3. 小题解析
222-
const matchSub = trim.match(/^(\(\d+\)|\d+)(.*)/);
230+
const matchSub = trim0.match(/^(\(\d+\)|\d+)(.*)/);
223231
if (matchSub && current && current.type == 'question') {
224232
current.rawContent += `<ol class='sub-question' start="${matchSub[1].replace(/\D/g, '')}"><li>${matchSub[2].trim()}</li></ol>`;
225233
return;
@@ -231,13 +239,13 @@ D. (1) 为假命题, (2) 为假命题。
231239
if (isHeader || current.type === 'text') {
232240
// 如果当前是无格式的纯文本,每一行独立成块,以触发自然分页
233241
flushCurrent();
234-
current = { id: idSeq++, type: 'text', rawContent: trim, spacing: 0, forcePageBreak: false };
242+
current = { id: idSeq++, type: 'text', rawContent: trim0, spacing: 0, forcePageBreak: false };
235243
} else {
236244
// 题目块内的续行,依然拼接到一起(保证缩进样式不断裂)
237-
current.rawContent += `<br>${trim}`;
245+
current.rawContent += `<br>${trim0}`;
238246
}
239247
} else {
240-
current = { id: idSeq++, type: 'text', rawContent: trim, spacing: 0, forcePageBreak: false };
248+
current = { id: idSeq++, type: 'text', rawContent: trim0, spacing: 0, forcePageBreak: false };
241249
}
242250
});
243251

0 commit comments

Comments
 (0)