File tree Expand file tree Collapse file tree 4 files changed +29
-11
lines changed Expand file tree Collapse file tree 4 files changed +29
-11
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ def foobar(door, bar={}):
9
9
"# ;
10
10
11
11
let message = & [ Group :: new ( )
12
+ . primary_level ( Level :: NOTE )
12
13
. element (
13
14
Snippet :: source ( source)
14
15
. fold ( false )
Original file line number Diff line number Diff line change @@ -275,14 +275,16 @@ impl Renderer {
275
275
if og_primary_path. is_none ( ) && primary_path. is_some ( ) {
276
276
og_primary_path = primary_path;
277
277
}
278
- let level = group
279
- . elements
280
- . first ( )
281
- . and_then ( |s| match & s {
282
- Element :: Title ( title) => Some ( title. level . clone ( ) ) ,
283
- _ => None ,
284
- } )
285
- . unwrap_or ( Level :: ERROR ) ;
278
+ let level = group. primary_level . clone ( ) . unwrap_or_else ( || {
279
+ group
280
+ . elements
281
+ . first ( )
282
+ . and_then ( |s| match & s {
283
+ Element :: Title ( title) => Some ( title. level . clone ( ) ) ,
284
+ _ => None ,
285
+ } )
286
+ . unwrap_or ( Level :: ERROR )
287
+ } ) ;
286
288
let mut source_map_annotated_lines = VecDeque :: new ( ) ;
287
289
let mut max_depth = 0 ;
288
290
for e in & group. elements {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ pub(crate) struct Id<'a> {
20
20
/// An [`Element`] container
21
21
#[ derive( Clone , Debug ) ]
22
22
pub struct Group < ' a > {
23
+ pub ( crate ) primary_level : Option < Level < ' a > > ,
23
24
pub ( crate ) elements : Vec < Element < ' a > > ,
24
25
}
25
26
@@ -31,7 +32,10 @@ impl Default for Group<'_> {
31
32
32
33
impl < ' a > Group < ' a > {
33
34
pub fn new ( ) -> Self {
34
- Self { elements : vec ! [ ] }
35
+ Self {
36
+ primary_level : None ,
37
+ elements : vec ! [ ] ,
38
+ }
35
39
}
36
40
37
41
pub fn element ( mut self , section : impl Into < Element < ' a > > ) -> Self {
@@ -44,6 +48,15 @@ impl<'a> Group<'a> {
44
48
self
45
49
}
46
50
51
+ /// Set the primary [`Level`] for this [`Group`].
52
+ ///
53
+ /// If not specified, use the [`Level`] of the first element in a [`Group`]
54
+ /// if it is a [`Title`]. If not it will default to [`Level::ERROR`].
55
+ pub fn primary_level ( mut self , level : Level < ' a > ) -> Self {
56
+ self . primary_level = Some ( level) ;
57
+ self
58
+ }
59
+
47
60
pub fn is_empty ( & self ) -> bool {
48
61
self . elements . is_empty ( )
49
62
}
@@ -263,6 +276,8 @@ impl<'a> Annotation<'a> {
263
276
#[ non_exhaustive]
264
277
pub enum AnnotationKind {
265
278
/// Match the primary [`Level`] of the group.
279
+ ///
280
+ /// See [`Group::primary_level`] for details about how this is determined
266
281
Primary ,
267
282
/// Additional context to explain the [`Primary`][Self::Primary]
268
283
/// [`Annotation`]
You can’t perform that action at this time.
0 commit comments