Skip to content

Commit cfdd423

Browse files
committed
New docs infrastructure
1 parent f7aa0c3 commit cfdd423

18 files changed

Lines changed: 1868 additions & 60 deletions

File tree

‎.cargo/config.toml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@
55
# different commit if test artifacts need to be regenerated to create the test
66
# report.
77
testit = "run --quiet --package=test-wrapper --"
8+
9+
# Runs the documentation generator.
10+
#
11+
# We use the `dev-fast` profile as a reasonable trade-off between Rust and Typst
12+
# compilation speed. Just `dev` makes the Typst compilation very slow, while
13+
# `release` makes the Rust compilation very slow.
14+
docit = "run --profile dev-fast --package=typst-docs --"

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ tests/fuzz/artifacts
1414
tests/fuzz/coverage
1515
tarpaulin-report.html
1616

17+
docs/dist
18+
1719
# Rust
1820
/target
1921
**/*.rs.bk

‎Cargo.lock‎

Lines changed: 90 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ typst-cli = { path = "crates/typst-cli", version = "0.14.2" }
2222
typst-eval = { path = "crates/typst-eval", version = "0.14.2" }
2323
typst-html = { path = "crates/typst-html", version = "0.14.2" }
2424
typst-ide = { path = "crates/typst-ide", version = "0.14.2" }
25-
typst-kit = { path = "crates/typst-kit", version = "0.14.2" }
25+
typst-kit = { path = "crates/typst-kit", version = "0.14.2", default-features = false }
2626
typst-layout = { path = "crates/typst-layout", version = "0.14.2" }
2727
typst-library = { path = "crates/typst-library", version = "0.14.2" }
2828
typst-macros = { path = "crates/typst-macros", version = "0.14.2" }
@@ -99,7 +99,6 @@ pixglyph = "0.6"
9999
png = "0.17"
100100
portable-atomic = "1.6"
101101
proc-macro2 = "1"
102-
pulldown-cmark = "0.9"
103102
quote = "1"
104103
rayon = "1.7.0"
105104
regex = "1"
@@ -134,6 +133,7 @@ toml = { version = "0.8", default-features = false, features = ["parse", "displa
134133
ttf-parser = "0.25.0"
135134
two-face = { version = "0.4.3", default-features = false, features = ["syntect-fancy"] }
136135
typed-arena = "2"
136+
unicode_names2 = "1"
137137
unicode-bidi = "0.3.18"
138138
unicode-ident = "1.0"
139139
unicode-math-class = "0.1"
@@ -155,6 +155,10 @@ zip = { version = "5", default-features = false, features = ["deflate"] }
155155
[profile.dev.package."*"]
156156
opt-level = 2
157157

158+
[profile.dev-fast]
159+
inherits = "dev"
160+
opt-level = 2
161+
158162
[profile.release]
159163
lto = "thin"
160164
codegen-units = 1

‎crates/typst-html/src/rules.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ const TERMS_RULE: ShowFn<TermsElem> = |elem, _, styles| {
163163
))
164164
};
165165

166+
// Also check `PATCHED_LINK_RULE` in `docs/src/main.rs` when editing this.
166167
const LINK_RULE: ShowFn<LinkElem> = |elem, engine, _| {
167168
let span = elem.span();
168169
let dest = elem.dest.resolve_early(engine, span)?;
@@ -759,6 +760,7 @@ pub fn html_span_filled(content: Content, color: Color) -> Content {
759760

760761
const RAW_LINE_RULE: ShowFn<RawLine> = |elem, _, _| Ok(elem.body.clone());
761762

763+
// Also check `PATCHED_IMAGE_RULE` in `docs/src/main.rs` when editing this.
762764
const IMAGE_RULE: ShowFn<ImageElem> = |elem, engine, styles| {
763765
let image = elem.decode(engine, styles)?;
764766

‎crates/typst-library/src/layout/frame.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ impl Frame {
218218
}
219219
}
220220

221+
/// Filters out items in the frame in-place.
222+
pub fn retain(&mut self, mut filter: impl FnMut(&mut FrameItem) -> bool) {
223+
Arc::make_mut(&mut self.items).retain_mut(|(_, item)| filter(item));
224+
}
225+
221226
/// Whether the given frame should be inlined.
222227
fn should_inline(&self, frame: &Frame) -> bool {
223228
// We do not inline big frames and hard frames.
@@ -318,7 +323,7 @@ impl Frame {
318323

319324
/// Hide all content in the frame, but keep metadata.
320325
pub fn hide(&mut self) {
321-
Arc::make_mut(&mut self.items).retain_mut(|(_, item)| match item {
326+
self.retain(|item| match item {
322327
FrameItem::Group(group) => {
323328
group.frame.hide();
324329
!group.frame.is_empty()

‎crates/typst-library/src/text/font/mod.rs‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ impl Font {
129129
.map(|units| self.to_em(units))
130130
}
131131

132-
/// Lookup a name by id.
133-
pub fn find_name(&self, id: u16) -> Option<String> {
134-
find_name(&self.0.ttf, id)
132+
/// Determine the font's PostScript name.
133+
pub fn post_script_name(&self) -> Option<String> {
134+
find_name(&self.0.ttf, name_id::POST_SCRIPT_NAME)
135135
}
136136

137137
/// A reference to the underlying `ttf-parser` face.
@@ -310,10 +310,8 @@ impl FontMetrics {
310310
.and_then(|id| ttf.glyph_hor_advance(id).map(|units| font.to_em(units)))
311311
.unwrap_or(typst_library::math::THICK);
312312

313-
let is_cambria = || {
314-
font.find_name(name_id::POST_SCRIPT_NAME)
315-
.is_some_and(|name| name == "CambriaMath")
316-
};
313+
let is_cambria =
314+
|| font.post_script_name().is_some_and(|name| name == "CambriaMath");
317315

318316
Box::new(
319317
ttf.tables()

‎crates/typst-library/src/text/raw.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ impl PlainText for Packed<RawElem> {
523523
}
524524
}
525525

526+
cast! {
527+
RawElem,
528+
v: Content => v.unpack::<Self>().map_err(|_| "expected raw text")?
529+
}
530+
526531
/// The content of the raw text.
527532
#[derive(Debug, Clone, Hash)]
528533
pub enum RawContent {

‎crates/typst-syntax/src/source.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ impl Source {
4747
)
4848
}
4949

50+
/// Create a new source file with an already created syntax tree.
51+
pub fn with_root(id: FileId, text: String, root: SyntaxNode) -> Self {
52+
Self(Arc::new(LazyHash::new(SourceInner { id, lines: Lines::new(text), root })))
53+
}
54+
5055
/// The root node of the file's untyped syntax tree.
5156
pub fn root(&self) -> &SyntaxNode {
5257
&self.0.root

0 commit comments

Comments
 (0)