From afbfa115160531e113a7935833a9d8a954f363c5 Mon Sep 17 00:00:00 2001 From: Mahmoud-Emad Date: Wed, 22 Oct 2025 21:31:49 +0300 Subject: [PATCH] refactor: Improve frontmatter and def parsing logic - Save content before modifying - Handle '*' character for defs correctly - Re-enable frontmatter parsing for '---' and '+++' - Re-enable frontmatter parsing for '---' and '+++' in paragraphs --- lib/data/markdown/elements/parser_paragraph.v | 22 +++++----- lib/data/markdown/parsers/parse_doc.v | 40 +++++++++---------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/lib/data/markdown/elements/parser_paragraph.v b/lib/data/markdown/elements/parser_paragraph.v index dbd7f906..17816a25 100644 --- a/lib/data/markdown/elements/parser_paragraph.v +++ b/lib/data/markdown/elements/parser_paragraph.v @@ -24,12 +24,13 @@ fn (mut paragraph Paragraph) paragraph_parse() ! { if mut llast is Def { if (char_ == '' || char_ == ' ' || char_ == '\n') && parser.char_prev() != '*' { if llast.content.len < 3 { + saved_content := llast.content paragraph.children.pop() mut llast2 := paragraph.children.last() if mut llast2 is Text { - llast2.content += llast.content + char_ + llast2.content += saved_content + char_ } else { - paragraph.text_new(mut paragraph.parent_doc(), llast.content + char_) + paragraph.text_new(mut paragraph.parent_doc(), saved_content + char_) } parser.next() char_ = '' @@ -46,15 +47,16 @@ fn (mut paragraph Paragraph) paragraph_parse() ! { } else if !(texttools.is_upper_text(char_) || char_ == '_') { // this means it wasn't a def, we need to add text // console.print_debug(' -- no def: ${char_}') + saved_content := llast.content paragraph.children.pop() // console.print_debug(' -- no def: ${paragraph.children.last()}') mut llast2 := paragraph.children.last() if mut llast2 is Text { llast2_content := llast2.content - llast2.content = llast2_content + llast.content + char_ + llast2.content = llast2_content + saved_content + char_ // llast2.content += llast.content + char_ } else { - paragraph.text_new(mut paragraph.parent_doc(), llast.content + char_) + paragraph.text_new(mut paragraph.parent_doc(), saved_content + char_) } parser.next() char_ = '' @@ -139,12 +141,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 ['