typography and documents: formula and diagram SVG for export; a diagram label without a font is an error
CI / platforms (windows-latest) (push) Failing after 8s
CI / site (push) Successful in 22s
CI / crate (push) Failing after 12m32s
CI / platforms (ubuntu-24.04) (push) Canceled after 0s

This commit is contained in:
ZacharyZhang-NY committed 2026-10-12 09:56:38 -04:00
1 parent 7ed4ea8323
commit cec9689f26
5 files changed
+100 -3

No files matched your search

+12
View File
@@ -116,6 +116,18 @@ impl Asset for Typesetter {
}
}
/// `source` as black outlined SVG, for export.
pub fn formula_svg(source: &str, display: bool) -> Result<String, MathError> {
let formula = Formula {
source: source.to_owned().into(),
display,
rgba: 0x0000_00ff,
font: 1600,
scale: 100,
};
svg(&formula).map(|(svg, _)| svg)
}
/// The formula as outlined SVG holding all ink; its size.
fn svg(formula: &Formula) -> Result<(String, Size<Pixels>), MathError> {
let ast = parsed(&formula.source)?;
+8
View File
@@ -177,3 +177,11 @@ fn a_shared_formula_stays_until_its_last_holder_leaves(cx: &mut gpui::TestAppCon
flush(cx);
assert!(!cached("c^2", cx), "the last holder freed it");
}
#[test]
fn an_exported_formula_is_black_outlines() {
let svg = formula_svg(r"\sqrt{x}", true).expect("typesets");
assert!(svg.starts_with("<svg") && !svg.contains("<text"), "{svg}");
assert!(svg.contains("0,0,0"), "black: {svg}");
assert!(formula_svg(r"\frac{", false).is_err());
}
+1 -1
View File
@@ -26,7 +26,7 @@ pub use formatted::{
pub use inline::{Blockquote, Code, Highlight, Kbd, KbdCombo};
pub use link::{ExternalLink, Link};
pub(crate) use math::failed;
pub use math::{Latex, MathError};
pub use math::{Latex, MathError, formula_svg};
pub use rolling::AnimatedNumber;
pub use select::SelectableText;
pub use text::{Caption, Heading, Label, Overline, Paragraph, Subtitle, Title, literal, tabular};