#pragma once #include #include #include #include class GfxRenderer; /** * DictHtmlParser parses HTML dictionary definitions into ParsedText. * * Supports: * - Bold: , * - Italic: , * - Underline: , * - Lists:
    ,
  1. with numbering/bullets * - Block elements:

    ,
    ,


    , (entry separator) * - HTML entities: numeric (&#NNN;, &#xHHH;) and named (&, etc.) * - Superscript: rendered as ^text */ class DictHtmlParser { public: /** * Parse HTML definition and populate ParsedText with styled words. * Each paragraph/block creates a separate ParsedText via the callback. * * @param html The HTML definition text * @param fontId Font ID for text width calculations * @param renderer Reference to renderer for layout * @param onParagraph Callback invoked for each paragraph/block of text */ static void parse(const std::string& html, int fontId, const GfxRenderer& renderer, uint16_t viewportWidth, const std::function)>& onTextBlock); private: // Decode HTML entity at position i (starting with '&') static std::string decodeEntity(const std::string& html, size_t& i); // Extract tag name from position (after '<') static std::string extractTagName(const std::string& html, size_t start, bool& isClosing); // Check if tag is a block-level element static bool isBlockTag(const std::string& tagName); // Check if tag starts/ends bold static bool isBoldTag(const std::string& tagName); // Check if tag starts/ends italic static bool isItalicTag(const std::string& tagName); // Check if tag starts/ends underline static bool isUnderlineTag(const std::string& tagName); // Check if tag is superscript static bool isSuperscriptTag(const std::string& tagName); // Check if tag is list item static bool isListItemTag(const std::string& tagName); // Check if tag starts ordered list static bool isOrderedListTag(const std::string& tagName); };