summaryrefslogtreecommitdiff
path: root/crates/typst-docs/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-08-03 16:33:17 +0200
committerLaurenz <laurmaedje@gmail.com>2023-08-03 16:33:17 +0200
commit028d2f53085022c39945b1a99c9dc78eb8069d4a (patch)
treec220f3fed751c3e3b5e3c07d6246a1378b0519cb /crates/typst-docs/src
parent53a896f049d45a8e9a225ceacd56da07854aa973 (diff)
Split markup and math shorthands for docs
Diffstat (limited to 'crates/typst-docs/src')
-rw-r--r--crates/typst-docs/src/lib.rs36
1 files changed, 24 insertions, 12 deletions
diff --git a/crates/typst-docs/src/lib.rs b/crates/typst-docs/src/lib.rs
index fae94a6f..4dda2c0d 100644
--- a/crates/typst-docs/src/lib.rs
+++ b/crates/typst-docs/src/lib.rs
@@ -214,7 +214,8 @@ pub struct CategoryModel {
pub details: Html,
pub kind: &'static str,
pub items: Vec<CategoryItem>,
- pub shorthands: Option<Vec<SymbolModel>>,
+ pub markup_shorthands: Option<Vec<SymbolModel>>,
+ pub math_shorthands: Option<Vec<SymbolModel>>,
}
/// Details about a category item.
@@ -325,13 +326,20 @@ fn category_page(resolver: &dyn Resolver, category: &str) -> PageModel {
items.sort_by_cached_key(|item| item.name.clone());
// Add symbol pages. These are ordered manually.
- let mut shorthands = vec![];
+ let mut markup_shorthands = vec![];
+ let mut math_shorthands = vec![];
if category == "symbols" {
for module in ["sym", "emoji"] {
let subpage = symbol_page(resolver, &route, module);
let BodyModel::Symbols(model) = &subpage.body else { continue };
- shorthands.extend(
- model.list.iter().filter(|symbol| symbol.shorthand.is_some()).cloned(),
+ let list = &model.list;
+ markup_shorthands.extend(
+ list.iter()
+ .filter(|symbol| symbol.markup_shorthand.is_some())
+ .cloned(),
+ );
+ math_shorthands.extend(
+ list.iter().filter(|symbol| symbol.math_shorthand.is_some()).cloned(),
);
items.push(CategoryItem {
@@ -361,7 +369,8 @@ fn category_page(resolver: &dyn Resolver, category: &str) -> PageModel {
details: Html::markdown(resolver, details(category)),
kind,
items,
- shorthands: Some(shorthands),
+ markup_shorthands: Some(markup_shorthands),
+ math_shorthands: Some(math_shorthands),
}),
children,
}
@@ -659,7 +668,8 @@ fn types_page(resolver: &dyn Resolver, parent: &str) -> PageModel {
details: Html::markdown(resolver, details("types")),
kind: "Types",
items,
- shorthands: None,
+ markup_shorthands: None,
+ math_shorthands: None,
}),
children,
}
@@ -836,7 +846,8 @@ pub struct SymbolsModel {
#[serde(rename_all = "camelCase")]
pub struct SymbolModel {
pub name: String,
- pub shorthand: Option<&'static str>,
+ pub markup_shorthand: Option<&'static str>,
+ pub math_shorthand: Option<&'static str>,
pub codepoint: u32,
pub accent: bool,
pub unicode_name: Option<String>,
@@ -859,13 +870,14 @@ fn symbol_page(resolver: &dyn Resolver, parent: &str, name: &str) -> PageModel {
};
for (variant, c) in symbol.variants() {
+ let shorthand = |list: &[(&'static str, char)]| {
+ list.iter().copied().find(|&(_, x)| x == c).map(|(s, _)| s)
+ };
+
list.push(SymbolModel {
name: complete(variant),
- shorthand: typst::syntax::ast::Shorthand::LIST
- .iter()
- .copied()
- .find(|&(_, x)| x == c)
- .map(|(s, _)| s),
+ markup_shorthand: shorthand(typst::syntax::ast::Shorthand::MARKUP_LIST),
+ math_shorthand: shorthand(typst::syntax::ast::Shorthand::MATH_LIST),
codepoint: c as u32,
accent: typst::eval::Symbol::combining_accent(c).is_some(),
unicode_name: unicode_names2::name(c)