mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Fix docs outline for nested definitions (#5823)
This commit is contained in:
parent
ca702c7f82
commit
d61f57365b
@ -550,8 +550,6 @@ fn func_outline(model: &FuncModel, id_base: &str) -> Vec<OutlineItem> {
|
|||||||
.collect(),
|
.collect(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
outline.extend(scope_outline(&model.scope));
|
|
||||||
} else {
|
} else {
|
||||||
outline.extend(model.params.iter().map(|param| OutlineItem {
|
outline.extend(model.params.iter().map(|param| OutlineItem {
|
||||||
id: eco_format!("{id_base}-{}", urlify(param.name)),
|
id: eco_format!("{id_base}-{}", urlify(param.name)),
|
||||||
@ -560,27 +558,30 @@ fn func_outline(model: &FuncModel, id_base: &str) -> Vec<OutlineItem> {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outline.extend(scope_outline(&model.scope, id_base));
|
||||||
|
|
||||||
outline
|
outline
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Produce an outline for a function scope.
|
/// Produce an outline for a function scope.
|
||||||
fn scope_outline(scope: &[FuncModel]) -> Option<OutlineItem> {
|
fn scope_outline(scope: &[FuncModel], id_base: &str) -> Option<OutlineItem> {
|
||||||
if scope.is_empty() {
|
if scope.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(OutlineItem {
|
let dash = if id_base.is_empty() { "" } else { "-" };
|
||||||
id: "definitions".into(),
|
let id = eco_format!("{id_base}{dash}definitions");
|
||||||
name: "Definitions".into(),
|
|
||||||
children: scope
|
let children = scope
|
||||||
.iter()
|
.iter()
|
||||||
.map(|func| {
|
.map(|func| {
|
||||||
let id = urlify(&eco_format!("definitions-{}", func.name));
|
let id = urlify(&eco_format!("{id}-{}", func.name));
|
||||||
let children = func_outline(func, &id);
|
let children = func_outline(func, &id);
|
||||||
OutlineItem { id, name: func.title.into(), children }
|
OutlineItem { id, name: func.title.into(), children }
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect();
|
||||||
})
|
|
||||||
|
Some(OutlineItem { id, name: "Definitions".into(), children })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a page for a group of functions.
|
/// Create a page for a group of functions.
|
||||||
@ -687,7 +688,7 @@ fn type_outline(model: &TypeModel) -> Vec<OutlineItem> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
outline.extend(scope_outline(&model.scope));
|
outline.extend(scope_outline(&model.scope, ""));
|
||||||
outline
|
outline
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user