Skip to content

Commit

Permalink
WIP Add log to md parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo-Hafsaoui committed Nov 24, 2024
1 parent 229cfd1 commit a2008bb
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions internal/adapters/input/markdown_tree_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
core "anemon/internal/core"
"errors"
"fmt"
"log/slog"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -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:]
}

0 comments on commit a2008bb

Please sign in to comment.