mirror of
https://github.com/typst/typst
synced 2025-08-13 14:47:54 +08:00
Compare commits
8 Commits
913f673e29
...
191f3a05a9
Author | SHA1 | Date | |
---|---|---|---|
|
191f3a05a9 | ||
|
7897e86bcc | ||
|
8e0e0f1a3b | ||
|
0a4b72f8f6 | ||
|
25ad4f7d41 | ||
|
c4d7faf527 | ||
|
ec3c058220 | ||
|
a3c2489eb6 |
17
Cargo.lock
generated
17
Cargo.lock
generated
@ -748,9 +748,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flate2"
|
name = "flate2"
|
||||||
version = "1.1.0"
|
version = "1.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "11faaf5a5236997af9848be0bef4db95824b1d534ebc64d0f0c6cf3e67bd38dc"
|
checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"libz-rs-sys",
|
"libz-rs-sys",
|
||||||
@ -1469,9 +1469,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libz-rs-sys"
|
name = "libz-rs-sys"
|
||||||
version = "0.4.2"
|
version = "0.5.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "902bc563b5d65ad9bba616b490842ef0651066a1a1dc3ce1087113ffcb873c8d"
|
checksum = "172a788537a2221661b480fee8dc5f96c580eb34fa88764d3205dc356c7e4221"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zlib-rs",
|
"zlib-rs",
|
||||||
]
|
]
|
||||||
@ -3932,13 +3932,12 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zip"
|
name = "zip"
|
||||||
version = "2.5.0"
|
version = "4.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "27c03817464f64e23f6f37574b4fdc8cf65925b5bfd2b0f2aedf959791941f88"
|
checksum = "9aed4ac33e8eb078c89e6cbb1d5c4c7703ec6d299fc3e7c3695af8f8b423468b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arbitrary",
|
"arbitrary",
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"crossbeam-utils",
|
|
||||||
"flate2",
|
"flate2",
|
||||||
"indexmap 2.7.1",
|
"indexmap 2.7.1",
|
||||||
"memchr",
|
"memchr",
|
||||||
@ -3947,9 +3946,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zlib-rs"
|
name = "zlib-rs"
|
||||||
version = "0.4.2"
|
version = "0.5.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8b20717f0917c908dc63de2e44e97f1e6b126ca58d0e391cee86d504eb8fbd05"
|
checksum = "626bd9fa9734751fc50d6060752170984d7053f5a39061f524cda68023d4db8a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zopfli"
|
name = "zopfli"
|
||||||
|
@ -143,7 +143,7 @@ xmlparser = "0.13.5"
|
|||||||
xmlwriter = "0.1.0"
|
xmlwriter = "0.1.0"
|
||||||
xz2 = { version = "0.1", features = ["static"] }
|
xz2 = { version = "0.1", features = ["static"] }
|
||||||
yaml-front-matter = "0.1"
|
yaml-front-matter = "0.1"
|
||||||
zip = { version = "2.5", default-features = false, features = ["deflate"] }
|
zip = { version = "4.3", default-features = false, features = ["deflate"] }
|
||||||
|
|
||||||
[profile.dev.package."*"]
|
[profile.dev.package."*"]
|
||||||
opt-level = 2
|
opt-level = 2
|
||||||
|
@ -59,19 +59,11 @@ pub fn register(rules: &mut NativeRuleMap) {
|
|||||||
rules.register::<FrameElem>(Paged, |elem, _, _| Ok(elem.body.clone()));
|
rules.register::<FrameElem>(Paged, |elem, _, _| Ok(elem.body.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
const STRONG_RULE: ShowFn<StrongElem> = |elem, _, _| {
|
const STRONG_RULE: ShowFn<StrongElem> =
|
||||||
Ok(HtmlElem::new(tag::strong)
|
|elem, _, _| Ok(HtmlElem::new(tag::strong).with_body(Some(elem.body.clone())).pack());
|
||||||
.with_body(Some(elem.body.clone()))
|
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
|
||||||
|
|
||||||
const EMPH_RULE: ShowFn<EmphElem> = |elem, _, _| {
|
const EMPH_RULE: ShowFn<EmphElem> =
|
||||||
Ok(HtmlElem::new(tag::em)
|
|elem, _, _| Ok(HtmlElem::new(tag::em).with_body(Some(elem.body.clone())).pack());
|
||||||
.with_body(Some(elem.body.clone()))
|
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
|
||||||
|
|
||||||
const LIST_RULE: ShowFn<ListElem> = |elem, _, styles| {
|
const LIST_RULE: ShowFn<ListElem> = |elem, _, styles| {
|
||||||
Ok(HtmlElem::new(tag::ul)
|
Ok(HtmlElem::new(tag::ul)
|
||||||
@ -86,8 +78,7 @@ const LIST_RULE: ShowFn<ListElem> = |elem, _, styles| {
|
|||||||
.pack()
|
.pack()
|
||||||
.spanned(item.span())
|
.spanned(item.span())
|
||||||
}))))
|
}))))
|
||||||
.pack()
|
.pack())
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const ENUM_RULE: ShowFn<EnumElem> = |elem, _, styles| {
|
const ENUM_RULE: ShowFn<EnumElem> = |elem, _, styles| {
|
||||||
@ -114,7 +105,7 @@ const ENUM_RULE: ShowFn<EnumElem> = |elem, _, styles| {
|
|||||||
li.with_body(Some(body)).pack().spanned(item.span())
|
li.with_body(Some(body)).pack().spanned(item.span())
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Ok(ol.with_body(Some(body)).pack().spanned(elem.span()))
|
Ok(ol.with_body(Some(body)).pack())
|
||||||
};
|
};
|
||||||
|
|
||||||
const TERMS_RULE: ShowFn<TermsElem> = |elem, _, styles| {
|
const TERMS_RULE: ShowFn<TermsElem> = |elem, _, styles| {
|
||||||
@ -166,8 +157,7 @@ const LINK_RULE: ShowFn<LinkElem> = |elem, engine, _| {
|
|||||||
Ok(HtmlElem::new(tag::a)
|
Ok(HtmlElem::new(tag::a)
|
||||||
.with_optional_attr(attr::href, href)
|
.with_optional_attr(attr::href, href)
|
||||||
.with_body(Some(elem.body.clone()))
|
.with_body(Some(elem.body.clone()))
|
||||||
.pack()
|
.pack())
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const HEADING_RULE: ShowFn<HeadingElem> = |elem, engine, styles| {
|
const HEADING_RULE: ShowFn<HeadingElem> = |elem, engine, styles| {
|
||||||
@ -203,10 +193,9 @@ const HEADING_RULE: ShowFn<HeadingElem> = |elem, engine, styles| {
|
|||||||
.with_attr(attr::role, "heading")
|
.with_attr(attr::role, "heading")
|
||||||
.with_attr(attr::aria_level, eco_format!("{}", level + 1))
|
.with_attr(attr::aria_level, eco_format!("{}", level + 1))
|
||||||
.pack()
|
.pack()
|
||||||
.spanned(span)
|
|
||||||
} else {
|
} else {
|
||||||
let t = [tag::h2, tag::h3, tag::h4, tag::h5, tag::h6][level - 1];
|
let t = [tag::h2, tag::h3, tag::h4, tag::h5, tag::h6][level - 1];
|
||||||
HtmlElem::new(t).with_body(Some(realized)).pack().spanned(span)
|
HtmlElem::new(t).with_body(Some(realized)).pack()
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -225,17 +214,13 @@ const FIGURE_RULE: ShowFn<FigureElem> = |elem, _, styles| {
|
|||||||
// Ensure that the body is considered a paragraph.
|
// Ensure that the body is considered a paragraph.
|
||||||
realized += ParbreakElem::shared().clone().spanned(span);
|
realized += ParbreakElem::shared().clone().spanned(span);
|
||||||
|
|
||||||
Ok(HtmlElem::new(tag::figure)
|
Ok(HtmlElem::new(tag::figure).with_body(Some(realized)).pack())
|
||||||
.with_body(Some(realized))
|
|
||||||
.pack()
|
|
||||||
.spanned(span))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const FIGURE_CAPTION_RULE: ShowFn<FigureCaption> = |elem, engine, styles| {
|
const FIGURE_CAPTION_RULE: ShowFn<FigureCaption> = |elem, engine, styles| {
|
||||||
Ok(HtmlElem::new(tag::figcaption)
|
Ok(HtmlElem::new(tag::figcaption)
|
||||||
.with_body(Some(elem.realize(engine, styles)?))
|
.with_body(Some(elem.realize(engine, styles)?))
|
||||||
.pack()
|
.pack())
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const QUOTE_RULE: ShowFn<QuoteElem> = |elem, _, styles| {
|
const QUOTE_RULE: ShowFn<QuoteElem> = |elem, _, styles| {
|
||||||
@ -376,19 +361,11 @@ fn show_cell(tag: HtmlTag, cell: &Cell, styles: StyleChain) -> Content {
|
|||||||
.spanned(cell.span())
|
.spanned(cell.span())
|
||||||
}
|
}
|
||||||
|
|
||||||
const SUB_RULE: ShowFn<SubElem> = |elem, _, _| {
|
const SUB_RULE: ShowFn<SubElem> =
|
||||||
Ok(HtmlElem::new(tag::sub)
|
|elem, _, _| Ok(HtmlElem::new(tag::sub).with_body(Some(elem.body.clone())).pack());
|
||||||
.with_body(Some(elem.body.clone()))
|
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
|
||||||
|
|
||||||
const SUPER_RULE: ShowFn<SuperElem> = |elem, _, _| {
|
const SUPER_RULE: ShowFn<SuperElem> =
|
||||||
Ok(HtmlElem::new(tag::sup)
|
|elem, _, _| Ok(HtmlElem::new(tag::sup).with_body(Some(elem.body.clone())).pack());
|
||||||
.with_body(Some(elem.body.clone()))
|
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
|
||||||
|
|
||||||
const UNDERLINE_RULE: ShowFn<UnderlineElem> = |elem, _, _| {
|
const UNDERLINE_RULE: ShowFn<UnderlineElem> = |elem, _, _| {
|
||||||
// Note: In modern HTML, `<u>` is not the underline element, but
|
// Note: In modern HTML, `<u>` is not the underline element, but
|
||||||
@ -427,8 +404,7 @@ const RAW_RULE: ShowFn<RawElem> = |elem, _, styles| {
|
|||||||
|
|
||||||
Ok(HtmlElem::new(if elem.block.get(styles) { tag::pre } else { tag::code })
|
Ok(HtmlElem::new(if elem.block.get(styles) { tag::pre } else { tag::code })
|
||||||
.with_body(Some(Content::sequence(seq)))
|
.with_body(Some(Content::sequence(seq)))
|
||||||
.pack()
|
.pack())
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const RAW_LINE_RULE: ShowFn<RawLine> = |elem, _, _| Ok(elem.body.clone());
|
const RAW_LINE_RULE: ShowFn<RawLine> = |elem, _, _| Ok(elem.body.clone());
|
||||||
|
@ -272,7 +272,7 @@ const HEADING_RULE: ShowFn<HeadingElem> = |elem, engine, styles| {
|
|||||||
BlockElem::new().with_body(Some(BlockBody::Content(realized)))
|
BlockElem::new().with_body(Some(BlockBody::Content(realized)))
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(block.pack().spanned(span))
|
Ok(block.pack())
|
||||||
};
|
};
|
||||||
|
|
||||||
const FIGURE_RULE: ShowFn<FigureElem> = |elem, _, styles| {
|
const FIGURE_RULE: ShowFn<FigureElem> = |elem, _, styles| {
|
||||||
@ -326,8 +326,7 @@ const FIGURE_RULE: ShowFn<FigureElem> = |elem, _, styles| {
|
|||||||
const FIGURE_CAPTION_RULE: ShowFn<FigureCaption> = |elem, engine, styles| {
|
const FIGURE_CAPTION_RULE: ShowFn<FigureCaption> = |elem, engine, styles| {
|
||||||
Ok(BlockElem::new()
|
Ok(BlockElem::new()
|
||||||
.with_body(Some(BlockBody::Content(elem.realize(engine, styles)?)))
|
.with_body(Some(BlockBody::Content(elem.realize(engine, styles)?)))
|
||||||
.pack()
|
.pack())
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const QUOTE_RULE: ShowFn<QuoteElem> = |elem, _, styles| {
|
const QUOTE_RULE: ShowFn<QuoteElem> = |elem, _, styles| {
|
||||||
@ -550,9 +549,7 @@ const BIBLIOGRAPHY_RULE: ShowFn<BibliographyElem> = |elem, engine, styles| {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const TABLE_RULE: ShowFn<TableElem> = |elem, _, _| {
|
const TABLE_RULE: ShowFn<TableElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::multi_layouter(elem.clone(), crate::grid::layout_table)
|
Ok(BlockElem::multi_layouter(elem.clone(), crate::grid::layout_table).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const TABLE_CELL_RULE: ShowFn<TableCell> = |elem, _, styles| {
|
const TABLE_CELL_RULE: ShowFn<TableCell> = |elem, _, styles| {
|
||||||
@ -703,27 +700,19 @@ const ALIGN_RULE: ShowFn<AlignElem> =
|
|||||||
|elem, _, styles| Ok(elem.body.clone().aligned(elem.alignment.get(styles)));
|
|elem, _, styles| Ok(elem.body.clone().aligned(elem.alignment.get(styles)));
|
||||||
|
|
||||||
const PAD_RULE: ShowFn<PadElem> = |elem, _, _| {
|
const PAD_RULE: ShowFn<PadElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::multi_layouter(elem.clone(), crate::pad::layout_pad)
|
Ok(BlockElem::multi_layouter(elem.clone(), crate::pad::layout_pad).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const COLUMNS_RULE: ShowFn<ColumnsElem> = |elem, _, _| {
|
const COLUMNS_RULE: ShowFn<ColumnsElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::multi_layouter(elem.clone(), crate::flow::layout_columns)
|
Ok(BlockElem::multi_layouter(elem.clone(), crate::flow::layout_columns).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const STACK_RULE: ShowFn<StackElem> = |elem, _, _| {
|
const STACK_RULE: ShowFn<StackElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::multi_layouter(elem.clone(), crate::stack::layout_stack)
|
Ok(BlockElem::multi_layouter(elem.clone(), crate::stack::layout_stack).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const GRID_RULE: ShowFn<GridElem> = |elem, _, _| {
|
const GRID_RULE: ShowFn<GridElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::multi_layouter(elem.clone(), crate::grid::layout_grid)
|
Ok(BlockElem::multi_layouter(elem.clone(), crate::grid::layout_grid).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const GRID_CELL_RULE: ShowFn<GridCell> = |elem, _, styles| {
|
const GRID_CELL_RULE: ShowFn<GridCell> = |elem, _, styles| {
|
||||||
@ -753,33 +742,23 @@ fn show_cell(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const MOVE_RULE: ShowFn<MoveElem> = |elem, _, _| {
|
const MOVE_RULE: ShowFn<MoveElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::transforms::layout_move)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::transforms::layout_move).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const SCALE_RULE: ShowFn<ScaleElem> = |elem, _, _| {
|
const SCALE_RULE: ShowFn<ScaleElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::transforms::layout_scale)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::transforms::layout_scale).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const ROTATE_RULE: ShowFn<RotateElem> = |elem, _, _| {
|
const ROTATE_RULE: ShowFn<RotateElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::transforms::layout_rotate)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::transforms::layout_rotate).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const SKEW_RULE: ShowFn<SkewElem> = |elem, _, _| {
|
const SKEW_RULE: ShowFn<SkewElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::transforms::layout_skew)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::transforms::layout_skew).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const REPEAT_RULE: ShowFn<RepeatElem> = |elem, _, _| {
|
const REPEAT_RULE: ShowFn<RepeatElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::repeat::layout_repeat)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::repeat::layout_repeat).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const HIDE_RULE: ShowFn<HideElem> =
|
const HIDE_RULE: ShowFn<HideElem> =
|
||||||
@ -801,83 +780,66 @@ const LAYOUT_RULE: ShowFn<LayoutElem> = |elem, _, _| {
|
|||||||
crate::flow::layout_fragment(engine, &result, locator, styles, regions)
|
crate::flow::layout_fragment(engine, &result, locator, styles, regions)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.pack()
|
.pack())
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const IMAGE_RULE: ShowFn<ImageElem> = |elem, _, styles| {
|
const IMAGE_RULE: ShowFn<ImageElem> = |elem, _, styles| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::image::layout_image)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::image::layout_image)
|
||||||
.with_width(elem.width.get(styles))
|
.with_width(elem.width.get(styles))
|
||||||
.with_height(elem.height.get(styles))
|
.with_height(elem.height.get(styles))
|
||||||
.pack()
|
.pack())
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const LINE_RULE: ShowFn<LineElem> = |elem, _, _| {
|
const LINE_RULE: ShowFn<LineElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_line)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_line).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const RECT_RULE: ShowFn<RectElem> = |elem, _, styles| {
|
const RECT_RULE: ShowFn<RectElem> = |elem, _, styles| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_rect)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_rect)
|
||||||
.with_width(elem.width.get(styles))
|
.with_width(elem.width.get(styles))
|
||||||
.with_height(elem.height.get(styles))
|
.with_height(elem.height.get(styles))
|
||||||
.pack()
|
.pack())
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const SQUARE_RULE: ShowFn<SquareElem> = |elem, _, styles| {
|
const SQUARE_RULE: ShowFn<SquareElem> = |elem, _, styles| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_square)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_square)
|
||||||
.with_width(elem.width.get(styles))
|
.with_width(elem.width.get(styles))
|
||||||
.with_height(elem.height.get(styles))
|
.with_height(elem.height.get(styles))
|
||||||
.pack()
|
.pack())
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const ELLIPSE_RULE: ShowFn<EllipseElem> = |elem, _, styles| {
|
const ELLIPSE_RULE: ShowFn<EllipseElem> = |elem, _, styles| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_ellipse)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_ellipse)
|
||||||
.with_width(elem.width.get(styles))
|
.with_width(elem.width.get(styles))
|
||||||
.with_height(elem.height.get(styles))
|
.with_height(elem.height.get(styles))
|
||||||
.pack()
|
.pack())
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const CIRCLE_RULE: ShowFn<CircleElem> = |elem, _, styles| {
|
const CIRCLE_RULE: ShowFn<CircleElem> = |elem, _, styles| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_circle)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_circle)
|
||||||
.with_width(elem.width.get(styles))
|
.with_width(elem.width.get(styles))
|
||||||
.with_height(elem.height.get(styles))
|
.with_height(elem.height.get(styles))
|
||||||
.pack()
|
.pack())
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const POLYGON_RULE: ShowFn<PolygonElem> = |elem, _, _| {
|
const POLYGON_RULE: ShowFn<PolygonElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_polygon)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_polygon).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const CURVE_RULE: ShowFn<CurveElem> = |elem, _, _| {
|
const CURVE_RULE: ShowFn<CurveElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_curve)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_curve).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const PATH_RULE: ShowFn<PathElem> = |elem, _, _| {
|
const PATH_RULE: ShowFn<PathElem> = |elem, _, _| {
|
||||||
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_path)
|
Ok(BlockElem::single_layouter(elem.clone(), crate::shapes::layout_path).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const EQUATION_RULE: ShowFn<EquationElem> = |elem, _, styles| {
|
const EQUATION_RULE: ShowFn<EquationElem> = |elem, _, styles| {
|
||||||
if elem.block.get(styles) {
|
if elem.block.get(styles) {
|
||||||
Ok(BlockElem::multi_layouter(elem.clone(), crate::math::layout_equation_block)
|
Ok(BlockElem::multi_layouter(elem.clone(), crate::math::layout_equation_block)
|
||||||
.pack()
|
.pack())
|
||||||
.spanned(elem.span()))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(InlineElem::layouter(elem.clone(), crate::math::layout_equation_inline)
|
Ok(InlineElem::layouter(elem.clone(), crate::math::layout_equation_inline).pack())
|
||||||
.pack()
|
|
||||||
.spanned(elem.span()))
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -31,6 +31,12 @@ use crate::World;
|
|||||||
/// Displays the text verbatim and in a monospace font. This is typically used
|
/// Displays the text verbatim and in a monospace font. This is typically used
|
||||||
/// to embed computer code into your document.
|
/// to embed computer code into your document.
|
||||||
///
|
///
|
||||||
|
/// Note that text given to this element cannot contain arbitrary formatting,
|
||||||
|
/// such as `[*strong*]` or `[_emphasis_]`, as it is displayed verbatim. If
|
||||||
|
/// you'd like to display any kind of content with a monospace font, instead of
|
||||||
|
/// using [`raw`], you should change its font to a monospace font using the
|
||||||
|
/// [`text`]($text) function.
|
||||||
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ````example
|
/// ````example
|
||||||
/// Adding `rbx` to `rcx` gives
|
/// Adding `rbx` to `rcx` gives
|
||||||
@ -57,6 +63,38 @@ use crate::World;
|
|||||||
/// #raw("fn " + "main() {}", lang: "rust")
|
/// #raw("fn " + "main() {}", lang: "rust")
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
/// # Styling
|
||||||
|
/// By default, the `raw` element uses the `DejaVu Sans Mono` font, available
|
||||||
|
/// by default in Typst, with a smaller font size of `0.8em` (that is, 80% of
|
||||||
|
/// the global font size). This is because monospace fonts tend to be visually
|
||||||
|
/// larger than non-monospace fonts.
|
||||||
|
///
|
||||||
|
/// You can customize these properties with show-set rules:
|
||||||
|
///
|
||||||
|
/// ````example
|
||||||
|
/// // Switch to Cascadia Code for
|
||||||
|
/// // both inline and block raw.
|
||||||
|
/// #show raw: set text(font: "Cascadia Code")
|
||||||
|
///
|
||||||
|
/// // Make raw blocks 20% larger than their default size.
|
||||||
|
/// // Keep inline raw at the same size.
|
||||||
|
/// #show raw.where(block: true): set text(1.2em)
|
||||||
|
///
|
||||||
|
/// Now using the `Cascadia Code` font for raw text.
|
||||||
|
/// Here's some Python code. It looks larger now:
|
||||||
|
///
|
||||||
|
/// ```py
|
||||||
|
/// def python():
|
||||||
|
/// return 5 + 5
|
||||||
|
/// ```
|
||||||
|
/// ````
|
||||||
|
///
|
||||||
|
/// In addition, you can customize the syntax highlighting colors by setting
|
||||||
|
/// a custom theme through the [`theme`]($raw.theme) field.
|
||||||
|
///
|
||||||
|
/// For complete customization of the appearance of a raw block, a show rule
|
||||||
|
/// on [`raw.line`]($raw.line) could be helpful, such as to add line numbers.
|
||||||
|
///
|
||||||
/// # Syntax
|
/// # Syntax
|
||||||
/// This function also has dedicated syntax. You can enclose text in 1 or 3+
|
/// This function also has dedicated syntax. You can enclose text in 1 or 3+
|
||||||
/// backticks (`` ` ``) to make it raw. Two backticks produce empty raw text.
|
/// backticks (`` ` ``) to make it raw. Two backticks produce empty raw text.
|
||||||
@ -73,6 +111,10 @@ use crate::World;
|
|||||||
/// needed, start the text with a single space (which will be trimmed) or use
|
/// needed, start the text with a single space (which will be trimmed) or use
|
||||||
/// the single backtick syntax. If your text should start or end with a
|
/// the single backtick syntax. If your text should start or end with a
|
||||||
/// backtick, put a space before or after it (it will be trimmed).
|
/// backtick, put a space before or after it (it will be trimmed).
|
||||||
|
///
|
||||||
|
/// If no syntax highlighting is available by default for your specified
|
||||||
|
/// language tag, you may provide a custom syntax specification file to the
|
||||||
|
/// [`syntaxes`]($raw.syntaxes) field.
|
||||||
#[elem(
|
#[elem(
|
||||||
scope,
|
scope,
|
||||||
title = "Raw Text / Code",
|
title = "Raw Text / Code",
|
||||||
|
@ -374,7 +374,11 @@ fn visit_show_rules<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply a built-in show rule.
|
// Apply a built-in show rule.
|
||||||
ShowStep::Builtin(rule) => rule.apply(&output, s.engine, chained),
|
ShowStep::Builtin(rule) => {
|
||||||
|
let _scope = typst_timing::TimingScope::new(output.elem().name());
|
||||||
|
rule.apply(&output, s.engine, chained)
|
||||||
|
.map(|content| content.spanned(output.span()))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Errors in show rules don't terminate compilation immediately. We just
|
// Errors in show rules don't terminate compilation immediately. We just
|
||||||
|
@ -76,14 +76,16 @@ Here is a list of common markup commands used in LaTeX and their Typst
|
|||||||
equivalents. You can also check out the [full syntax cheat sheet]($syntax).
|
equivalents. You can also check out the [full syntax cheat sheet]($syntax).
|
||||||
|
|
||||||
| Element | LaTeX | Typst | See |
|
| Element | LaTeX | Typst | See |
|
||||||
|:-----------------|:--------------------------|:-----------------------|:-----------|
|
|:-----------------------|:--------------------------|:-----------------------|:-----------|
|
||||||
| Strong emphasis | `\textbf{strong}` | `[*strong*]` | [`strong`] |
|
| Strong emphasis | `\textbf{strong}` | `[*strong*]` | [`strong`] |
|
||||||
| Emphasis | `\emph{emphasis}` | `[_emphasis_]` | [`emph`] |
|
| Emphasis | `\emph{emphasis}` | `[_emphasis_]` | [`emph`] |
|
||||||
| Monospace / code | `\texttt{print(1)}` | ``[`print(1)`]`` | [`raw`] |
|
|
||||||
| Link | `\url{https://typst.app}` | `[https://typst.app/]` | [`link`] |
|
| Link | `\url{https://typst.app}` | `[https://typst.app/]` | [`link`] |
|
||||||
| Label | `\label{intro}` | `[<intro>]` | [`label`] |
|
| Label | `\label{intro}` | `[<intro>]` | [`label`] |
|
||||||
| Reference | `\ref{intro}` | `[@intro]` | [`ref`] |
|
| Reference | `\ref{intro}` | `[@intro]` | [`ref`] |
|
||||||
| Citation | `\cite{humphrey97}` | `[@humphrey97]` | [`cite`] |
|
| Citation | `\cite{humphrey97}` | `[@humphrey97]` | [`cite`] |
|
||||||
|
| Verbatim / code | `\verb|print(f"{x}")|`, `verbatim` / `listing` environments | ``[`print(f"{x}")`]`` | [`raw`] |
|
||||||
|
| Monospace / typewriter | `\texttt{mono}` | ``[`mono`]`` or `text` function | [`raw`], [`text`] |
|
||||||
|
| Verbatim | `verbatim` environment | ``[`#typst-code()`]`` | [`raw`] |
|
||||||
| Bullet list | `itemize` environment | `[- List]` | [`list`] |
|
| Bullet list | `itemize` environment | `[- List]` | [`list`] |
|
||||||
| Numbered list | `enumerate` environment | `[+ List]` | [`enum`] |
|
| Numbered list | `enumerate` environment | `[+ List]` | [`enum`] |
|
||||||
| Term list | `description` environment | `[/ Term: List]` | [`terms`] |
|
| Term list | `description` environment | `[/ Term: List]` | [`terms`] |
|
||||||
@ -121,6 +123,16 @@ To get a [numbered list]($enum) (`enumerate`) instead, use a `+` instead of the
|
|||||||
hyphen. For a [term list]($terms) (`description`), write `[/ Term: Description]`
|
hyphen. For a [term list]($terms) (`description`), write `[/ Term: Description]`
|
||||||
instead.
|
instead.
|
||||||
|
|
||||||
|
Regarding the usage of monospace fonts (also known as "typewriter" font style
|
||||||
|
in LaTeX), it should be noted that using [`raw`] such as in
|
||||||
|
``[`monospace`]`` (where you'd use `\texttt{monospace}` in LaTeX) works for
|
||||||
|
most cases where you only have simple text. If you need to use formatting, such
|
||||||
|
as in `\texttt{monospace \textbf{bold}}`, you will need to replicate its look by
|
||||||
|
switch to changing the text font to a monospace font with
|
||||||
|
`#text(font: "DejaVu Sans Mono", size: 0.8em)[monospace *bold*]`, for example,
|
||||||
|
since `raw` only supports verbatim (unformatted) text. See its documentation
|
||||||
|
for more details.
|
||||||
|
|
||||||
## How do I use a command? { #commands }
|
## How do I use a command? { #commands }
|
||||||
LaTeX heavily relies on commands (prefixed by backslashes). It uses these
|
LaTeX heavily relies on commands (prefixed by backslashes). It uses these
|
||||||
_macros_ to affect the typesetting process and to insert and manipulate content.
|
_macros_ to affect the typesetting process and to insert and manipulate content.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user