dsh-zju-lecture-note 2.2.3 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +102 -1
- package/README.md +98 -150
- package/SECURITY.md +136 -44
- package/docs/technical.md +175 -45
- package/lib/client.js +14 -13
- package/lib/index.js +53 -19
- package/lib/tools.js +28 -3
- package/lib/tools.schema.json +28 -3
- package/mcp_server.py +285 -34
- package/package.json +6 -2
- package/skills/scholia-notes/SKILL.md +8 -1
- package/skills/scholia-notes/references/format-spec.md +57 -6
- package/skills/scholia-notes/references/prelude.typ +55 -0
- package/skills/scholia-notes/references/typography-spec.md +4 -4
- package/skills/scholia-notes.manifest.json +9 -9
- package/skills/zju-lecture-summarizer/SKILL.md +56 -11
- package/skills/zju-lecture-summarizer-help/SKILL.md +95 -0
- package/skills/zju-lecture-summarizer-help.manifest.json +14 -0
- package/skills/zju-lecture-summarizer-login/SKILL.md +40 -0
- package/skills/zju-lecture-summarizer-login.manifest.json +14 -0
- package/skills/zju-lecture-summarizer.manifest.json +4 -4
- package/zju_lecture/__init__.py +16 -0
- package/zju_lecture/browser_login.py +923 -0
- package/zju_lecture/cli.py +98 -3
- package/zju_lecture/client.py +808 -741
- package/zju_lecture/handout.py +390 -60
- package/zju_lecture/handout_prelude.typ +47 -2
- package/zju_lecture/note_lint.py +12 -0
- package/zju_lecture/prelude.typ +55 -0
- package/zju_lecture/study_notes.py +415 -4
- package/zju_lecture/typst-packages/VENDORED.md +1 -1
- package/zju_lecture/typst-packages/preview/noteworthy/0.4.0/LICENSE +20 -20
- package/zju_lecture/typst-packages/preview/noteworthy/0.4.0/lib.typ +128 -128
- package/zju_lecture/typst-packages/preview/noteworthy/0.4.0/typst.toml +15 -15
- package/zju_lecture/typst-packages/preview/scholia/0.1.0/src/lib.typ +2 -2
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/LICENSE +21 -21
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/lib/func.typ +142 -142
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/lib/id.typ +11 -11
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/lib/pre-rendering.typ +50 -50
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/lib/sections.typ +141 -141
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/lib/shadows.typ +118 -118
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/showy.typ +267 -267
- package/zju_lecture/typst-packages/preview/showybox/2.0.4/typst.toml +11 -11
package/zju_lecture/handout.py
CHANGED
|
@@ -40,10 +40,15 @@ from .study_notes import (
|
|
|
40
40
|
MARKERS,
|
|
41
41
|
StudyNotesError,
|
|
42
42
|
_run_typst,
|
|
43
|
+
_SUMMARY_LINE_RE,
|
|
44
|
+
_UNKNOWN_MARKER_RE,
|
|
45
|
+
block_boundary,
|
|
43
46
|
find_typst,
|
|
44
47
|
latex_to_typst,
|
|
45
48
|
pad_inline_math,
|
|
46
49
|
split_quote_items,
|
|
50
|
+
split_question_number,
|
|
51
|
+
split_review_labels,
|
|
47
52
|
strip_heading_number,
|
|
48
53
|
)
|
|
49
54
|
|
|
@@ -95,6 +100,8 @@ _TABLE_SEP_RE = re.compile(
|
|
|
95
100
|
)
|
|
96
101
|
_IMAGE_RE = re.compile(r'^!\[([^\]]*)\]\(\s*([^)\s]+)(?:\s+"[^"]*")?\s*\)$')
|
|
97
102
|
_HR_RE = re.compile(r"^\s*([-*_])(?:\s*\1){2,}\s*$")
|
|
103
|
+
#: 只剩破折号的「正文」:`[例] 标题 ——` 拆出来的残渣。
|
|
104
|
+
_DASH_ONLY_RE = re.compile(r"^[—–-]+$")
|
|
98
105
|
_LINK_RE = re.compile(r"\[([^\]]*)\]\(\s*([^)\s]+)(?:\s+\"[^\"]*\")?\s*\)")
|
|
99
106
|
_DETAILS_OPEN_RE = re.compile(r"<details[^>]*>", re.IGNORECASE)
|
|
100
107
|
_DETAILS_CLOSE_RE = re.compile(r"</details\s*>", re.IGNORECASE)
|
|
@@ -323,12 +330,20 @@ def _extract_label(text: str) -> Tuple[str, str]:
|
|
|
323
330
|
|
|
324
331
|
|
|
325
332
|
def _split_knot_title(body: str) -> Tuple[str, str]:
|
|
326
|
-
"""按 ``标题 —— 正文`` 拆开 knot 的内容。
|
|
333
|
+
"""按 ``标题 —— 正文`` 拆开 knot 的内容。
|
|
334
|
+
|
|
335
|
+
标题单独占一行、以 ``——`` 收尾时(正文从下一行开始),残留的破折号不是
|
|
336
|
+
正文的一部分 —— 否则 ``[例] 例 1:… ——`` 会在框里多排一个「—」。
|
|
337
|
+
"""
|
|
327
338
|
for separator in ("——", "—", " – ", " - "):
|
|
328
339
|
if separator in body:
|
|
329
340
|
head, rest = body.split(separator, 1)
|
|
330
|
-
if head.strip()
|
|
331
|
-
|
|
341
|
+
if not head.strip():
|
|
342
|
+
continue
|
|
343
|
+
rest = rest.strip()
|
|
344
|
+
if not rest or _DASH_ONLY_RE.match(rest):
|
|
345
|
+
return head.strip(), ""
|
|
346
|
+
return head.strip(), rest
|
|
332
347
|
return "", body.strip()
|
|
333
348
|
|
|
334
349
|
|
|
@@ -657,6 +672,10 @@ def _quote_block(
|
|
|
657
672
|
"NOTE": ("说明", "def"),
|
|
658
673
|
"TIP": ("提示", "def"),
|
|
659
674
|
}.get(kind, ("", "thm"))
|
|
675
|
+
if kind == "IMPORTANT":
|
|
676
|
+
# 「重点」不再套方框:走 prelude 的 keypoint —— 规范蓝色的文字段落,
|
|
677
|
+
# 只保留首行缩进与段距,没有底色 / 左侧竖线。
|
|
678
|
+
return "#keypoint[*" + label + "* " + body + "]"
|
|
660
679
|
if kind:
|
|
661
680
|
accent = _PALETTE[tone]
|
|
662
681
|
return (
|
|
@@ -733,21 +752,268 @@ def _image_block(
|
|
|
733
752
|
return "#figure(" + ", ".join(figure_args) + ")"
|
|
734
753
|
|
|
735
754
|
|
|
755
|
+
def _read_display_math(
|
|
756
|
+
lines: Sequence[str],
|
|
757
|
+
index: int,
|
|
758
|
+
warnings: List[str],
|
|
759
|
+
) -> Tuple[str, int]:
|
|
760
|
+
"""从 ``lines[index]`` 的 ``$$`` 开始读一个块级公式。
|
|
761
|
+
|
|
762
|
+
返回 ``(Typst 片段, 下一个待处理下标)``;块级公式以 ``$ … $``(两侧
|
|
763
|
+
有空白)输出,Typst 才会把它当居中块级公式。
|
|
764
|
+
"""
|
|
765
|
+
body = [lines[index].strip()[2:]]
|
|
766
|
+
index += 1
|
|
767
|
+
total = len(lines)
|
|
768
|
+
if "$$" in body[0]:
|
|
769
|
+
inner = body[0].split("$$")[0]
|
|
770
|
+
else:
|
|
771
|
+
while index < total:
|
|
772
|
+
line = lines[index].strip()
|
|
773
|
+
index += 1
|
|
774
|
+
if "$$" in line:
|
|
775
|
+
body.append(line.split("$$")[0])
|
|
776
|
+
break
|
|
777
|
+
body.append(line)
|
|
778
|
+
inner = "\n".join(body)
|
|
779
|
+
converted, issues = latex_to_typst(inner.strip())
|
|
780
|
+
warnings.extend(issues)
|
|
781
|
+
return "$ " + converted.strip() + " $", index
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
def _absorbs_blocks(name: str) -> bool:
|
|
785
|
+
"""标记块是否**跨段**:框类装置与证明一直写到下一个标记/标题。
|
|
786
|
+
|
|
787
|
+
``[直觉]`` / ``[练习]`` / ``[边注]`` / ``[强调]`` 这类装置是一句话,
|
|
788
|
+
只吃标记行那一句;定理、定义、例、证明的正文常常带块级公式与多个
|
|
789
|
+
段落,旧实现遇到空行或 ``$$`` 就收尾,公式会被甩到方框外,证明的
|
|
790
|
+
qed 方块也会停在第一段末尾(实地讲义里就是这样误导读者的)。
|
|
791
|
+
"""
|
|
792
|
+
call, _shape = MARKERS[name]
|
|
793
|
+
return call == "proof" or call in _KNOT_CALLS
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
def _collect_marker_body(
|
|
797
|
+
lines: Sequence[str],
|
|
798
|
+
index: int,
|
|
799
|
+
first: str,
|
|
800
|
+
absorb: bool,
|
|
801
|
+
proof: bool = False,
|
|
802
|
+
) -> Tuple[List[str], int]:
|
|
803
|
+
"""收集标记行之后的正文行,返回 ``(行列表, 下一个待处理下标)``。
|
|
804
|
+
|
|
805
|
+
``absorb=False`` 沿用旧规则:遇到空行、标题、公式、列表、表格、代码块
|
|
806
|
+
或下一个标记就停。``absorb=True`` 一直收到下一个标题 / 标记 / 新话题,
|
|
807
|
+
空行保留为段落分隔;``proof=True`` 时不把「短引导词 + 时间码」当边界,
|
|
808
|
+
免得证明被从中间截断。
|
|
809
|
+
"""
|
|
810
|
+
body: List[str] = [first] if first else []
|
|
811
|
+
total = len(lines)
|
|
812
|
+
if absorb:
|
|
813
|
+
while index < total:
|
|
814
|
+
raw = lines[index]
|
|
815
|
+
stripped = raw.strip()
|
|
816
|
+
if block_boundary(stripped, proof=proof):
|
|
817
|
+
break
|
|
818
|
+
body.append(raw)
|
|
819
|
+
index += 1
|
|
820
|
+
else:
|
|
821
|
+
while index < total:
|
|
822
|
+
candidate = lines[index].strip()
|
|
823
|
+
if (
|
|
824
|
+
not candidate
|
|
825
|
+
or _HEADING_RE.match(candidate)
|
|
826
|
+
or _is_marker_start(candidate)
|
|
827
|
+
or candidate.startswith("$$")
|
|
828
|
+
or _LIST_RE.match(lines[index])
|
|
829
|
+
or candidate.startswith("|")
|
|
830
|
+
or _FENCE_RE.match(candidate)
|
|
831
|
+
):
|
|
832
|
+
break
|
|
833
|
+
body.append(candidate)
|
|
834
|
+
index += 1
|
|
835
|
+
while body and not body[0].strip():
|
|
836
|
+
body.pop(0)
|
|
837
|
+
while body and not body[-1].strip():
|
|
838
|
+
body.pop()
|
|
839
|
+
return body, index
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
def _extract_block_label(body: List[str]) -> Tuple[List[str], str]:
|
|
843
|
+
"""摘掉块里的 ``<def:x>``,返回 ``(正文行, label)``。
|
|
844
|
+
|
|
845
|
+
认三个位置:标记行末尾(最常见)、独占一行的 ``<label>``、最后一段末尾。
|
|
846
|
+
跨段标记把 ``<label>`` 写在公式后面单独一行也很自然,三种都认,
|
|
847
|
+
才能和 :func:`_collect_refs` 的编号对得上。
|
|
848
|
+
"""
|
|
849
|
+
if body:
|
|
850
|
+
text, label = _extract_label(body[0])
|
|
851
|
+
if label:
|
|
852
|
+
return [text] + list(body[1:]), label
|
|
853
|
+
for position, raw in enumerate(body):
|
|
854
|
+
stripped = raw.strip()
|
|
855
|
+
if not stripped:
|
|
856
|
+
continue
|
|
857
|
+
text, label = _extract_label(stripped)
|
|
858
|
+
if not label or text.strip():
|
|
859
|
+
continue
|
|
860
|
+
rest = list(body)
|
|
861
|
+
del rest[position]
|
|
862
|
+
return rest, label
|
|
863
|
+
for position in range(len(body) - 1, -1, -1):
|
|
864
|
+
if not body[position].strip():
|
|
865
|
+
continue
|
|
866
|
+
text, label = _extract_label(body[position])
|
|
867
|
+
if not label:
|
|
868
|
+
break
|
|
869
|
+
rest = list(body)
|
|
870
|
+
rest[position] = text
|
|
871
|
+
if not text.strip():
|
|
872
|
+
del rest[position]
|
|
873
|
+
return rest, label
|
|
874
|
+
return list(body), ""
|
|
875
|
+
|
|
876
|
+
|
|
877
|
+
def _split_knot_title_lines(body: List[str]) -> Tuple[str, List[str]]:
|
|
878
|
+
"""只在**第一段**里找 ``标题 —— 正文``;后面的段落原样保留。"""
|
|
879
|
+
if not body:
|
|
880
|
+
return "", []
|
|
881
|
+
title, rest = _split_knot_title(_join_paragraph([body[0]]))
|
|
882
|
+
if not title:
|
|
883
|
+
return "", list(body)
|
|
884
|
+
remainder = list(body[1:])
|
|
885
|
+
if rest.strip():
|
|
886
|
+
return title, [rest] + remainder
|
|
887
|
+
return title, remainder
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
def _render_block_sequence(
|
|
891
|
+
lines: Sequence[str],
|
|
892
|
+
warnings: List[str],
|
|
893
|
+
image_resolver,
|
|
894
|
+
refs: Optional[Dict[str, str]] = None,
|
|
895
|
+
) -> Tuple[str, int]:
|
|
896
|
+
"""把标记块里的若干行渲染成 Typst 块序列(块内段落不缩进)。
|
|
897
|
+
|
|
898
|
+
与 :func:`_render_body` 的区别:不处理标题、不统计章节、不写段首缩进
|
|
899
|
+
(``#h(2em)``)—— 这些内容会作为 ``#theorem{…}`` / ``#proof{…}`` 的
|
|
900
|
+
内容块嵌进装置里,缩进交给装置自己的内边距。
|
|
901
|
+
|
|
902
|
+
返回 ``(Typst 内容, 段落数)``:段落数记进「方框:正文」统计,否则内容
|
|
903
|
+
一搬进装置,分母就凭空变小,比例检查会误报。
|
|
904
|
+
"""
|
|
905
|
+
out: List[str] = []
|
|
906
|
+
paragraph: List[str] = []
|
|
907
|
+
paragraphs = 0
|
|
908
|
+
total = len(lines)
|
|
909
|
+
index = 0
|
|
910
|
+
|
|
911
|
+
def flush() -> None:
|
|
912
|
+
nonlocal paragraphs
|
|
913
|
+
if not paragraph:
|
|
914
|
+
return
|
|
915
|
+
text = _join_paragraph(paragraph)
|
|
916
|
+
paragraph.clear()
|
|
917
|
+
if not text.strip():
|
|
918
|
+
return
|
|
919
|
+
# 「题目 / 切入点 / 关键步骤 / 易错点」写在同一段里时,一段一行排开:
|
|
920
|
+
# 四段式例题排成一大坨在框里很难读(实地讲义里就是这样)。
|
|
921
|
+
for part in split_review_labels(text):
|
|
922
|
+
out.append(_render_rich_text(part, warnings, image_resolver, refs))
|
|
923
|
+
paragraphs += 1
|
|
924
|
+
|
|
925
|
+
while index < total:
|
|
926
|
+
raw = lines[index]
|
|
927
|
+
stripped = raw.strip()
|
|
928
|
+
if not stripped:
|
|
929
|
+
flush()
|
|
930
|
+
index += 1
|
|
931
|
+
continue
|
|
932
|
+
if stripped.startswith("$$"):
|
|
933
|
+
flush()
|
|
934
|
+
math, index = _read_display_math(lines, index, warnings)
|
|
935
|
+
out.append(math)
|
|
936
|
+
continue
|
|
937
|
+
if _LIST_RE.match(raw):
|
|
938
|
+
flush()
|
|
939
|
+
list_lines: List[str] = []
|
|
940
|
+
while index < total and _LIST_RE.match(lines[index]):
|
|
941
|
+
list_lines.append(lines[index])
|
|
942
|
+
index += 1
|
|
943
|
+
out.append(_list_block(list_lines, warnings, image_resolver, refs))
|
|
944
|
+
continue
|
|
945
|
+
if stripped.startswith("|") and stripped.endswith("|"):
|
|
946
|
+
rows: List[str] = []
|
|
947
|
+
while index < total:
|
|
948
|
+
candidate = lines[index].strip()
|
|
949
|
+
if candidate.startswith("|") and candidate.endswith("|"):
|
|
950
|
+
rows.append(candidate)
|
|
951
|
+
index += 1
|
|
952
|
+
else:
|
|
953
|
+
break
|
|
954
|
+
if len(rows) >= 2 and _TABLE_SEP_RE.match(rows[1]):
|
|
955
|
+
flush()
|
|
956
|
+
out.append(_table_block(rows, warnings, image_resolver, refs))
|
|
957
|
+
else:
|
|
958
|
+
paragraph.extend(rows)
|
|
959
|
+
continue
|
|
960
|
+
if stripped.startswith(">"):
|
|
961
|
+
flush()
|
|
962
|
+
quote_lines: List[str] = []
|
|
963
|
+
while index < total and lines[index].strip().startswith(">"):
|
|
964
|
+
quote_lines.append(lines[index])
|
|
965
|
+
index += 1
|
|
966
|
+
out.append(_quote_block(quote_lines, warnings, image_resolver, refs))
|
|
967
|
+
continue
|
|
968
|
+
fence = _FENCE_RE.match(stripped)
|
|
969
|
+
if fence:
|
|
970
|
+
flush()
|
|
971
|
+
marker_text = fence.group(1)
|
|
972
|
+
info = fence.group(2) or ""
|
|
973
|
+
code: List[str] = []
|
|
974
|
+
index += 1
|
|
975
|
+
while index < total and not lines[index].strip().startswith(marker_text[:3]):
|
|
976
|
+
code.append(lines[index])
|
|
977
|
+
index += 1
|
|
978
|
+
if index < total:
|
|
979
|
+
index += 1
|
|
980
|
+
out.append(_code_block(marker_text, info, code))
|
|
981
|
+
continue
|
|
982
|
+
image = _IMAGE_RE.match(stripped)
|
|
983
|
+
if image:
|
|
984
|
+
flush()
|
|
985
|
+
out.append(
|
|
986
|
+
_image_block(
|
|
987
|
+
image.group(1), image.group(2), warnings, image_resolver, refs
|
|
988
|
+
)
|
|
989
|
+
)
|
|
990
|
+
index += 1
|
|
991
|
+
continue
|
|
992
|
+
paragraph.append(raw)
|
|
993
|
+
index += 1
|
|
994
|
+
|
|
995
|
+
flush()
|
|
996
|
+
return "\n\n".join(part for part in out if part.strip()), paragraphs
|
|
997
|
+
|
|
998
|
+
|
|
736
999
|
def _render_marker_block(
|
|
737
1000
|
name: str,
|
|
738
|
-
|
|
1001
|
+
body_lines: Sequence[str],
|
|
739
1002
|
number: str,
|
|
740
1003
|
warnings: List[str],
|
|
741
1004
|
image_resolver,
|
|
742
1005
|
refs: Optional[Dict[str, str]] = None,
|
|
743
|
-
) -> str:
|
|
744
|
-
"""
|
|
1006
|
+
) -> Tuple[str, int]:
|
|
1007
|
+
"""把一个标记块(标记行 + 后续正文)渲染成对应的 PDF 装置。
|
|
1008
|
+
|
|
1009
|
+
返回 ``(Typst 片段, 块内段落数)``;段落数并入全篇的「方框:正文」统计。
|
|
1010
|
+
"""
|
|
745
1011
|
call, shape = MARKERS[name]
|
|
746
1012
|
if call is None:
|
|
747
|
-
return "#divider"
|
|
748
|
-
body, label =
|
|
1013
|
+
return "#divider", 0
|
|
1014
|
+
body, label = _extract_block_label(list(body_lines))
|
|
749
1015
|
if shape == "knot":
|
|
750
|
-
title, content =
|
|
1016
|
+
title, content = _split_knot_title_lines(body)
|
|
751
1017
|
args = [_json_string(number)]
|
|
752
1018
|
if title:
|
|
753
1019
|
args.append(
|
|
@@ -755,24 +1021,25 @@ def _render_marker_block(
|
|
|
755
1021
|
+ _render_inline(title, warnings, image_resolver, refs=refs)
|
|
756
1022
|
+ "]"
|
|
757
1023
|
)
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
+ _render_rich_text(content, warnings, image_resolver, refs)
|
|
761
|
-
+ "]"
|
|
1024
|
+
content_typst, paragraphs = _render_block_sequence(
|
|
1025
|
+
content, warnings, image_resolver, refs
|
|
762
1026
|
)
|
|
1027
|
+
fragment = "#" + call + "(" + ", ".join(args) + ")[" + content_typst + "]"
|
|
763
1028
|
else:
|
|
764
1029
|
if call == "yourturn":
|
|
765
1030
|
# 练习块里已经有书写横线,题面里的短填空线一并丢掉(见规范 §2.1)。
|
|
766
|
-
body = re.sub(r"_{4,}", " ", body
|
|
767
|
-
|
|
1031
|
+
body = [re.sub(r"_{4,}", " ", line) for line in body]
|
|
1032
|
+
content_typst, paragraphs = _render_block_sequence(
|
|
1033
|
+
body, warnings, image_resolver, refs
|
|
1034
|
+
)
|
|
768
1035
|
if call == "sidenote":
|
|
769
1036
|
# 边注的符号必须用圆括号参数;方括号写法会被当成第二个内容块。
|
|
770
|
-
fragment = "#sidenote([" +
|
|
1037
|
+
fragment = "#sidenote([" + content_typst + "], symbol: [!])"
|
|
771
1038
|
else:
|
|
772
|
-
fragment = "#" + call + "[" +
|
|
1039
|
+
fragment = "#" + call + "[" + content_typst + "]"
|
|
773
1040
|
if label:
|
|
774
1041
|
fragment += " <" + label + ">"
|
|
775
|
-
return fragment
|
|
1042
|
+
return fragment, paragraphs
|
|
776
1043
|
|
|
777
1044
|
|
|
778
1045
|
def _is_block_start(line: str) -> bool:
|
|
@@ -789,6 +1056,9 @@ def _is_block_start(line: str) -> bool:
|
|
|
789
1056
|
or (stripped.startswith("|") and stripped.endswith("|"))
|
|
790
1057
|
or _IMAGE_RE.match(stripped)
|
|
791
1058
|
or _is_marker_start(stripped)
|
|
1059
|
+
or _UNKNOWN_MARKER_RE.match(stripped)
|
|
1060
|
+
or stripped.lower().startswith("<details")
|
|
1061
|
+
or stripped.lower().startswith("</details")
|
|
792
1062
|
)
|
|
793
1063
|
|
|
794
1064
|
|
|
@@ -803,8 +1073,12 @@ def _collect_refs(lines: Sequence[str]) -> Dict[str, str]:
|
|
|
803
1073
|
sub = 0
|
|
804
1074
|
counts: Dict[str, int] = {}
|
|
805
1075
|
|
|
806
|
-
|
|
1076
|
+
index = 0
|
|
1077
|
+
total = len(lines)
|
|
1078
|
+
while index < total:
|
|
1079
|
+
raw = lines[index]
|
|
807
1080
|
stripped = raw.strip()
|
|
1081
|
+
index += 1
|
|
808
1082
|
if not stripped:
|
|
809
1083
|
continue
|
|
810
1084
|
heading = _HEADING_RE.match(stripped)
|
|
@@ -834,9 +1108,14 @@ def _collect_refs(lines: Sequence[str]) -> Dict[str, str]:
|
|
|
834
1108
|
call, _shape = MARKERS[name]
|
|
835
1109
|
if call not in _KNOT_CALLS:
|
|
836
1110
|
continue
|
|
1111
|
+
# 与 _render_body 用同一个收集器:框可以跨段,<label> 也可能写在
|
|
1112
|
+
# 最后一段末尾;两处必须同进同退,编号才不会漂。
|
|
1113
|
+
body_lines, index = _collect_marker_body(
|
|
1114
|
+
lines, index, marker.group(2), _absorbs_blocks(name), name == "证明"
|
|
1115
|
+
)
|
|
837
1116
|
counts["knot"] = counts.get("knot", 0) + 1
|
|
838
1117
|
number = (str(section) + "." if section else "") + str(counts["knot"])
|
|
839
|
-
|
|
1118
|
+
_body, label = _extract_block_label(body_lines)
|
|
840
1119
|
if label:
|
|
841
1120
|
refs[label] = number
|
|
842
1121
|
return refs
|
|
@@ -859,6 +1138,7 @@ def _render_body(
|
|
|
859
1138
|
counts: Dict[str, int] = {}
|
|
860
1139
|
section_name = ""
|
|
861
1140
|
boxes_by_section: Dict[str, int] = {}
|
|
1141
|
+
question_count = 0
|
|
862
1142
|
|
|
863
1143
|
def count(name: str, amount: int = 1) -> None:
|
|
864
1144
|
blocks[name] = blocks.get(name, 0) + amount
|
|
@@ -902,35 +1182,79 @@ def _render_body(
|
|
|
902
1182
|
marker = _MARKER_BLOCK_RE.match(stripped)
|
|
903
1183
|
if marker and marker.group(1) in MARKERS:
|
|
904
1184
|
name = marker.group(1)
|
|
905
|
-
body_lines =
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
if (
|
|
910
|
-
not candidate
|
|
911
|
-
or _HEADING_RE.match(candidate)
|
|
912
|
-
or _is_marker_start(candidate)
|
|
913
|
-
or candidate.startswith("$$")
|
|
914
|
-
or _LIST_RE.match(lines[index])
|
|
915
|
-
or candidate.startswith("|")
|
|
916
|
-
or _FENCE_RE.match(candidate)
|
|
917
|
-
):
|
|
918
|
-
break
|
|
919
|
-
body_lines.append(candidate)
|
|
920
|
-
index += 1
|
|
921
|
-
body = _join_paragraph(body_lines).strip()
|
|
922
|
-
call, shape = MARKERS[name]
|
|
1185
|
+
body_lines, index = _collect_marker_body(
|
|
1186
|
+
lines, index + 1, marker.group(2), _absorbs_blocks(name), name == "证明"
|
|
1187
|
+
)
|
|
1188
|
+
call, _shape = MARKERS[name]
|
|
923
1189
|
number = ""
|
|
924
1190
|
if call in _KNOT_CALLS:
|
|
925
1191
|
counts["knot"] = counts.get("knot", 0) + 1
|
|
926
1192
|
number = (str(section) + "." if section else "") + str(counts["knot"])
|
|
927
1193
|
boxes_by_section[section_name] = boxes_by_section.get(section_name, 0) + 1
|
|
928
|
-
|
|
929
|
-
|
|
1194
|
+
fragment, inner_paragraphs = _render_marker_block(
|
|
1195
|
+
name, body_lines, number, warnings, image_resolver, refs
|
|
930
1196
|
)
|
|
1197
|
+
out.append(fragment)
|
|
1198
|
+
if inner_paragraphs:
|
|
1199
|
+
# 块内段落也算进「方框:正文」的分母:内容搬进装置之后,
|
|
1200
|
+
# 分母不能凭空变小,否则比例检查会把正常的讲义判成框框滥用。
|
|
1201
|
+
count("paragraph", inner_paragraphs)
|
|
931
1202
|
count(call or name)
|
|
932
1203
|
continue
|
|
933
1204
|
|
|
1205
|
+
# 未知的中文标记(`[推导] …`):推导按旧规范的 Proof 排(斜体 Proof. +
|
|
1206
|
+
# 块末 qed,跨段、不套框);其余未知标记按加粗小标题兜底。
|
|
1207
|
+
unknown = _UNKNOWN_MARKER_RE.match(stripped)
|
|
1208
|
+
if unknown:
|
|
1209
|
+
if unknown.group(1) == "推导":
|
|
1210
|
+
body_lines, index = _collect_marker_body(
|
|
1211
|
+
lines, index + 1, unknown.group(2), True, True
|
|
1212
|
+
)
|
|
1213
|
+
fragment, inner_paragraphs = _render_marker_block(
|
|
1214
|
+
"证明", body_lines, "", warnings, image_resolver, refs
|
|
1215
|
+
)
|
|
1216
|
+
out.append(fragment)
|
|
1217
|
+
if inner_paragraphs:
|
|
1218
|
+
count("paragraph", inner_paragraphs)
|
|
1219
|
+
count("proof")
|
|
1220
|
+
continue
|
|
1221
|
+
lead = "**" + unknown.group(1) + "**"
|
|
1222
|
+
if unknown.group(2):
|
|
1223
|
+
lead += " " + unknown.group(2)
|
|
1224
|
+
out.append(_paragraph(lead, warnings, image_resolver, refs))
|
|
1225
|
+
count("paragraph")
|
|
1226
|
+
index += 1
|
|
1227
|
+
continue
|
|
1228
|
+
|
|
1229
|
+
# 自测题的答案块:`<details><summary>答案</summary>…</details>`。
|
|
1230
|
+
# 题干已在上面的段落分支里套成 `#selftest` 琥珀框;答案排在框外,
|
|
1231
|
+
# 用 `#answer`(左侧淡灰细线 + 标签)与题目分开。
|
|
1232
|
+
if stripped.lower().startswith("<details"):
|
|
1233
|
+
index += 1
|
|
1234
|
+
label = "答案"
|
|
1235
|
+
content: List[str] = []
|
|
1236
|
+
while index < total:
|
|
1237
|
+
candidate = lines[index]
|
|
1238
|
+
text_line = candidate.strip()
|
|
1239
|
+
if text_line.lower().startswith("</details"):
|
|
1240
|
+
index += 1
|
|
1241
|
+
break
|
|
1242
|
+
summary = _SUMMARY_LINE_RE.search(text_line)
|
|
1243
|
+
if summary:
|
|
1244
|
+
label = summary.group(1).strip() or label
|
|
1245
|
+
index += 1
|
|
1246
|
+
continue
|
|
1247
|
+
content.append(candidate)
|
|
1248
|
+
index += 1
|
|
1249
|
+
content_typst, inner = _render_block_sequence(
|
|
1250
|
+
content, warnings, image_resolver, refs
|
|
1251
|
+
)
|
|
1252
|
+
out.append("#answer(" + _json_string(label) + ")[" + content_typst + "]")
|
|
1253
|
+
count("answer")
|
|
1254
|
+
if inner:
|
|
1255
|
+
count("paragraph", inner)
|
|
1256
|
+
continue
|
|
1257
|
+
|
|
934
1258
|
fence = _FENCE_RE.match(stripped)
|
|
935
1259
|
if fence:
|
|
936
1260
|
marker_text = fence.group(1)
|
|
@@ -947,22 +1271,8 @@ def _render_body(
|
|
|
947
1271
|
continue
|
|
948
1272
|
|
|
949
1273
|
if stripped.startswith("$$"):
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
if "$$" in body[0]:
|
|
953
|
-
inner = body[0].split("$$")[0]
|
|
954
|
-
else:
|
|
955
|
-
while index < total:
|
|
956
|
-
line = lines[index].strip()
|
|
957
|
-
index += 1
|
|
958
|
-
if "$$" in line:
|
|
959
|
-
body.append(line.split("$$")[0])
|
|
960
|
-
break
|
|
961
|
-
body.append(line)
|
|
962
|
-
inner = "\n".join(body)
|
|
963
|
-
converted, issues = latex_to_typst(inner.strip())
|
|
964
|
-
warnings.extend(issues)
|
|
965
|
-
out.append("$ " + converted.strip() + " $")
|
|
1274
|
+
math, index = _read_display_math(lines, index, warnings)
|
|
1275
|
+
out.append(math)
|
|
966
1276
|
count("equation")
|
|
967
1277
|
continue
|
|
968
1278
|
|
|
@@ -1036,7 +1346,28 @@ def _render_body(
|
|
|
1036
1346
|
while index < total and not _is_block_start(lines[index]):
|
|
1037
1347
|
paragraph.append(lines[index])
|
|
1038
1348
|
index += 1
|
|
1039
|
-
|
|
1349
|
+
text = _join_paragraph(paragraph)
|
|
1350
|
+
# 紧跟 `<details>` 的段落是自测题题干:套进与「例」同款的琥珀方框,
|
|
1351
|
+
# 答案就会排在框外,题目与答案之间有一道清楚的边界。
|
|
1352
|
+
probe = index
|
|
1353
|
+
while probe < total and not lines[probe].strip():
|
|
1354
|
+
probe += 1
|
|
1355
|
+
if probe < total and lines[probe].strip().lower().startswith("<details"):
|
|
1356
|
+
number, stem = split_question_number(text)
|
|
1357
|
+
if number:
|
|
1358
|
+
question_count = max(question_count, int(number))
|
|
1359
|
+
else:
|
|
1360
|
+
question_count += 1
|
|
1361
|
+
number = str(question_count)
|
|
1362
|
+
out.append(
|
|
1363
|
+
"#selftest(" + number + ")["
|
|
1364
|
+
+ _render_rich_text(stem, warnings, image_resolver, refs)
|
|
1365
|
+
+ "]"
|
|
1366
|
+
)
|
|
1367
|
+
count("selftest")
|
|
1368
|
+
count("paragraph")
|
|
1369
|
+
continue
|
|
1370
|
+
out.append(_paragraph(text, warnings, image_resolver, refs))
|
|
1040
1371
|
count("paragraph")
|
|
1041
1372
|
|
|
1042
1373
|
for name, boxes in boxes_by_section.items():
|
|
@@ -1150,9 +1481,8 @@ def render_handout(
|
|
|
1150
1481
|
|
|
1151
1482
|
warnings: List[str] = []
|
|
1152
1483
|
cleaned = _HTML_COMMENT_RE.sub("", markdown.replace("\r\n", "\n"))
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
cleaned = _DETAILS_CLOSE_RE.sub("", cleaned)
|
|
1484
|
+
# `<details>` / `<summary>` 不再预先摊平:自测题的题干与答案要分别排成
|
|
1485
|
+
# `#selftest`(琥珀框)与 `#answer`(框外、灰色左线),见 _render_body。
|
|
1156
1486
|
|
|
1157
1487
|
body_lines, fields = _extract_cover(
|
|
1158
1488
|
cleaned, title=title, subtitle=subtitle, author=author, date=date, kicker=kicker
|
|
@@ -117,14 +117,14 @@
|
|
|
117
117
|
// 标题后的间距比 2.2.1 略大:小节标题与正文之间留出呼吸,
|
|
118
118
|
// 读者一眼能看出「新的一节从这里开始」(规范见 typography-spec.md §2)。
|
|
119
119
|
#show heading: set text(font: fonts.heading)
|
|
120
|
-
#show heading.where(level: 1): it => block(width: 100%, above:
|
|
120
|
+
#show heading.where(level: 1): it => block(width: 100%, above: 24pt, below: 12pt)[
|
|
121
121
|
#text(size: 15pt, weight: "bold", fill: palette.muted)[#counter(heading).display()]
|
|
122
122
|
#h(0.7em)
|
|
123
123
|
#text(size: 15pt, weight: "bold", fill: palette.thm)[#it.body]
|
|
124
124
|
#v(1pt)
|
|
125
125
|
#line(length: 100%, stroke: 1.1pt + palette.rule)
|
|
126
126
|
]
|
|
127
|
-
#show heading.where(level: 2): it => block(above:
|
|
127
|
+
#show heading.where(level: 2): it => block(above: 22pt, below: 0.85em)[
|
|
128
128
|
#text(size: 12.5pt, weight: "bold", fill: palette.def)[#counter(heading).display() #it.body]
|
|
129
129
|
]
|
|
130
130
|
#show heading.where(level: 3): it => block(above: 9pt, below: 0.65em)[
|
|
@@ -215,6 +215,39 @@
|
|
|
215
215
|
},
|
|
216
216
|
)
|
|
217
217
|
|
|
218
|
+
// 自测题:题干复用「例」的琥珀方框;答案排在框外(淡灰左线 + 「答案」标签),
|
|
219
|
+
// 题目与答案之间因此有一道清楚的边界。渲染器把 `<details>` 块映射成这两个装置。
|
|
220
|
+
#let selftest(number, body) = block(
|
|
221
|
+
width: 100%,
|
|
222
|
+
breakable: true,
|
|
223
|
+
fill: tint(palette.eg),
|
|
224
|
+
stroke: (left: 2pt + palette.eg),
|
|
225
|
+
inset: (left: 11pt, right: 10pt, top: 7pt, bottom: 7pt),
|
|
226
|
+
above: 14pt,
|
|
227
|
+
below: 2pt,
|
|
228
|
+
{
|
|
229
|
+
set align(left)
|
|
230
|
+
text(font: fonts.sans, weight: "bold", size: 0.92em, fill: palette.eg)[自测题 #number]
|
|
231
|
+
h(0.4em)
|
|
232
|
+
body
|
|
233
|
+
},
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
#let answer(label, body) = block(
|
|
237
|
+
width: 100%,
|
|
238
|
+
breakable: true,
|
|
239
|
+
inset: (left: 12pt, right: 10pt),
|
|
240
|
+
stroke: (left: 1.2pt + palette.hairline),
|
|
241
|
+
above: 4pt,
|
|
242
|
+
below: 16pt,
|
|
243
|
+
{
|
|
244
|
+
set align(left)
|
|
245
|
+
text(font: fonts.sans, weight: "bold", size: 0.9em, fill: palette.muted)[#label]
|
|
246
|
+
v(0.25em)
|
|
247
|
+
body
|
|
248
|
+
},
|
|
249
|
+
)
|
|
250
|
+
|
|
218
251
|
// 证明:不套框,只给斜体 Proof. 与行末的 qed 方块。
|
|
219
252
|
// qed 用 box(rect(...)) 而不是裸 rect:rect 是块级元素,会另起一行;
|
|
220
253
|
// 填空笔记链路的 mark() 也是 box,两条链路的方块才会都落在行末。
|
|
@@ -265,6 +298,18 @@
|
|
|
265
298
|
#let accent(body) = text(weight: "bold", fill: palette.thm)[#body]
|
|
266
299
|
#let warn(body) = text(weight: "bold", fill: palette.warn)[#body]
|
|
267
300
|
#let aside(body) = text(size: 0.9em, fill: palette.muted)[#body]
|
|
301
|
+
// 重点:蓝色文字段落(不是方框)。用于 `> [!IMPORTANT]`:块级容器只提供
|
|
302
|
+
// 段距与首行缩进,没有底色 / 竖线,读起来仍是正文。
|
|
303
|
+
#let keypoint(body) = block(
|
|
304
|
+
width: 100%,
|
|
305
|
+
above: 6pt,
|
|
306
|
+
below: 6pt,
|
|
307
|
+
{
|
|
308
|
+
set text(fill: palette.thm)
|
|
309
|
+
h(2em)
|
|
310
|
+
body
|
|
311
|
+
},
|
|
312
|
+
)
|
|
268
313
|
#let gap(hint) = text(font: fonts.sans, size: 0.92em, fill: palette.eg)[[ fill in: #hint ]]
|
|
269
314
|
#let fillin(width: 2.2cm) = box(
|
|
270
315
|
width: width,
|
package/zju_lecture/note_lint.py
CHANGED
|
@@ -20,6 +20,8 @@ import tempfile
|
|
|
20
20
|
import time
|
|
21
21
|
from typing import List, NamedTuple
|
|
22
22
|
|
|
23
|
+
from .study_notes import MARKERS, _UNKNOWN_MARKER_RE
|
|
24
|
+
|
|
23
25
|
ERROR = "error"
|
|
24
26
|
WARN = "warn"
|
|
25
27
|
|
|
@@ -206,6 +208,16 @@ def check_markdown(text: str) -> List[Issue]:
|
|
|
206
208
|
_excerpt(stripped),
|
|
207
209
|
))
|
|
208
210
|
|
|
211
|
+
unknown = _UNKNOWN_MARKER_RE.match(probe.strip())
|
|
212
|
+
if unknown and unknown.group(1) not in MARKERS:
|
|
213
|
+
issues.append(Issue(
|
|
214
|
+
idx, WARN, "unknown_marker",
|
|
215
|
+
f"未知标记 `[{unknown.group(1)}]`,PDF 里只会排成加粗小标题",
|
|
216
|
+
"换成已支持的标记(`[定义]` / `[定理]` / `[证明]` / `[例]` / `[直觉]` / "
|
|
217
|
+
"`[强调]` / `[弱注]` 等),或去掉方括号写成普通段落。",
|
|
218
|
+
_excerpt(stripped),
|
|
219
|
+
))
|
|
220
|
+
|
|
209
221
|
|
|
210
222
|
# Per-formula checks.
|
|
211
223
|
for offset, body in _iter_inline_math(probe):
|