Skip to content

Commit db796b6

Browse files
GuillaumeGomezsyphar
authored andcommitted
Fix crate-level docs not being rendered correctly if there is no readme:
* Markdown was not rendered * Highlighting wasn't run as expected * Lines start were completely trimmed whereas they shouldn't
1 parent 4da9cd7 commit db796b6

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/db/add_package.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,10 @@ fn read_rust_doc(file_path: &Path) -> Result<Option<String>> {
469469
let line = line?;
470470
if line.starts_with("//!") {
471471
// some lines may or may not have a space between the `//!` and the start of the text
472-
let line = line.trim_start_matches("//!").trim_start();
472+
let mut line = line.trim_start_matches("//!");
473+
if line.starts_with(' ') {
474+
line = &line[1..];
475+
}
473476
if !line.is_empty() {
474477
rustdoc.push_str(line);
475478
}

src/web/highlight.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ fn try_with_syntax(syntax: &SyntaxReference, code: &str) -> Result<String> {
5151

5252
fn select_syntax(name: Option<&str>, code: &str) -> &'static SyntaxReference {
5353
name.and_then(|name| {
54+
if name.is_empty() {
55+
return SYNTAXES.find_syntax_by_token("rust");
56+
}
5457
SYNTAXES.find_syntax_by_token(name).or_else(|| {
5558
name.rsplit_once('.')
5659
.and_then(|(_, ext)| SYNTAXES.find_syntax_by_token(ext))

templates/crate/details.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198

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

0 commit comments

Comments
 (0)