possibly first working draft
This commit is contained in:
@ -25,27 +25,45 @@ func NewNote() *Note {
|
||||
return &Note{}
|
||||
}
|
||||
|
||||
func (n *Note) GetUpdateDateRep() string {
|
||||
return n.UpdatedAt.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
// ExtractTitle return the first level heading content ('# title')
|
||||
func ExtractTitle(mkd string) string {
|
||||
if mkd == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(mkd, "# ") {
|
||||
return ""
|
||||
lines := strings.Split(mkd, "\n")
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if strings.HasPrefix(line, "# ") {
|
||||
// Extract title from # heading
|
||||
title := strings.TrimPrefix(line, "# ")
|
||||
title = strings.TrimSpace(title)
|
||||
// Remove common markdown formatting
|
||||
title = removeMarkdownFormatting(title)
|
||||
return title
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var title string
|
||||
for _, c := range strings.TrimLeft(mkd, "# ") {
|
||||
if strings.Contains("*~", string(c)) {
|
||||
continue
|
||||
}
|
||||
if string(c) == "\n" {
|
||||
break
|
||||
}
|
||||
title = title + string(c)
|
||||
}
|
||||
return title
|
||||
// removeMarkdownFormatting removes common markdown formatting from text
|
||||
func removeMarkdownFormatting(text string) string {
|
||||
// Remove **bold** and *italic* formatting
|
||||
result := text
|
||||
result = strings.ReplaceAll(result, "**", "")
|
||||
result = strings.ReplaceAll(result, "*", "")
|
||||
result = strings.ReplaceAll(result, "_", "")
|
||||
result = strings.ReplaceAll(result, "`", "")
|
||||
result = strings.ReplaceAll(result, "~~", "")
|
||||
|
||||
// Clean up multiple spaces
|
||||
result = strings.Join(strings.Fields(result), " ")
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func GenerateNoteID(path string) string {
|
||||
|
||||
Reference in New Issue
Block a user