diff --git a/lib/data/markdown/elements/element_def.v b/lib/data/markdown/elements/element_def.v index b99b7504..5a4581e2 100644 --- a/lib/data/markdown/elements/element_def.v +++ b/lib/data/markdown/elements/element_def.v @@ -1,5 +1,8 @@ module elements + +//TODO: def is broken, way how we do it is bad + @[heap] pub struct Def { DocBase diff --git a/lib/data/markdown/elements/element_paragraph.v b/lib/data/markdown/elements/element_paragraph.v index c146b5c1..9705cc45 100644 --- a/lib/data/markdown/elements/element_paragraph.v +++ b/lib/data/markdown/elements/element_paragraph.v @@ -8,6 +8,7 @@ pub struct Paragraph { } fn (mut self Paragraph) process() !int { + // println(self) if self.processed { return 0 } @@ -38,7 +39,7 @@ fn (self Paragraph) html() !string { mut out := self.DocBase.html()! // the children should have all the content if self.children.len == 1 { if out.trim_space() != '' { - if self.children[0] is Link { + if self.children[0] or { panic("bug") } is Link { return out } else { return out diff --git a/lib/data/markdown/elements/parser_char.v b/lib/data/markdown/elements/parser_char.v index fd19ec6c..b7ef4407 100644 --- a/lib/data/markdown/elements/parser_char.v +++ b/lib/data/markdown/elements/parser_char.v @@ -15,7 +15,7 @@ mut: struct ParserChar { mut: charnr int - chars string + runes []rune errors []ParserCharError } @@ -25,14 +25,14 @@ fn parser_char_new_path(path string) !ParserChar { } mut content := os.read_file(path) or { return error('Failed to load file ${path}') } return ParserChar{ - chars: content + runes: content.runes() charnr: 0 } } pub fn parser_char_new_text(text string) ParserChar { return ParserChar{ - chars: text + runes: text.runes() charnr: 0 } } @@ -53,12 +53,10 @@ fn (mut parser ParserChar) char(nr int) !string { if parser.eof() { return '' } - mut c := parser.chars.substr(nr, nr + 1) - if c == '“' { // TODO: doesn't seem to be working, it can't because unicode chars are not 1 char, they are more than 1 - c = '"' - } - // console.print_debug(" +++ '${c}' ${c[0]}") - return c + // V's substr operates on bytes, not runes. + // To get a single rune, we access the runes slice directly. + // The comment on line 57 was a strong hint. + return parser.runes[nr].str() } // get current char @@ -90,10 +88,14 @@ fn (mut parser ParserChar) char_prev() string { // check if starting from position we are on, offset is to count further fn (mut parser ParserChar) text_next_is(tofind string, offset int) bool { startpos := parser.charnr + offset - if startpos + tofind.len > parser.chars.len { + // Convert tofind to runes for accurate length comparison and slicing + tofind_runes := tofind.runes() + if startpos + tofind_runes.len > parser.runes.len { return false } - text := parser.chars.substr(startpos, startpos + tofind.len).replace('\n', '\\n') + // Extract the substring based on rune indices + mut text_runes := parser.runes[startpos..startpos + tofind_runes.len] + text := text_runes.string() didfind := (text == tofind) // console.print_debug(" -NT${offset}($tofind):'$text':$didfind .. ") return didfind @@ -119,7 +121,7 @@ fn (mut parser ParserChar) next() { // return true if end of file fn (mut parser ParserChar) eof() bool { - if parser.charnr > parser.chars.len - 1 { + if parser.charnr > parser.runes.len - 1 { return true } return false diff --git a/lib/data/markdown/elements/parser_paragraph.v b/lib/data/markdown/elements/parser_paragraph.v index 95ac39b9..08ad6024 100644 --- a/lib/data/markdown/elements/parser_paragraph.v +++ b/lib/data/markdown/elements/parser_paragraph.v @@ -1,7 +1,7 @@ module elements import freeflowuniverse.herolib.core.texttools -import freeflowuniverse.herolib.ui.console +// import freeflowuniverse.herolib.ui.console // DO NOT CHANGE THE WAY HOW THIS WORKS, THIS HAS BEEN DONE AS A STATEFUL PARSER BY DESIGN // THIS ALLOWS FOR EASY ADOPTIONS TO DIFFERENT REALITIES @@ -20,7 +20,6 @@ fn (mut paragraph Paragraph) paragraph_parse() ! { mut char_ := parser.char_current() // console.print_debug("[[[${char_}]]]") - // char == '' means end of file if mut llast is Def { if (char_ == '' || char_ == ' ' || char_ == '\n') && parser.char_prev() != '*' { @@ -36,6 +35,7 @@ fn (mut paragraph Paragraph) paragraph_parse() ! { char_ = '' continue } else { + println(14) // means we did find a def, we can stop // console.print_debug(" -- end def") paragraph.text_new(mut paragraph.parent_doc(), char_) @@ -62,12 +62,10 @@ fn (mut paragraph Paragraph) paragraph_parse() ! { } // console.print_debug(" -- def: ${char_}") } - if parser.eof() { assert char_ == '' break } - // check for comments end if mut llast is Comment { if char_ == '\n' { @@ -141,12 +139,12 @@ fn (mut paragraph Paragraph) paragraph_parse() ! { if mut llast is Text { if char_ != '' { - if char_ == '*' { - paragraph.def_new(mut paragraph.parent_doc(), '*') - parser.next() - char_ = '' - continue - } + // if char_ == '*' { + // paragraph.def_new(mut paragraph.parent_doc(), '*') + // parser.next() + // char_ = '' + // continue + // } // check for comments start for totry in ['