generate id for headers
This commit is contained in:
parent
5b4a9c3e2d
commit
e36e222f23
1 changed files with 10 additions and 1 deletions
|
@ -37,8 +37,17 @@ pub fn convert_document(markdown: &str) -> String {
|
|||
state = S::None;
|
||||
html += "</p>\n";
|
||||
}
|
||||
let id: String = header
|
||||
.to_lowercase()
|
||||
.chars()
|
||||
.filter_map(|c| match c {
|
||||
' ' => Some('-'),
|
||||
'-' | '_' => Some(c),
|
||||
_ => c.is_alphanumeric().then_some(c),
|
||||
})
|
||||
.collect();
|
||||
let header = &convert_line(header);
|
||||
html += &format!("<h{level}>{header}</h{level}>\n");
|
||||
html += &format!("<h{level} id=\"{id}\">{header}</h{level}>\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue