...
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
module elements
|
||||
|
||||
|
||||
//TODO: def is broken, way how we do it is bad
|
||||
|
||||
@[heap]
|
||||
pub struct Def {
|
||||
DocBase
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ['<!--', '//'] {
|
||||
// TODO: this is a quick fix for now (https:// is being parsed as comment)
|
||||
|
||||
@@ -86,7 +86,7 @@ pub fn play(args_ PlayArgs) ! {
|
||||
if !path.ends_with('/') {
|
||||
path += '/'
|
||||
}
|
||||
println(' -- NEW PATH: ${path}')
|
||||
// println(' -- NEW PATH: ${path}')
|
||||
mypage.path = path
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -106,7 +106,7 @@ pub fn (mut site Site) page_add(args_ Page) ! {
|
||||
|
||||
pagefile.write(c)!
|
||||
|
||||
console.print_debug("Copy images in collection '${collection_name}' to ${pagefile.path_dir()}")
|
||||
// console.print_debug("Copy images in collection '${collection_name}' to ${pagefile.path_dir()}")
|
||||
|
||||
site.client.copy_images(collection_name, page_name, pagefile.path_dir()) or {
|
||||
return error("Couldn't copy images for '${page_name}' in collection '${collection_name}' using doctreeclient. Available pages:\n${site.client.list_markdown()!}\nError: ${err}")
|
||||
|
||||
Reference in New Issue
Block a user