fix: render markdown in headings
This commit is contained in:
parent
6da4a7712b
commit
6451f929b4
2 changed files with 32 additions and 9 deletions
|
@ -321,12 +321,14 @@ input[type="checkbox"] {
|
|||
}
|
||||
|
||||
/* typo */
|
||||
p {
|
||||
margin-bottom: var(--pad-4);
|
||||
}
|
||||
p,
|
||||
ul,
|
||||
ol {
|
||||
margin-bottom: var(--pad-4) !important;
|
||||
|
||||
p:last-child {
|
||||
margin-bottom: 0;
|
||||
&:last-child {
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.post_right:not(.repost) {
|
||||
|
@ -522,6 +524,11 @@ blockquote {
|
|||
opacity: 75%;
|
||||
}
|
||||
|
||||
p,
|
||||
span {
|
||||
font-size: inherit;
|
||||
}
|
||||
|
||||
/* codemirror/hljs */
|
||||
.CodeMirror {
|
||||
color: var(--color-text) !important;
|
||||
|
@ -660,6 +667,7 @@ blockquote {
|
|||
|
||||
.CodeMirror-line {
|
||||
padding-left: 0 !important;
|
||||
font-size: 16px !important;
|
||||
}
|
||||
|
||||
.CodeMirror-focused .CodeMirror-placeholder {
|
||||
|
|
|
@ -884,6 +884,14 @@ pub fn parse_details(input: &str) -> String {
|
|||
output
|
||||
}
|
||||
|
||||
fn underscore_chars(mut x: String, chars: &[&str]) -> String {
|
||||
for y in chars {
|
||||
x = x.replace(y, "_");
|
||||
}
|
||||
|
||||
x
|
||||
}
|
||||
|
||||
/// Get the list of headers needed for [`parse_toc`].
|
||||
pub fn get_toc_list(input: &str) -> (String, String) {
|
||||
let mut output = String::new();
|
||||
|
@ -919,11 +927,18 @@ pub fn get_toc_list(input: &str) -> (String, String) {
|
|||
let x = line.replacen(&"#".repeat(hc), "", 1);
|
||||
let htext = x.trim();
|
||||
|
||||
let id = htext.to_lowercase().replace(" ", "_");
|
||||
output.push_str(&format!("<h{hc} id=\"{id}\">{htext}</h{hc}>\n"));
|
||||
let id = underscore_chars(
|
||||
htext.to_lowercase(),
|
||||
&[" ", "(", ")", "[", "]", "{", "}", ":", "?", "#", "&"],
|
||||
);
|
||||
|
||||
output.push_str(&format!(
|
||||
"<h{hc} id=\"{id}\">{}</h{hc}>\n",
|
||||
render_markdown(&htext)
|
||||
));
|
||||
|
||||
// add heading to toc
|
||||
toc += &format!("{}- [{htext}](#{id})\n", " ".repeat(hc));
|
||||
toc += &format!("{}- <a href=\"#{id}\">{htext}</a>\n", " ".repeat(hc));
|
||||
|
||||
// ...
|
||||
continue;
|
||||
|
@ -958,7 +973,7 @@ pub fn parse_toc(input: &str) -> String {
|
|||
// not in pre
|
||||
if line.len() == 5 && line.to_lowercase() == "[toc]" {
|
||||
// add toc
|
||||
output.push_str(&toc_list);
|
||||
output.push_str(&format!("\n{toc_list}"));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue