From dbae41fd8543696ef9f094373a2bbb9233c6714d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Mon, 23 Mar 2026 13:23:19 -0300 Subject: [PATCH] Minor fix in md2html. Better error report in XML loading. --- TODO.md | 2 -- src/eepp/ui/uiscenenode.cpp | 19 +++++++++++++++++++ src/thirdparty/md4c/md4c-html.c | 6 +++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index 8ae58927c..ffa966bfb 100644 --- a/TODO.md +++ b/TODO.md @@ -7,8 +7,6 @@ ## UI Module -* Implement a better DropDownList (model/view approach) - * Implement TableView and TreeView properties. * Add automatic font-fallback for lang scripts diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index a97b9e38d..dce59e127 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -443,6 +443,13 @@ void UISceneNode::setThreadPool( const std::shared_ptr& threadPool ) mThreadPool = threadPool; } +static std::string getErrorContext( size_t offset, std::string_view content ) { + static constexpr auto CONTEXT_LENGTH = 40; + std::size_t left = std::max( 0ul, offset - CONTEXT_LENGTH ); + std::size_t right = std::min( content.size(), offset + 40 ); + return std::string{ content.substr( left, right - left ) }; +} + UIWidget* UISceneNode::loadLayoutFromFile( const std::string& layoutPath, Node* parent, const Uint32& marker ) { if ( FileSystem::fileExists( layoutPath ) ) { @@ -456,6 +463,9 @@ UIWidget* UISceneNode::loadLayoutFromFile( const std::string& layoutPath, Node* Log::error( "Couldn't load UI Layout: %s", layoutPath.c_str() ); Log::error( "Error description: %s", result.description() ); Log::error( "Error offset: %d", result.offset ); + std::string data; + FileSystem::fileGet( layoutPath, data ); + Log::error( "Error context: %s", getErrorContext( result.offset, data ) ); } } else if ( PackManager::instance()->isFallbackToPacksActive() ) { std::string path( layoutPath ); @@ -493,6 +503,7 @@ UIWidget* UISceneNode::loadLayoutFromString( const char* layoutString, Node* par needsReplacements ? fixedLayout.c_str() : layoutString ); Log::error( "Error description: %s", result.description() ); Log::error( "Error offset: %d", result.offset ); + Log::error( "Error context: %s", getErrorContext( result.offset, layoutString ) ); } return NULL; @@ -529,6 +540,10 @@ UIWidget* UISceneNode::loadLayoutFromMemory( const void* buffer, Int32 bufferSiz needsReplacements ? fixedLayout.c_str() : layoutString.data() ); Log::error( "Error description: %s", result.description() ); Log::error( "Error offset: %d", result.offset ); + Log::error( "Error context: %s", + getErrorContext( result.offset, + std::string_view{ static_cast( buffer ), + static_cast( bufferSize ) } ) ); } return NULL; @@ -551,14 +566,17 @@ UIWidget* UISceneNode::loadLayoutFromStream( IOStream& stream, Node* parent, std::string fixedLayout; bool needsReplacements = voidTagsRegex.matches( scopedBuffer.get(), 0, nullptr, scopedBuffer.length() ); + std::string_view contents; if ( needsReplacements ) { fixedLayout = voidTagsRegex.gsub( layoutString.data(), "%1 />" ); result = doc.load_buffer( fixedLayout.c_str(), fixedLayout.size(), pugi::parse_default | pugi::parse_ws_pcdata ); + contents = fixedLayout; } else { result = doc.load_buffer( scopedBuffer.get(), scopedBuffer.length(), pugi::parse_default | pugi::parse_ws_pcdata ); + contents = std::string_view( scopedBuffer.get(), scopedBuffer.length() ); } if ( result ) { @@ -568,6 +586,7 @@ UIWidget* UISceneNode::loadLayoutFromStream( IOStream& stream, Node* parent, needsReplacements ? fixedLayout.c_str() : layoutString.data() ); Log::error( "Error description: %s", result.description() ); Log::error( "Error offset: %d", result.offset ); + Log::error( "Error context: %s", getErrorContext( result.offset, contents ) ); } return NULL; diff --git a/src/thirdparty/md4c/md4c-html.c b/src/thirdparty/md4c/md4c-html.c index 5229de541..4c1707717 100644 --- a/src/thirdparty/md4c/md4c-html.c +++ b/src/thirdparty/md4c/md4c-html.c @@ -285,10 +285,10 @@ render_open_li_block(MD_HTML* r, const MD_BLOCK_LI_DETAIL* det) { if(det->is_task) { RENDER_VERBATIM(r, "
  • " - "task_mark == 'x' || det->task_mark == 'X') - RENDER_VERBATIM(r, " checked"); - RENDER_VERBATIM(r, ">"); + RENDER_VERBATIM(r, " checked=\"true\""); + RENDER_VERBATIM(r, " />"); } else { RENDER_VERBATIM(r, "
  • "); }