@@ -33,13 +33,25 @@ fn is_module_readme(dn doc.DocNode) bool {
33
33
return dn.comments.len > 0 && (dn.content == 'module ${dn.name} ' || dn.name == 'README' )
34
34
}
35
35
36
- fn trim_doc_node_description (desc string ) string {
36
+ // trim_doc_node_description returns the nodes trimmed description.
37
+ // An example use are the descriptions of the search results in the sidebar.
38
+ fn trim_doc_node_description (mod_name string , desc string ) string {
37
39
mut dn_desc := desc.replace_each (['\r\n ' , '\n ' , '"' , '\\ "' ])
38
- // Handle module READMEs.
39
- if dn_desc.starts_with ('## Description\n\n ' ) {
40
- dn_desc = dn_desc['## Description\n\n ' .len..].all_before ('\n ' )
41
- if dn_desc.starts_with ('`' ) && dn_desc.count ('`' ) > 1 {
42
- dn_desc = dn_desc.all_after ('`' ).all_after ('`' ).trim_left (' ' )
40
+ // Get the first "descriptive" line.
41
+ if dn_desc.starts_with ('#' ) {
42
+ // Handle module READMEs.
43
+ for l in dn_desc.split_into_lines ()[1 ..] {
44
+ if l != '' && ! l.starts_with ('#' ) {
45
+ quoted_mod_name := '`${mod_name} `'
46
+ if l.starts_with (quoted_mod_name) {
47
+ // Omit the module name in the description as it is redundant since the name is displayed as well.
48
+ // "`arrays` is a module that..." -> "is a module that..."
49
+ dn_desc = l.all_after (quoted_mod_name).trim_left (' ' )
50
+ } else {
51
+ dn_desc = l
52
+ }
53
+ break
54
+ }
43
55
}
44
56
} else {
45
57
dn_desc = dn_desc.all_before ('\n ' )
@@ -48,7 +60,7 @@ fn trim_doc_node_description(desc string) string {
48
60
if dn_desc.len > 80 {
49
61
dn_desc = dn_desc[..80 ]
50
62
}
51
- // If `\` is last character, it ends with `\"` which leads to a JS error.
63
+ // If `\` is the last character, it ends with `\"` which leads to a JS error.
52
64
return dn_desc.trim_string_right ('\\ ' )
53
65
}
54
66
0 commit comments