Add math stdlib with formulas/plots and polish the docs view.

Ship Num/Formula runtime, bilingual math libs, SVG plots with axes/grid, and view UX for collapsible folders plus centered plots.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-08-05 11:30:47 +08:00
1 parent a53ebb65ee
commit dcd0cdb8f7
40 files changed
+3553 -276

No files matched your search

+39 -14
View File
@@ -36,7 +36,7 @@ pub struct ClassifiedLine {
fn is_code_starter(c: char) -> bool {
matches!(
c,
'#' | '*' | '>' | '+' | '-' | '`' | '|' | '~'
'#' | '*' | '>' | '+' | '-' | '`' | '|' | '~' | '$'
) || c.is_ascii_digit()
}
@@ -72,26 +72,40 @@ pub fn classify_source(source: &str) -> Vec<ClassifiedLine> {
let mut out = Vec::with_capacity(lines.len());
let mut in_comment_paragraph = false;
let mut in_math_fence = false;
for (i, text) in lines.into_iter().enumerate() {
let base = classify_line(text);
let trimmed = text.trim();
let structural = is_structural_code_line(trimmed);
let kind = match base {
LineKind::Blank => {
in_comment_paragraph = false;
LineKind::Blank
let kind = if in_math_fence {
if trimmed == "$$" {
in_math_fence = false;
}
LineKind::Comment => {
in_comment_paragraph = true;
LineKind::Comment
LineKind::Code
} else {
match base {
LineKind::Blank => {
in_comment_paragraph = false;
LineKind::Blank
}
LineKind::Comment => {
in_comment_paragraph = true;
LineKind::Comment
}
LineKind::Code if structural => {
in_comment_paragraph = false;
LineKind::Code
}
LineKind::Code if in_comment_paragraph => LineKind::Comment,
LineKind::Code => {
// Multi-line math fence opener (not same-line `$$…$$`).
if trimmed == "$$" {
in_math_fence = true;
}
LineKind::Code
}
}
LineKind::Code if structural => {
in_comment_paragraph = false;
LineKind::Code
}
LineKind::Code if in_comment_paragraph => LineKind::Comment,
LineKind::Code => LineKind::Code,
};
out.push(ClassifiedLine {
line_no: (i + 1) as u32,
@@ -186,4 +200,15 @@ mod tests {
assert!(lines.iter().any(|l| l.kind == LineKind::Comment));
assert!(lines.iter().any(|l| l.kind == LineKind::Code));
}
#[test]
fn math_fence_body_stays_code() {
let lines = classify_source("`f` =\n$$\nx^2 - 2\n$$\n");
assert!(
lines
.iter()
.all(|l| l.kind == LineKind::Code || l.kind == LineKind::Blank),
"expected fence body as Code, got {lines:?}"
);
}
}