mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-07-24 07:45:57 +02:00
v1.1.6 - Multi-window, single-instance file handling, line height setting
This commit is contained in:
@@ -77,6 +77,29 @@ pub fn parse_note(raw: &str, filename: &str) -> (NoteMeta, String) {
|
||||
(meta, content)
|
||||
}
|
||||
|
||||
/// Ensure the body starts with `# Title` heading for external app compatibility.
|
||||
/// If the body already starts with `# Title`, leave it as-is.
|
||||
fn ensure_title_heading(body: &str, title: &str) -> String {
|
||||
let trimmed = body.trim_start();
|
||||
|
||||
// Check if body already starts with `# Title`
|
||||
if let Some(rest) = trimmed.strip_prefix("# ") {
|
||||
let first_line_end = rest.find('\n').unwrap_or(rest.len());
|
||||
let heading_text = rest[..first_line_end].trim();
|
||||
if heading_text.eq_ignore_ascii_case(title.trim()) {
|
||||
return body.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
// Don't add heading to empty notes (new/blank notes)
|
||||
if trimmed.is_empty() {
|
||||
return body.to_string();
|
||||
}
|
||||
|
||||
// Prepend `# Title` heading
|
||||
format!("# {}\n\n{}", title, body)
|
||||
}
|
||||
|
||||
pub fn serialize_frontmatter(meta: &NoteMeta) -> String {
|
||||
let tags_str = if meta.tags.is_empty() {
|
||||
"[]".to_string()
|
||||
@@ -104,7 +127,8 @@ pub fn serialize_frontmatter(meta: &NoteMeta) -> String {
|
||||
|
||||
pub fn update_note_raw(meta: &NoteMeta, body: &str) -> String {
|
||||
let fm = serialize_frontmatter(meta);
|
||||
format!("{}{}", fm, body)
|
||||
let body_with_heading = ensure_title_heading(body, &meta.title);
|
||||
format!("{}{}", fm, body_with_heading)
|
||||
}
|
||||
|
||||
/// Merge NoteMeta fields into existing frontmatter, preserving unknown YAML keys.
|
||||
@@ -163,7 +187,8 @@ pub fn merge_frontmatter(original_raw: &str, meta: &NoteMeta, body: &str) -> Str
|
||||
Err(_) => return update_note_raw(meta, body),
|
||||
};
|
||||
|
||||
format!("---\n{}---\n{}", yaml_str, body)
|
||||
let body_with_heading = ensure_title_heading(body, &meta.title);
|
||||
format!("---\n{}---\n{}", yaml_str, body_with_heading)
|
||||
}
|
||||
|
||||
fn filename_to_title(filename: &str) -> String {
|
||||
|
||||
Reference in New Issue
Block a user