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 */
|
/* typo */
|
||||||
p {
|
p,
|
||||||
margin-bottom: var(--pad-4);
|
ul,
|
||||||
}
|
ol {
|
||||||
|
margin-bottom: var(--pad-4) !important;
|
||||||
|
|
||||||
p:last-child {
|
&:last-child {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0 !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.post_right:not(.repost) {
|
.post_right:not(.repost) {
|
||||||
|
@ -522,6 +524,11 @@ blockquote {
|
||||||
opacity: 75%;
|
opacity: 75%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p,
|
||||||
|
span {
|
||||||
|
font-size: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
/* codemirror/hljs */
|
/* codemirror/hljs */
|
||||||
.CodeMirror {
|
.CodeMirror {
|
||||||
color: var(--color-text) !important;
|
color: var(--color-text) !important;
|
||||||
|
@ -660,6 +667,7 @@ blockquote {
|
||||||
|
|
||||||
.CodeMirror-line {
|
.CodeMirror-line {
|
||||||
padding-left: 0 !important;
|
padding-left: 0 !important;
|
||||||
|
font-size: 16px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.CodeMirror-focused .CodeMirror-placeholder {
|
.CodeMirror-focused .CodeMirror-placeholder {
|
||||||
|
|
|
@ -884,6 +884,14 @@ pub fn parse_details(input: &str) -> String {
|
||||||
output
|
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`].
|
/// Get the list of headers needed for [`parse_toc`].
|
||||||
pub fn get_toc_list(input: &str) -> (String, String) {
|
pub fn get_toc_list(input: &str) -> (String, String) {
|
||||||
let mut output = String::new();
|
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 x = line.replacen(&"#".repeat(hc), "", 1);
|
||||||
let htext = x.trim();
|
let htext = x.trim();
|
||||||
|
|
||||||
let id = htext.to_lowercase().replace(" ", "_");
|
let id = underscore_chars(
|
||||||
output.push_str(&format!("<h{hc} id=\"{id}\">{htext}</h{hc}>\n"));
|
htext.to_lowercase(),
|
||||||
|
&[" ", "(", ")", "[", "]", "{", "}", ":", "?", "#", "&"],
|
||||||
|
);
|
||||||
|
|
||||||
|
output.push_str(&format!(
|
||||||
|
"<h{hc} id=\"{id}\">{}</h{hc}>\n",
|
||||||
|
render_markdown(&htext)
|
||||||
|
));
|
||||||
|
|
||||||
// add heading to toc
|
// add heading to toc
|
||||||
toc += &format!("{}- [{htext}](#{id})\n", " ".repeat(hc));
|
toc += &format!("{}- <a href=\"#{id}\">{htext}</a>\n", " ".repeat(hc));
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
continue;
|
continue;
|
||||||
|
@ -958,7 +973,7 @@ pub fn parse_toc(input: &str) -> String {
|
||||||
// not in pre
|
// not in pre
|
||||||
if line.len() == 5 && line.to_lowercase() == "[toc]" {
|
if line.len() == 5 && line.to_lowercase() == "[toc]" {
|
||||||
// add toc
|
// add toc
|
||||||
output.push_str(&toc_list);
|
output.push_str(&format!("\n{toc_list}"));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue