Cycle list markers by default (#2788)

Co-authored-by: Laurenz <laurmaedje@gmail.com>
This commit is contained in:
Emmett Rayes 2023-12-18 18:25:28 +01:00 committed by GitHub
parent 1f983ced90
commit 6808e58a3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 4 deletions

View File

@ -69,7 +69,7 @@ pub struct ListElem {
///
/// Instead of plain content, you can also pass an array with multiple
/// markers that should be used for nested lists. If the list nesting depth
/// exceeds the number of markers, the last one is repeated. For total
/// exceeds the number of markers, the markers are cycled. For total
/// control, you may pass a function that maps the list's nesting depth
/// (starting from `{0}`) to a desired marker.
///
@ -85,7 +85,14 @@ pub struct ListElem {
/// - Items
/// ```
#[borrowed]
#[default(ListMarker::Content(vec![TextElem::packed('•')]))]
#[default(ListMarker::Content(vec![
// These are all available in the default font, vertically centered, and
// roughly of the same size (with the last one having slightly lower
// weight because it is not filled).
TextElem::packed('\u{2022}'), // Bullet
TextElem::packed('\u{2023}'), // Triangular Bullet
TextElem::packed('\u{2013}'), // En-dash
]))]
pub marker: ListMarker,
/// The indent of each item.
@ -202,7 +209,7 @@ impl ListMarker {
fn resolve(&self, engine: &mut Engine, depth: usize) -> SourceResult<Content> {
Ok(match self {
Self::Content(list) => {
list.get(depth).or(list.last()).cloned().unwrap_or_default()
list.get(depth % list.len()).cloned().unwrap_or_default()
}
Self::Func(func) => func.call(engine, [depth])?.display(),
})

Binary file not shown.

Before

Width:  |  Height:  |  Size: 852 B

After

Width:  |  Height:  |  Size: 835 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -7,7 +7,7 @@
- B
---
// Test that last item is repeated.
// Test that items are cycled.
#set list(marker: ([--], []))
- A
- B