diff --git a/crates/stef-doc/src/templates.rs b/crates/stef-doc/src/templates.rs index 8d8e622..57650d1 100644 --- a/crates/stef-doc/src/templates.rs +++ b/crates/stef-doc/src/templates.rs @@ -74,8 +74,19 @@ impl Display for PathUp { } } +fn first_comment(item: &Comment<'_>) -> String { + item.0 + .iter() + .take_while(|line| !line.value.trim().is_empty()) + .fold(String::new(), |mut acc, line| { + acc.push_str(line.value); + acc.push('\n'); + acc + }) +} + fn merge_comments(item: &Comment<'_>) -> String { - item.0.iter().fold(String::new(),|mut acc, line| { + item.0.iter().fold(String::new(), |mut acc, line| { acc.push_str(line.value); acc.push('\n'); acc diff --git a/crates/stef-doc/templates/detail/module.html b/crates/stef-doc/templates/detail/module.html index 325c39c..8e83468 100644 --- a/crates/stef-doc/templates/detail/module.html +++ b/crates/stef-doc/templates/detail/module.html @@ -26,9 +26,7 @@

Modules

{{ m.name }} - {%- if !m.comment.0.is_empty() %} - {{ m.comment.0[0].value|markdown|trim|safe }} - {%- endif %} + {{ self::first_comment(m.comment)|markdown|trim|safe }} {%- else %} @@ -47,9 +45,7 @@

Structs

{{ s.name }} - {%- if !s.comment.0.is_empty() %} - {{ s.comment.0[0].value|markdown|trim|safe }} - {%- endif %} + {{ self::first_comment(s.comment)|markdown|trim|safe }} {%- else %} @@ -68,9 +64,7 @@

Enums

{{ e.name }} - {%- if !e.comment.0.is_empty() %} - {{ e.comment.0[0].value|markdown|trim|safe }} - {%- endif %} + {{ self::first_comment(e.comment)|markdown|trim|safe }} {%- else %} @@ -89,9 +83,7 @@

Aliases

{{ a.name }} - {%- if !a.comment.0.is_empty() %} - {{ a.comment.0[0].value|markdown|trim|safe }} - {%- endif %} + {{ self::first_comment(a.comment)|markdown|trim|safe }} {%- else %} @@ -110,9 +102,7 @@

Constants

{{ c.name }} - {%- if !c.comment.0.is_empty() %} - {{ c.comment.0[0].value|markdown|trim|safe }} - {%- endif %} + {{ self::first_comment(c.comment)|markdown|trim|safe }} {%- else %} diff --git a/crates/stef-doc/templates/index.html b/crates/stef-doc/templates/index.html index 784671e..c708930 100644 --- a/crates/stef-doc/templates/index.html +++ b/crates/stef-doc/templates/index.html @@ -17,9 +17,7 @@

Modules

{{ m.name }} - {%- if !m.comment.0.is_empty() %} - {{ m.comment.0[0].value|markdown|trim|safe }} - {%- endif %} + {{ self::first_comment(m.comment)|markdown|trim|safe }} {%- else %} @@ -38,9 +36,7 @@

Structs

{{ s.name }} - {%- if !s.comment.0.is_empty() %} - {{ s.comment.0[0].value|markdown|trim|safe }} - {%- endif %} + {{ self::first_comment(s.comment)|markdown|trim|safe }} {%- else %} @@ -59,9 +55,7 @@

Enums

{{ e.name }} - {%- if !e.comment.0.is_empty() %} - {{ e.comment.0[0].value|markdown|trim|safe }} - {%- endif %} + {{ self::first_comment(e.comment)|markdown|trim|safe }} {%- else %} @@ -80,9 +74,7 @@

Aliases

{{ a.name }} - {%- if !a.comment.0.is_empty() %} - {{ a.comment.0[0].value|markdown|trim|safe }} - {%- endif %} + {{ self::first_comment(a.comment)|markdown|trim|safe }} {%- else %} @@ -101,9 +93,7 @@

Constants

{{ c.name }} - {%- if !c.comment.0.is_empty() %} - {{ c.comment.0[0].value|markdown|trim|safe }} - {%- endif %} + {{ self::first_comment(c.comment)|markdown|trim|safe }} {%- else %} diff --git a/crates/stef-doc/tests/snapshots/render__render@attribute_multi.stef.snap b/crates/stef-doc/tests/snapshots/render__render@attribute_multi.stef.snap index 6f283fb..6f2f302 100644 --- a/crates/stef-doc/tests/snapshots/render__render@attribute_multi.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@attribute_multi.stef.snap @@ -36,6 +36,7 @@ input_file: crates/stef-parser/tests/inputs/attribute_multi.stef Sample + diff --git a/crates/stef-doc/tests/snapshots/render__render@attribute_single.stef.snap b/crates/stef-doc/tests/snapshots/render__render@attribute_single.stef.snap index 78a2073..85e6bb1 100644 --- a/crates/stef-doc/tests/snapshots/render__render@attribute_single.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@attribute_single.stef.snap @@ -36,6 +36,7 @@ input_file: crates/stef-parser/tests/inputs/attribute_single.stef Sample + diff --git a/crates/stef-doc/tests/snapshots/render__render@attribute_unit.stef.snap b/crates/stef-doc/tests/snapshots/render__render@attribute_unit.stef.snap index 5d1fc13..37d6a37 100644 --- a/crates/stef-doc/tests/snapshots/render__render@attribute_unit.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@attribute_unit.stef.snap @@ -36,6 +36,7 @@ input_file: crates/stef-parser/tests/inputs/attribute_unit.stef Sample + diff --git a/crates/stef-doc/tests/snapshots/render__render@attributes.stef.snap b/crates/stef-doc/tests/snapshots/render__render@attributes.stef.snap index 3d11556..9579e5c 100644 --- a/crates/stef-doc/tests/snapshots/render__render@attributes.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@attributes.stef.snap @@ -36,6 +36,7 @@ input_file: crates/stef-parser/tests/inputs/attributes.stef Sample + diff --git a/crates/stef-doc/tests/snapshots/render__render@attributes_min_ws.stef.snap b/crates/stef-doc/tests/snapshots/render__render@attributes_min_ws.stef.snap index e02ec5d..ed227de 100644 --- a/crates/stef-doc/tests/snapshots/render__render@attributes_min_ws.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@attributes_min_ws.stef.snap @@ -36,6 +36,7 @@ input_file: crates/stef-parser/tests/inputs/attributes_min_ws.stef Sample + diff --git a/crates/stef-doc/tests/snapshots/render__render@const_basic.stef.snap b/crates/stef-doc/tests/snapshots/render__render@const_basic.stef.snap index c3870be..ca3b96a 100644 --- a/crates/stef-doc/tests/snapshots/render__render@const_basic.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@const_basic.stef.snap @@ -51,6 +51,7 @@ input_file: crates/stef-parser/tests/inputs/const_basic.stef BOOL_TRUE + @@ -58,6 +59,7 @@ input_file: crates/stef-parser/tests/inputs/const_basic.stef BOOL_FALSE + @@ -65,6 +67,7 @@ input_file: crates/stef-parser/tests/inputs/const_basic.stef INT + @@ -72,6 +75,7 @@ input_file: crates/stef-parser/tests/inputs/const_basic.stef FLOAT + @@ -79,6 +83,7 @@ input_file: crates/stef-parser/tests/inputs/const_basic.stef STRING + @@ -86,6 +91,7 @@ input_file: crates/stef-parser/tests/inputs/const_basic.stef BYTES + diff --git a/crates/stef-doc/tests/snapshots/render__render@const_string.stef.snap b/crates/stef-doc/tests/snapshots/render__render@const_string.stef.snap index 25ce6e5..3262316 100644 --- a/crates/stef-doc/tests/snapshots/render__render@const_string.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@const_string.stef.snap @@ -51,6 +51,7 @@ input_file: crates/stef-parser/tests/inputs/const_string.stef SIMPLE + @@ -58,6 +59,7 @@ input_file: crates/stef-parser/tests/inputs/const_string.stef NEWLINE_ESCAPE + @@ -65,6 +67,7 @@ input_file: crates/stef-parser/tests/inputs/const_string.stef ESCAPES + @@ -72,6 +75,7 @@ input_file: crates/stef-parser/tests/inputs/const_string.stef MULTILINE + diff --git a/crates/stef-doc/tests/snapshots/render__render@enum_min_ws.stef.snap b/crates/stef-doc/tests/snapshots/render__render@enum_min_ws.stef.snap index 7ab8b82..5ff9888 100644 --- a/crates/stef-doc/tests/snapshots/render__render@enum_min_ws.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@enum_min_ws.stef.snap @@ -41,6 +41,7 @@ input_file: crates/stef-parser/tests/inputs/enum_min_ws.stef Sample + diff --git a/crates/stef-doc/tests/snapshots/render__render@mixed.stef.snap b/crates/stef-doc/tests/snapshots/render__render@mixed.stef.snap index 95db2ef..e8a8329 100644 --- a/crates/stef-doc/tests/snapshots/render__render@mixed.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@mixed.stef.snap @@ -60,6 +60,7 @@ input_file: crates/stef-parser/tests/inputs/mixed.stef Address + @@ -671,7 +672,8 @@ const MAX_AGE: u8 = 120; MAX_DAY -

Absolute maximum for a day, but might be even less depending

+

Absolute maximum for a day, but might be even less depending +on the month.

diff --git a/crates/stef-doc/tests/snapshots/render__render@module_basic.stef.snap b/crates/stef-doc/tests/snapshots/render__render@module_basic.stef.snap index 755c060..253627a 100644 --- a/crates/stef-doc/tests/snapshots/render__render@module_basic.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@module_basic.stef.snap @@ -31,6 +31,7 @@ input_file: crates/stef-parser/tests/inputs/module_basic.stef a + @@ -106,6 +107,7 @@ input_file: crates/stef-parser/tests/inputs/module_basic.stef Sample + @@ -173,6 +175,7 @@ input_file: crates/stef-parser/tests/inputs/module_basic.stef Sample + diff --git a/crates/stef-doc/tests/snapshots/render__render@struct_min_ws.stef.snap b/crates/stef-doc/tests/snapshots/render__render@struct_min_ws.stef.snap index ee832ac..e53af85 100644 --- a/crates/stef-doc/tests/snapshots/render__render@struct_min_ws.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@struct_min_ws.stef.snap @@ -36,6 +36,7 @@ input_file: crates/stef-parser/tests/inputs/struct_min_ws.stef Sample + diff --git a/crates/stef-doc/tests/snapshots/render__render@types_basic.stef.snap b/crates/stef-doc/tests/snapshots/render__render@types_basic.stef.snap index 75789bc..6cfac0e 100644 --- a/crates/stef-doc/tests/snapshots/render__render@types_basic.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@types_basic.stef.snap @@ -36,6 +36,7 @@ input_file: crates/stef-parser/tests/inputs/types_basic.stef Sample + diff --git a/crates/stef-doc/tests/snapshots/render__render@types_generic.stef.snap b/crates/stef-doc/tests/snapshots/render__render@types_generic.stef.snap index 2baf5b6..c5a35c3 100644 --- a/crates/stef-doc/tests/snapshots/render__render@types_generic.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@types_generic.stef.snap @@ -36,6 +36,7 @@ input_file: crates/stef-parser/tests/inputs/types_generic.stef Sample + @@ -43,6 +44,7 @@ input_file: crates/stef-parser/tests/inputs/types_generic.stef SampleUnnamed + diff --git a/crates/stef-doc/tests/snapshots/render__render@types_nested.stef.snap b/crates/stef-doc/tests/snapshots/render__render@types_nested.stef.snap index c3df923..e318034 100644 --- a/crates/stef-doc/tests/snapshots/render__render@types_nested.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@types_nested.stef.snap @@ -36,6 +36,7 @@ input_file: crates/stef-parser/tests/inputs/types_nested.stef Sample + diff --git a/crates/stef-doc/tests/snapshots/render__render@types_non_zero.stef.snap b/crates/stef-doc/tests/snapshots/render__render@types_non_zero.stef.snap index 7fc31bb..c1a9286 100644 --- a/crates/stef-doc/tests/snapshots/render__render@types_non_zero.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@types_non_zero.stef.snap @@ -36,6 +36,7 @@ input_file: crates/stef-parser/tests/inputs/types_non_zero.stef Sample + diff --git a/crates/stef-doc/tests/snapshots/render__render@types_ref.stef.snap b/crates/stef-doc/tests/snapshots/render__render@types_ref.stef.snap index baff5af..60401bb 100644 --- a/crates/stef-doc/tests/snapshots/render__render@types_ref.stef.snap +++ b/crates/stef-doc/tests/snapshots/render__render@types_ref.stef.snap @@ -36,6 +36,7 @@ input_file: crates/stef-parser/tests/inputs/types_ref.stef Sample + @@ -43,6 +44,7 @@ input_file: crates/stef-parser/tests/inputs/types_ref.stef KeyValue + @@ -55,6 +57,7 @@ input_file: crates/stef-parser/tests/inputs/types_ref.stef Test123 +