parse md file in separate func
This commit is contained in:
parent
5dc6ce8daa
commit
8f54b4d4bf
27
main.go
27
main.go
@ -82,8 +82,6 @@ func print_children(heading *heading, headings []heading) {
|
||||
}
|
||||
|
||||
func print_children_recursive(heading *heading, headings []heading) {
|
||||
//fmt.Printf("pointer of parent: %p\n", heading)
|
||||
|
||||
for index, _ := range headings {
|
||||
if headings[index].parent == heading {
|
||||
fmt.Printf("Child of parent %p: %s\n", heading, headings[index].text)
|
||||
@ -92,18 +90,16 @@ func print_children_recursive(heading *heading, headings []heading) {
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
file_content_raw, err := os.ReadFile(os.Args[1])
|
||||
func parse_file(file_name string) []heading {
|
||||
file_content_raw, err := os.ReadFile(file_name)
|
||||
|
||||
var headings []heading = nil
|
||||
var headings []heading
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var file_content string = string(file_content_raw)
|
||||
|
||||
file_lines := strings.Split(file_content, "\n")
|
||||
file_lines := strings.Split(string(file_content_raw), "\n")
|
||||
|
||||
for index, value := range file_lines {
|
||||
if is_heading(value) {
|
||||
@ -111,15 +107,18 @@ func main() {
|
||||
headings, heading{value, get_heading_level(value), (index + 1), nil})
|
||||
}
|
||||
}
|
||||
return headings
|
||||
}
|
||||
|
||||
func main() {
|
||||
file_name := os.Args[1]
|
||||
|
||||
var headings []heading = nil
|
||||
|
||||
headings = parse_file(file_name)
|
||||
|
||||
get_parents(headings)
|
||||
|
||||
// print all children that do not have a parent
|
||||
//print_children(nil, headings)
|
||||
|
||||
// print all children of the second header
|
||||
//print_children(&headings[1], headings)
|
||||
|
||||
print_children_recursive(nil, headings)
|
||||
|
||||
fmt.Printf("%v\n", headings)
|
||||
|
Reference in New Issue
Block a user