summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2026-01-31 14:31:32 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2026-01-31 15:08:14 +1300
commitd8855e24893ba7db97aaf7f94b054782a4276833 (patch)
tree961c2035bfcbaaa94eee20d86683af9830a9c8e8
parent200bb2c3c2af8f43d8403015198cc1932293b7bf (diff)
downloadtoaster-d8855e24893ba7db97aaf7f94b054782a4276833.zip
Auto-insert line breaks for environment-free math fragmentsHEADmain
This was an important functionality for a lot of my math notes, so I've brought it back, but only if the math syntax fragment doesn't contain a '\begin', which denotes the sort of advanced environment where automatic line breaks are not welcome.
-rw-r--r--src/generate_html.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/generate_html.rs b/src/generate_html.rs
index 36f3325..7bec912 100644
--- a/src/generate_html.rs
+++ b/src/generate_html.rs
@@ -239,7 +239,13 @@ pub fn document_to_html(page: &Page, website: &Website) -> String {
}
Block::Fragment { language, content } => {
match language.as_str() {
- "math" => html!("<div class='math'>{content}</div>"),
+ "math" => {
+ let mut content = content.trim().to_string();
+ if !content.contains(r"\begin") {
+ content = content.replace("\n", " \\\\\n").to_string();
+ }
+ html!("<div class='math'>{content}</div>")
+ },
"embed-html" => html!("{content}"),
"embed-css" => wrap!("style", html!("{content}")),
"embed-javascript"|"embed-js" => wrap!("script", html!("{content}")),