Skip to content

Commit

Permalink
Fix crate-level docs not being rendered correctly if there is no readme:
Browse files Browse the repository at this point in the history
 * Markdown was not rendered
 * Highlighting wasn't run as expected
 * Lines start were completely trimmed whereas they shouldn't
  • Loading branch information
GuillaumeGomez committed Jan 17, 2025
1 parent d97b27d commit 406eb57
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/db/add_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,10 @@ fn read_rust_doc(file_path: &Path) -> Result<Option<String>> {
let line = line?;
if line.starts_with("//!") {
// some lines may or may not have a space between the `//!` and the start of the text
let line = line.trim_start_matches("//!").trim_start();
let mut line = line.trim_start_matches("//!");
if line.starts_with(' ') {
line = &line[1..];
}
if !line.is_empty() {
rustdoc.push_str(line);
}
Expand Down
3 changes: 3 additions & 0 deletions src/web/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ fn try_with_syntax(syntax: &SyntaxReference, code: &str) -> Result<String> {

fn select_syntax(name: Option<&str>, code: &str) -> &'static SyntaxReference {
name.and_then(|name| {
if name.is_empty() {
return SYNTAXES.find_syntax_by_token("rust");
}
SYNTAXES.find_syntax_by_token(name).or_else(|| {
name.rsplit_once('.')
.and_then(|(_, ext)| SYNTAXES.find_syntax_by_token(ext))
Expand Down
2 changes: 1 addition & 1 deletion templates/crate/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@

{# If there's not a readme then attempt to display the long description #}
{%- elif let Some(rustdoc) = rustdoc -%}
{{ rustdoc|safe }}
{{ crate::web::markdown::render(rustdoc)|safe }}
{%- endif -%}
</div>
</div>
Expand Down

0 comments on commit 406eb57

Please sign in to comment.