diff --git a/internal/adapters/input/markdown_tree_reader.go b/internal/adapters/input/markdown_tree_reader.go index 7fec5f2..8a0cf4c 100644 --- a/internal/adapters/input/markdown_tree_reader.go +++ b/internal/adapters/input/markdown_tree_reader.go @@ -4,6 +4,7 @@ import ( core "anemon/internal/core" "errors" "fmt" + "log/slog" "os" "path/filepath" "regexp" @@ -127,23 +128,33 @@ func parse_paragraphe(paragraph string) (core.Paragraphe, error) { // handleLine processes a line based on the number of leading hashtags func handleLine(n_paragraphe *core.Paragraphe, line string, nbHashtags int) error { - switch { - case nbHashtags > 0 && line[nbHashtags] != ' ': + if nbHashtags > 0 && line[nbHashtags] != ' '{ return fmt.Errorf("Err: cannot parse this md line {%s}, '#' should be followed by space", line) - case nbHashtags == 1: - n_paragraphe.H1 = line[nbHashtags+1:] - case nbHashtags == 2: - n_paragraphe.H2 = line[nbHashtags+1:] - case nbHashtags == 3: - n_paragraphe.H3 = line[nbHashtags+1:] - case nbHashtags == 4: - n_paragraphe.H4 = line[nbHashtags+1:] - case nbHashtags == 0 && len(line) > 1: - if strings.HasPrefix(line, "- ") { + } + switch nbHashtags { + case 1: + processesHeader(&n_paragraphe.H1,line,nbHashtags) + case 2: + processesHeader(&n_paragraphe.H2,line,nbHashtags) + case 3: + processesHeader(&n_paragraphe.H3,line,nbHashtags) + case 4: + processesHeader(&n_paragraphe.H4,line,nbHashtags) + case 0 : + if strings.HasPrefix(line, "- ") && len(line) > 1 { n_paragraphe.Items = append(n_paragraphe.Items, strings.TrimLeft(line, "- ")) } - case nbHashtags > 4: - return fmt.Errorf("Err: cannot parse this md line {%s}", line) + default: + return fmt.Errorf("cannot parse this md line {%s}", line) } return nil } + +//Affect to the Header the line without the `-` +func processesHeader (pt_header *string, line string, nbHashtags int){ + if *pt_header != ""{ + slog.Warn("Trying to overload Header","oldHeader", + *pt_header,"newHeader",line[nbHashtags+1:]) + } + *pt_header = line[nbHashtags+1:] +}