Rich text intelligent processing method and device, network attached storage equipment and system
The text parser and structure conversion generate a lightweight data exchange structure, combined with component generation and rule analysis, solves the problem of insufficient functional scalability of Text components in the HarmonyOS NEXT system, realizes efficient rich text parsing and rendering, and improves user interaction experience.
Patent Information
- Application Number
- CN202510401655.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-01
- Publication Date
- 2025-07-29
AI Technical Summary
In the existing HarmonyOS NEXT system, the Text component's functional scalability, interactivity and customizability in rich text display and interaction are insufficient, and cannot meet the high requirements of complex text display and interaction experience.
Text parsing and structure conversion are performed through text parser to generate lightweight data exchange structures, combine component generation and rule analysis, support user interaction event processing, and realize efficient parsing and rendering of rich text.
It improves the efficiency of rich text parsing and rendering, enhances the response accuracy and rendering accuracy of user interaction experience, and supports the analysis of rich text in different formats and compatibility of Hongmeng system.
Smart Images

Figure CN120387436A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of rich text processing, and in particular to a rich text intelligent processing method, device, network attached storage device and system. Background Art
[0002] In the ArkUI framework of the HarmonyOS NEXT system (the native version of the HarmonyOS operating system), the existing Text component solution mainly focuses on the basic display function of text. This solution does support the rendering of single-line or multi-line text, as well as basic operations such as flexible adjustment of font styles and line break control, providing developers with basic text display capabilities. However, with the continuous expansion of application scenarios and the increasing growth of user requirements, the limitations of the existing Text components in terms of functional extensibility, interactivity, and customizability are gradually becoming prominent.
[0003] Especially in the complex application scenario of rich text display, the functions of the existing Text components are particularly insufficient. Rich text usually contains various rich elements such as multiple font styles, colors, pictures, links, etc., as well as complex typesetting and interaction requirements. However, the existing Text components are difficult to effectively support these advanced features and cannot meet the higher requirements of users for complex text display and interaction experiences. Summary of the Invention
[0004] The present invention provides a rich text intelligent processing method, device, network attached storage device and system, which can improve the parsing and rendering efficiency and accuracy of rich text, and at the same time improve the applicability of rich text processing.
[0005] To solve the above technical problems, in the first aspect of the present invention, a rich text intelligent processing method is disclosed. The method is applied to the HarmonyOS operating system, and the method includes:
[0006] Performing a first data processing operation on the obtained text to be processed according to a preset text parser to obtain a first data processing result corresponding to the text to be processed; the first data processing operation includes a text parsing operation, a structure conversion operation, and a tag attribute extraction operation. The structure conversion operation is used to convert the text parsing result obtained after performing the text parsing operation on the text to be processed into a lightweight data exchange structure that meets the preset data processing requirements; both the text parsing operation and the tag attribute extraction operation are used to determine the core text information of the text to be processed;
[0007] Perform a second data processing operation on the first data processing result to obtain a second data processing result corresponding to the first data processing result; the second data processing operation includes a structure traversal operation for the lightweight data exchange structure, and further includes a component generation operation for generating interface components that meet the preset rich text display requirements;
[0008] Perform a third data processing operation on the second data processing result to obtain a third data processing result corresponding to the second data processing result; the third data processing operation includes a rule parsing operation and an interface style adaptation operation for the interface components, and further includes a user interaction event processing operation; the user interaction event processing operation is used to add a listening and response function for user interaction events to the second data processing result;
[0009] Perform a combination of the first data processing result, the second data processing result, and the third data processing result, and output the target rich text data.
[0010] As an optional implementation manner, in the first aspect of the present invention, the performing a first data processing operation on the obtained text to be processed according to a preset text parser to obtain a first data processing result corresponding to the text to be processed includes:
[0011] Convert the obtained text to be processed into a plurality of target tags according to a preset text parser, and all the target tags include any one of the element, attribute, and text node of the text to be processed;
[0012] Construct a DOM tree corresponding to all the tags according to the text parser; the DOM tree includes a plurality of target nodes, and all the target nodes at least include element nodes, and further include text nodes and / or comment nodes;
[0013] Perform tag parsing on the text to be processed to obtain tag attributes corresponding to the text to be processed, and store the tag attributes in the element nodes to update the DOM tree;
[0014] Perform a structure conversion operation on the DOM tree to obtain a structure conversion result corresponding to the DOM tree as the first data processing result, and the structure conversion operation is used to convert the DOM tree into a JSON structure.
[0015] As an optional implementation manner, in the first aspect of the present invention, the converting the obtained text to be processed into a plurality of target tags according to a preset text parser includes:
[0016] According to a regular expression or a preset text parser, and based on preset text parameters, perform parameter recognition, parameter matching, and tag conversion on the obtained text to be processed in sequence, so as to obtain multiple target tags corresponding to the text to be processed and the text parameters;
[0017] And, the performing a structure conversion operation on the DOM tree to obtain a structure conversion result corresponding to the DOM tree includes:
[0018] Starting from the root node of the DOM tree, perform an access on all the target nodes on the DOM tree;
[0019] For each accessed target node, create a JSON object corresponding to the target node, and set the filling fields corresponding to the JSON object corresponding to the target node, where the filling fields are used to fill the node type, tag name, text content, and node attributes corresponding to the target node;
[0020] For each child node in the element node, recursively perform an operation of creating a JSON object corresponding to the child node and setting the filling fields corresponding to the JSON object corresponding to the child node, and add the JSON object corresponding to each child node to the target array corresponding to the parent node of the child node;
[0021] After determining that all the target nodes have been accessed and converted into JSON objects, determine the DOM tree after the conversion as the structure conversion result.
[0022] As an optional implementation manner, in the first aspect of the present invention, the performing a second data processing operation on the first data processing result to obtain a second data processing result corresponding to the first data processing result includes:
[0023] Perform a structure traversal on the first data processing result in a recursive or iterative manner;
[0024] During the process of performing a structure traversal on the first data processing result, identify the target filling fields corresponding to each target node to obtain the element type corresponding to the target node; the target filling fields include the node type or the tag name;
[0025] According to the element type corresponding to each target node, perform creation or filling of a data structure on a preset interface component to obtain component data corresponding to a target interface component to be generated; the target interface component is a HarmonyOS UI component;
[0026] Create a component instance corresponding to the first data processing result according to the component data, and update the node attributes and their corresponding attribute values in the filled fields corresponding to each target node to the component instance;
[0027] According to the parent-child relationship corresponding to each JSON object in the first data processing result, combine the component instance and a preset component decorator to construct a component tree corresponding to the target interface component as the second data processing result.
[0028] As an optional implementation manner, in the first aspect of the present invention, the performing a third data processing operation on the second data processing result to obtain a third data processing result corresponding to the second data processing result includes:
[0029] Perform a rule parsing operation on the second data processing result to obtain a rule parsing result corresponding to the second data processing result;
[0030] Fill the rule parsing result into the corresponding interface component to be filled, and perform an adaptation processing operation on the interface component to be filled to obtain a first interface component corresponding to the interface component to be filled; the adaptation processing operation includes at least one of version update check, style change, and style attribute change;
[0031] According to the user interaction requirements, add an event listener, a hyperlink component, and a user-defined component to the first interface component to obtain a second interface component as the third data processing result.
[0032] As an optional implementation manner, in the first aspect of the present invention, the performing a rule parsing operation on the second data processing result to obtain a rule parsing result corresponding to the second data processing result includes:
[0033] Determine a style information reading method for the second data processing result, where the style information reading method includes a first reading method based on a JSON structure and / or a second reading method based on a CSS file;
[0034] When the style information reading method includes the first reading method, perform parsing on the JSON structure in the second data processing result according to a JSON parsing library to obtain a target JSON object;
[0035] Perform style attribute or class name access and information extraction on the target JSON object according to a predefined key to obtain style attribute information and class name information corresponding to the target JSON object as the rule parsing result corresponding to the second data processing result;
[0036] When the style information reading method includes the second reading method, load the target CSS file to be analyzed, and parse the target CSS file to obtain a plurality of rule set objects corresponding to the target CSS file. Each rule set object includes a selector and a style declaration;
[0037] Perform class name parsing on the JSON structure in the second data processing result to obtain class name information corresponding to the JSON structure in the second data processing result;
[0038] For each of the rule set objects, match the selector included in the rule set object with the class name information to obtain target rule set objects that meet the preset matching requirements among all the rule set objects, and add the style attributes and style values included in the style declaration corresponding to the target rule set objects to the rule parsing result corresponding to the second data processing result.
[0039] As an optional implementation manner, in the first aspect of the present invention, the event listener is used to listen for user interaction events and respond to user interaction events. The user interaction events include clicking, long pressing, and hovering;
[0040] The hyperlink component is used to respond to the user's requirements corresponding to page jumps or URL jumps;
[0041] The custom component is used to respond to the user's requirement for custom binding of event callback functions.
[0042] The second aspect of the present invention discloses a rich text intelligent processing device. The device is applied to the HarmonyOS operating system, and the device includes:
[0043] A first data processing module, configured to perform a first data processing operation on the obtained text to be processed according to a preset text parser, to obtain a first data processing result corresponding to the text to be processed; the first data processing operation includes a text parsing operation, a structure conversion operation, and a tag attribute extraction operation. The structure conversion operation is used to convert the text parsing result obtained after performing the text parsing operation on the text to be processed into a lightweight data exchange structure that meets the preset data processing requirements; both the text parsing operation and the tag attribute extraction operation are used to determine the core text information of the text to be processed;
[0044] A second data processing module, configured to perform a second data processing operation on the first data processing result to obtain a second data processing result corresponding to the first data processing result; the second data processing operation includes a structure traversal operation for the lightweight data exchange structure, and further includes a component generation operation. The component generation operation is used to generate an interface component that meets the preset rich text display requirements;
[0045] A third data processing module, configured to perform a third data processing operation on the second data processing result to obtain a third data processing result corresponding to the second data processing result; the third data processing operation includes a rule parsing operation and an interface style adaptation operation for the interface component, and further includes a user interaction event processing operation; the user interaction event processing operation is configured to add a listening and response function for user interaction events to the second data processing result;
[0046] A text output module, configured to combine the first data processing result, the second data processing result, and the third data processing result, and output target rich text data.
[0047] As an optional implementation manner, in the second aspect of the present invention, the manner in which the first data processing module performs a first data processing operation on the obtained text to be processed according to a preset text parser to obtain a first data processing result corresponding to the text to be processed specifically includes:
[0048] Convert the obtained text to be processed into a plurality of target tags according to a preset text parser, and all the target tags include any one of the element, attribute, and text node of the text to be processed;
[0049] Construct a DOM tree corresponding to all the tags according to the text parser; the DOM tree includes a plurality of target nodes, and all the target nodes at least include element nodes, and further include text nodes and / or comment nodes;
[0050] Perform tag parsing on the text to be processed to obtain tag attributes corresponding to the text to be processed, and store the tag attributes in the element nodes to update the DOM tree;
[0051] Perform a structure conversion operation on the DOM tree to obtain a structure conversion result corresponding to the DOM tree as the first data processing result, and the structure conversion operation is used to convert the DOM tree into a JSON structure.
[0052] As an optional implementation manner, in the second aspect of the present invention, the manner in which the first data processing module converts the obtained text to be processed into a plurality of target tags according to a preset text parser specifically includes:
[0053] According to a regular expression or a preset text parser, with a preset text parameter as a reference, perform parameter recognition, parameter matching, and tag conversion on the obtained text to be processed in sequence to obtain a plurality of target tags corresponding to the text to be processed and the text parameter;
[0054] Moreover, the manner in which the first data processing module performs a structure conversion operation on the DOM tree to obtain a structure conversion result corresponding to the DOM tree specifically includes:
[0055] Starting from the root node of the DOM tree, access all the target nodes on the DOM tree;
[0056] For each accessed target node, create a JSON object corresponding to the target node, and set the filling fields corresponding to the JSON object corresponding to the target node. The filling fields are used to fill the node type, tag name, text content, and node attributes corresponding to the target node;
[0057] For each child node in the element node, recursively perform the operations of creating a JSON object corresponding to the child node and setting the filling fields corresponding to the JSON object corresponding to the child node, and add the JSON object corresponding to each child node to the target array corresponding to the parent node of the child node;
[0058] After determining that all the target nodes have been accessed and converted into JSON objects, determine the DOM tree that has completed the conversion as the structure conversion result.
[0059] As an optional implementation manner, in the second aspect of the present invention, the manner in which the second data processing module performs a second data processing operation on the first data processing result to obtain a second data processing result corresponding to the first data processing result specifically includes:
[0060] Perform a structure traversal on the first data processing result in a recursive or iterative manner;
[0061] During the process of performing the structure traversal on the first data processing result, identify the target filling fields corresponding to each target node to obtain the element type corresponding to the target node; the target filling fields include the node type or the tag name;
[0062] According to the element type corresponding to each target node, perform the creation or filling of the data structure on the preset interface component to obtain the component data corresponding to the target interface component to be generated; the target interface component is a HarmonyOS UI component;
[0063] Create a component instance corresponding to the first data processing result according to the component data, and update the node attributes and their corresponding attribute values in the filling fields corresponding to each target node to the component instance;
[0064] Construct a component tree corresponding to the target interface component as the second data processing result by combining the component instances and the preset component decorators according to the parent-child relationships corresponding to each JSON object in the first data processing result.
[0065] As an optional implementation manner, in the second aspect of the present invention, the manner in which the third data processing module performs a third data processing operation on the second data processing result to obtain a third data processing result corresponding to the second data processing result specifically includes:
[0066] Perform a rule parsing operation on the second data processing result to obtain a rule parsing result corresponding to the second data processing result;
[0067] Fill the rule parsing result into the corresponding interface component to be filled, and perform an adaptation processing operation on the interface component to be filled to obtain a first interface component corresponding to the interface component to be filled; the adaptation processing operation includes at least one of version update check, style change, and style attribute change;
[0068] Add an event listener, a hyperlink component, and a user-defined component to the first interface component according to the user interaction requirements to obtain a second interface component as the third data processing result.
[0069] As an optional implementation manner, in the second aspect of the present invention, the manner in which the third data processing module performs a rule parsing operation on the second data processing result to obtain a rule parsing result corresponding to the second data processing result specifically includes:
[0070] Determine a style information reading method for the second data processing result, where the style information reading method includes a first reading method based on a JSON structure and / or a second reading method based on a CSS file;
[0071] When the style information reading method includes the first reading method, parse the JSON structure in the second data processing result according to a JSON parsing library to obtain a target JSON object;
[0072] Perform style attribute or class name access and information extraction on the target JSON object according to a predefined key to obtain style attribute information and class name information corresponding to the target JSON object as the rule parsing result corresponding to the second data processing result;
[0073] When the style information reading method includes the second reading method, load a target CSS file to be analyzed and parse the target CSS file to obtain a plurality of rule set objects corresponding to the target CSS file, and each rule set object includes a selector and a style declaration;
[0074] Perform class name parsing on the JSON structure in the second data processing result to obtain class name information corresponding to the JSON structure in the second data processing result;
[0075] For each of the rule set objects, match the selector included in the rule set object with the class name information to obtain target rule set objects that meet the preset matching requirements among all the rule set objects, and add the style attributes and style values included in the style declaration corresponding to the target rule set objects to the rule parsing result corresponding to the second data processing result.
[0076] As an optional implementation manner, in the second aspect of the present invention, the event listener is used to listen for user interaction events and respond to user interaction events, and the user interaction events include clicking, long pressing, and hovering;
[0077] The hyperlink component is used to respond to the user's requirements for page jump or URL jump;
[0078] The custom component is used to respond to the user's requirement for custom binding of event callback functions.
[0079] The third aspect of the present invention discloses a network attached storage device, which is configured with a display screen and is used to interact and communicate with an electronic device, and the network attached storage device is used to execute the rich text intelligent processing method disclosed in the first aspect of the present invention.
[0080] The fourth aspect of the present invention discloses an electronic device, which includes:
[0081] A memory storing executable program code;
[0082] A processor coupled to the memory;
[0083] The processor calls the executable program code stored in the memory to execute the rich text intelligent processing method disclosed in the first aspect of the present invention.
[0084] The fifth aspect of the present invention discloses a computer storage medium, which stores computer instructions, and when the computer instructions are called, they are used to execute the rich text intelligent processing method disclosed in the first aspect of the present invention.
[0085] The sixth aspect of the present invention discloses a rich text intelligent processing system, which includes the rich text intelligent processing device disclosed in the second aspect of the present invention and a network attached storage device communicatively connected to the device; or,
[0086] The system includes an electronic device disclosed in the fourth aspect of the present invention, and a network attached storage device communicatively connected to the electronic device.
[0087] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0088] Implementing the present invention, through the text parser and structure conversion operation, it is possible to support the parsing of rich texts in different formats, improving the compatibility of text processing in the HarmonyOS; and, based on the structure traversal and component generation mechanism, it is possible to map rich text nodes to HarmonyOS native UI components, optimizing the rendering path and reducing the rendering overhead in complex text scenarios; and, through the rule parsing and interface style adaptation operation, it is possible to automatically match the design specifications of the HarmonyOS, further improving the rich text parsing efficiency and overall rendering accuracy; in addition, a processing module for user interaction events is also integrated, which can support flexible editing, style adjustment, and event listening of user texts, enhancing the user interaction experience while improving the response accuracy of this interaction function. BRIEF DESCRIPTION OF THE DRAWINGS
[0089] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required for description in the embodiments. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0090] Figure 1 is a schematic flowchart of a rich text intelligent processing method disclosed in an embodiment of the present invention;
[0091] Figure 2 is a schematic flowchart of another rich text intelligent processing method disclosed in an embodiment of the present invention;
[0092] Figure 3 is a schematic structural diagram of a rich text intelligent processing device disclosed in an embodiment of the present invention;
[0093] Figure 4 is a schematic structural diagram of a network attached storage device disclosed in an embodiment of the present invention;
[0094] Figure 5 is a schematic structural diagram of an electronic device disclosed in an embodiment of the present invention;
[0095] Figure 6 is a schematic structural diagram of a rich text intelligent processing system disclosed in an embodiment of the present invention;
[0096] Figure 7 is a schematic structural diagram of another rich text intelligent processing system disclosed in an embodiment of the present invention. Detailed implementation manners
[0097] To enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of the present invention.
[0098] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, device, product or terminal including a series of steps or units is not limited to the listed steps or units, but optionally further includes unlisted steps or units, or optionally further includes other steps or units inherent to these processes, methods, products or terminals.
[0099] Referring to "embodiments" herein means that the specific features, structures or characteristics described in connection with the embodiments can be included in at least one embodiment of the present invention. The phrase appears in various places in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.
[0100] The present invention discloses a rich text intelligent processing method, device, network attached storage device and system. Through text parsers and structure conversion operations, it can support the parsing of rich texts in different formats, improving the compatibility of text processing in the HarmonyOS system; and, based on structure traversal and component generation mechanisms, it can map rich text nodes to native HarmonyOS UI components, optimizing the rendering path and reducing the rendering overhead in complex text scenarios; and, through rule parsing and interface style adaptation operations, it can automatically match the design specifications of the HarmonyOS system, further improving the rich text parsing efficiency and overall rendering accuracy; in addition, it also integrates a processing module for user interaction events, which can support flexible editing of user text, style adjustment and event listening, enhancing the user interaction experience while improving the response accuracy of the interaction function. The following will be described in detail respectively.
[0101] Embodiment 1
[0102] Please refer to Figure 1 , Figure 1 which is a schematic flowchart of a rich text intelligent processing method disclosed in an embodiment of the present invention. Among them, Figure 1The described rich text intelligent processing method can be applied to the HarmonyOS, or can be applied to a rich text intelligent processing device. The embodiments of the present invention do not make limitations. For example, Figure 1 As shown, the rich text intelligent processing method may include the following operations:
[0103] 101. Perform a first data processing operation on the obtained text to be processed according to a preset text parser, and obtain a first data processing result corresponding to the text to be processed.
[0104] In the embodiments of the present invention, the structure conversion operation is used to convert the text parsing result corresponding to the text to be processed after performing the text parsing operation into a lightweight data exchange structure that meets the preset data processing requirements; both the text parsing operation and the tag attribute extraction operation are used to determine the core text information of the text to be processed.
[0105] In the embodiments of the present invention, the text to be processed may include text or strings corresponding to HLMT / Markdown / custom tags, etc.
[0106] In the embodiments of the present invention, according to the different types of the actually obtained text to be processed, the text parser can be dynamically called accordingly. Further, the text parser can be a DSL interpreter or an HTML Parser (HTML parser), and the embodiments of the present invention do not make limitations.
[0107] 102. Perform a second data processing operation on the first data processing result, and obtain a second data processing result corresponding to the first data processing result.
[0108] In the embodiments of the present invention, the second data processing operation includes a structure traversal operation for the above lightweight data exchange structure, and further includes a component generation operation, and the component generation operation is used to generate an interface component that meets the preset rich text display requirements.
[0109] In the embodiments of the present invention, in actual application, step 102 can be performed by setting a JSON Processor (JSON processor) and a Component Generator (component generator).
[0110] In the embodiments of the present invention, the JSON processor is used to perform the structure traversal operation; the component generator is used to perform the component generation operation.
[0111] 103. Perform a third data processing operation on the second data processing result, and obtain a third data processing result corresponding to the second data processing result.
[0112] In an embodiment of the present invention, the third data processing operation includes a rule parsing operation and an interface style adaptation operation for the above interface component, and further includes a user interaction event processing operation; the user interaction event processing operation is used to add a listening and response function for user interaction events to the second data processing result.
[0113] In an embodiment of the present invention, in practical applications, step 103 can be executed by setting a Style&Attribute Processor (style processor) and an Event Handler (event processor). Among them, the component generator is used to execute
[0114] In an embodiment of the present invention, the style processor is used to execute the rule parsing operation and the interface style adaptation operation; the event processor is used to execute the user interaction event processing operation.
[0115] 104. Combine the first data processing result, the second data processing result, and the third data processing result, and output the target rich text data.
[0116] In an embodiment of the present invention, for any text to be processed, in practical applications, as described above, by setting an HTML parser, a JSON processor, a component generator, a style processor, and a style processor, it is possible to perform intelligent rich text processing on the text to be processed by components and layers. Subsequently, finally, by combining the 5 components, rich text data / rich text content corresponding to the text to be processed is output.
[0117] In an embodiment of the present invention, the above rich text intelligent processing method is based on the conventional UgRichText component and integrates the above-mentioned multiple components.
[0118] It can be seen that implementing Figure 1 the described rich text intelligent processing method, through the text parser and the structure conversion operation, can support the parsing of rich text in different formats, improving the compatibility of text processing in the HarmonyOS system; and, based on the structure traversal and component generation mechanism, can map rich text nodes to HarmonyOS native UI components, optimizing the rendering path and reducing the rendering overhead in complex text scenarios; and, through the rule parsing and interface style adaptation operations, can automatically match the design specifications of the HarmonyOS system, further improving the rich text parsing efficiency and the overall rendering accuracy; in addition, it also integrates a processing module for user interaction events, which can support flexible editing, style adjustment, and event listening of user text, enhancing the user interaction experience while improving the response accuracy of the interaction function.
[0119] In an alternative embodiment, the manner in which the above step 101 performs a first data processing operation on the obtained text to be processed according to a preset text parser to obtain a first data processing result corresponding to the text to be processed specifically includes:
[0120] According to the preset text parser, the obtained text to be processed is converted into a plurality of target tokens, and all target tokens include any one of the element, attribute, and text node of the text to be processed;
[0121] According to the text parser, a DOM tree corresponding to all tokens is constructed; the DOM tree includes a plurality of target nodes, and all target nodes include at least element nodes, and also include text nodes and / or comment nodes;
[0122] Perform tag parsing on the text to be processed to obtain tag attributes corresponding to the text to be processed, and store the tag attributes in the element nodes to update the DOM tree;
[0123] Perform a structure conversion operation on the DOM tree to obtain a structure conversion result corresponding to the DOM tree as the first data processing result, and this structure conversion operation is used to convert the DOM tree into a JSON structure.
[0124] In this alternative embodiment, taking the text to be processed as an HTML text as an example, an HTML parser instance can be created in advance to process the input HTML text, or an existing HTML parsing library (such as Jsoup, BeautifulSoup, lxml, etc.) can be selected to simplify the parsing process; then, read the HTML text from a file, network request, or string.
[0125] It can be seen that in this alternative embodiment, the text to be processed is converted into a plurality of target tokens through a preset text parser, and a corresponding DOM tree is constructed, and the tag attributes are further parsed and stored in the element nodes, and finally the DOM tree is converted into a JSON structure of the first data processing result, realizing the efficient and structured processing of the text to be processed, that is, it is beneficial to improve the process processing efficiency and processing accuracy of rich text.
[0126] In another alternative embodiment, the manner in which the above-mentioned method of converting the obtained text to be processed into a plurality of target tokens according to a preset text parser specifically includes:
[0127] According to a regular expression or a preset text parser, based on a preset text parameter, perform parameter recognition, parameter matching, and token conversion on the obtained text to be processed in sequence to obtain a plurality of target tokens corresponding to the text to be processed and the text parameter;
[0128] In this alternative embodiment, specifically, a regular expression or a dedicated HTML parser is used to identify and match tags, attributes, and text nodes in the HTML text; subsequently, the matched HTML elements, attributes, text nodes, etc. are converted into a series of tokens. These tokens serve as the basic units for subsequent processing by the parser.
[0129] Further, after the text to be processed obtained is converted into multiple target tokens according to the preset text parser, the method further includes:
[0130] Initialize a tag stack;
[0131] When a new start tag is detected, push the new start tag onto the tag stack to track the new start tag;
[0132] When an end tag is encountered, pop the start tag that matches the end tag from the tag stack.
[0133] By setting the mechanism of the tag stack, tag maintenance is thus performed.
[0134] In this alternative embodiment, the manner of performing tag parsing on the text to be processed to obtain the tag attributes corresponding to the text to be processed specifically includes:
[0135] Determine multiple tag nodes of the text to be processed and the tag names corresponding to each tag node (such as , , etc.);
[0136] Extract all attributes (such as href, style, class) of each tag node and their corresponding values;
[0137] Optionally, when each tag node includes text content, synchronously extract the text content corresponding to the tag node.
[0138] In this optional embodiment, and, the manner of performing a structure conversion operation on the DOM tree to obtain a structure conversion result corresponding to the DOM tree specifically includes:
[0139] Starting from the root node of the DOM tree, perform access on all target nodes on the DOM tree;
[0140] For each accessed target node, create a JSON object corresponding to the target node, and set the filling fields corresponding to the JSON object corresponding to the target node. The filling fields are used to fill the node type, tag name, text content, and node attributes corresponding to the target node;
[0141] For each child node in the element node, recursively perform the operations of creating a JSON object corresponding to the child node and setting the filling fields corresponding to the JSON object corresponding to the child node, and add the JSON object corresponding to each child node to the target array corresponding to the parent node of the child node;
[0142] After determining that all target nodes have been accessed and converted into JSON objects, determine the completed converted DOM tree as the structure conversion result.
[0143] It can be seen that in this optional embodiment, by using a regular expression or a preset text parser, the text to be processed is accurately converted into multiple target tags, improving the efficiency of parameterizing the text to be processed; subsequently, starting from the root node of the DOM tree, all target nodes are recursively accessed and converted into JSON objects, while filling in key information such as node type, tag name, text content, and node attributes, and finally structured JSON format data is obtained as the conversion result, greatly improving the processing efficiency and usability of text data.
[0144] In another optional embodiment, the manner of performing a second data processing operation on the first data processing result to obtain a second data processing result corresponding to the first data processing result specifically includes:
[0145] Perform a structure traversal on the first data processing result in a recursive or iterative manner;
[0146] During the process of performing a structural traversal on the first data processing result, identify the target filling fields corresponding to each target node to obtain the element type corresponding to the target node; the target filling fields include node types or tag names;
[0147] According to the element type corresponding to each target node, perform the creation or filling of the data structure on the preset interface component to obtain the component data corresponding to the target interface component to be generated; the target interface component is a HarmonyOS UI component;
[0148] Create a component instance corresponding to the first data processing result according to the component data, and update the node attributes and their corresponding attribute values in the filling fields corresponding to each target node to the component instance;
[0149] According to the parent-child relationship corresponding to each JSON object in the first data processing result, combine the component instance and the preset component decorator to construct a component tree corresponding to the target interface component as the second data processing result.
[0150] In this optional embodiment, perform a structural traversal on the first data processing result (usually structured JSON data) in a recursive or iterative manner. During the traversal process, identify the target filling fields corresponding to each target node, such as node types or tag names, so as to determine the element type corresponding to the target node. This step realizes the automatic mapping from structured data to UI component types, providing a basis for subsequent component creation and filling.
[0151] In this optional embodiment, according to the identified element type, it is possible to perform the creation or filling operation of the data structure on the preset interface component to obtain the target interface component and its corresponding component data. Since the target interface component is a HarmonyOS UI component, this step ensures the compatibility of the generated component with the HarmonyOS operating system, and at the same time supports the ability of dynamic creation of components and filling according to data content.
[0152] In this optional embodiment, create a component instance corresponding to the first data processing result, and update the node attributes and their corresponding attribute values in the filling fields to the component instance. This step ensures that the attributes of the component instance are consistent with the attributes in the data source, enabling the component to accurately reflect the information in the data source and improving the accuracy and reliability of the UI.
[0153] In this alternative embodiment, the component decorator can be the @Extend decorator, which can customize styles such as font, color, background, border, line spacing, alignment, etc., and supports CSS parsing. Moreover, according to the parent-child relationships corresponding to each JSON object in the first data processing result, it is possible to combine the component instances and the preset component decorators to construct a component tree corresponding to the component instances. This step realizes the hierarchical organization of components, making the generated UI interface have a clear hierarchical structure and good readability, while supporting complex UI layouts and interactions.
[0154] It can be seen that in this alternative embodiment, through the specific manner of performing the second data processing operation on the first data processing result, the automatic mapping from structured data to UI components is realized. At the same time, it also supports the dynamic creation and filling of HarmonyOS UI components, ensures the consistency between component instances and data sources, and constructs a component tree with a hierarchical structure. Through the setting of this step, the development efficiency and code maintainability are improved.
[0155] Embodiment 2
[0156] Please refer to Figure 2 , Figure 2 is a schematic flowchart of another rich text intelligent processing method disclosed in an embodiment of the present invention. Among them, Figure 2 the described rich text intelligent processing method can be applied to the HarmonyOS operating system or a rich text intelligent processing device, and the embodiments of the present invention do not make any limitations. As Figure 2 shown, the rich text intelligent processing method may include the following operations:
[0157] 201. Perform a first data processing operation on the obtained text to be processed according to a preset text parser, and obtain a first data processing result corresponding to the text to be processed.
[0158] 202. Perform a second data processing operation on the first data processing result to obtain a second data processing result corresponding to the first data processing result.
[0159] 203. Perform a rule parsing operation on the second data processing result to obtain a rule parsing result corresponding to the second data processing result.
[0160] 204. Fill the rule parsing result into the corresponding interface component to be filled, and perform an adaptation processing operation on the interface component to be filled to obtain a first interface component corresponding to the interface component to be filled.
[0161] In an embodiment of the present invention, the adaptation processing operation includes at least one of version update check, style change, and style attribute change.
[0162] In an embodiment of the present invention, after filling the rule parsing result into the corresponding interface component to be filled, it is necessary to check the current version information of the interface component to be filled. If there is a version update, style change, style attribute change, etc., the corresponding update and adaptation are automatically performed. For example, it is necessary to adapt the compatible style of HarmonyOS Next.
[0163] 205. According to the user interaction requirements, add an event listener, a hyperlink component, and a user-defined component to the first interface component to obtain a second interface component as a third data processing result.
[0164] In an embodiment of the present invention, the event listener is used to listen for user interaction events and respond to user interaction events. The user interaction events include click, long press, and hover;
[0165] The hyperlink component is used to respond to the user's page jump or URL jump corresponding requirements;
[0166] The custom component is used to respond to the user's custom binding requirements for executing event callback functions.
[0167] 206. Combine the first data processing result, the second data processing result, and the third data processing result, and output the target rich text data.
[0168] In the embodiments of the present invention, for other descriptions of steps 201-step 202 and step 206, please refer to the specific descriptions of steps 101-step 102 and step 104 in Embodiment 1 of the present invention, and the embodiments of the present invention will not be elaborated herein.
[0169] It can be seen that in the Figure 2 described rich text intelligent processing method, by performing further rule parsing operations on the second data processing result (usually the initially processed rich text data), it is possible to intelligently identify and understand specific rules or format requirements in the rich text, thereby facilitating the improvement of the accuracy of subsequent rich text processing; and, it is possible to fill the rule parsing result into the corresponding interface component to be filled and perform an adaptation processing operation on the interface component to be filled. The setting of this step ensures that the rich text content can be correctly and beautifully displayed on the interface components in the HarmonyOS operating system; at the same time, the setting of this adaptation processing operation enables the interface components to be flexibly adjusted as the HarmonyOS operating system is updated or the user's needs change, maintaining the compatibility of the interface and the consistency of the user experience; in addition, event listeners, hyperlink components, and user-defined components can also be added to the first interface component according to the user interaction requirements to obtain the second interface component (i.e., the third data processing result). The setting of this step enables the rich text interface not only to display information but also to respond to user interaction operations such as clicks and swipes, which is conducive to improving the user's sense of participation and satisfaction in using the rich text processing function.
[0170] In an optional embodiment, the manner in which the above step 203 performs a rule parsing operation on the second data processing result to obtain a rule parsing result corresponding to the second data processing result specifically includes:
[0171] Determine the style information reading method for the second data processing result. The style information reading method includes a first reading method based on a JSON structure and / or a second reading method based on a CSS file;
[0172] When the style information reading method includes the first reading method, parse the JSON structure in the second data processing result according to a JSON parsing library to obtain a target JSON object;
[0173] Access and extract style attributes or class names from the target JSON object according to predefined keys to obtain style attribute information and class name information corresponding to the target JSON object as the rule parsing result corresponding to the second data processing result;
[0174] In this optional embodiment, the predefined key may be style or className; the style attribute information may include style attributes and their corresponding attribute values. For example, the style attributes may be color, fontSize, etc. Further, the corresponding attribute values of the style attributes are red and 16px respectively.
[0175] In this optional embodiment, when the style information reading method includes the second reading method, load the target CSS file to be analyzed and parse the target CSS file to obtain multiple rule set objects corresponding to the target CSS file. Each rule set object includes a selector and a style declaration.
[0176] Perform class name parsing on the JSON structure in the second data processing result to obtain class name information corresponding to the JSON structure in the second data processing result.
[0177] For each rule set object, match the selector included in the rule set object with the class name information to obtain the target rule set object that meets the preset matching requirements among all rule set objects, and add the style attributes and style values included in the style declaration corresponding to the target rule set object to the rule parsing result corresponding to the second data processing result.
[0178] It can be seen that in this optional embodiment, multiple reading methods for the second data processing result are set, enabling the rich text processing to flexibly adapt to style information from different sources and formats, improving the compatibility and adaptability of the rich text processing method; and the two set style information reading methods ensure the accuracy and integrity of the style information, providing a reliable basis for subsequent rich text rendering and processing.
[0179] Embodiment III
[0180] Please refer to Figure 3 , Figure 3 which is a schematic structural diagram of a rich text intelligent processing device disclosed in an embodiment of the present invention. Among them, the rich text intelligent processing device may be applied to the HarmonyOS system. As Figure 3 shown, the rich text intelligent processing device may include a first data processing module 301, a second data processing module 302, a third data processing module 303, and a text output module 304, where:
[0181] The first data processing module 301 is configured to perform a first data processing operation on the obtained text to be processed according to a preset text parser, and obtain a first data processing result corresponding to the text to be processed; the first data processing operation includes a text parsing operation, a structure conversion operation, and a tag attribute extraction operation. The structure conversion operation is used to convert the text parsing result obtained after performing the text parsing operation on the text to be processed into a lightweight data exchange structure that meets the preset data processing requirements; both the text parsing operation and the tag attribute extraction operation are used to determine the core text information of the text to be processed.
[0182] The second data processing module 302 is configured to perform a second data processing operation on the first data processing result to obtain a second data processing result corresponding to the first data processing result; the second data processing operation includes a structure traversal operation for the above lightweight data exchange structure, and also includes a component generation operation, and the component generation operation is used to generate an interface component that meets the preset rich text display requirements.
[0183] The third data processing module 303 is configured to perform a third data processing operation on the second data processing result to obtain a third data processing result corresponding to the second data processing result; the third data processing operation includes a rule parsing operation and an interface style adaptation operation for the above interface component, and also includes a user interaction event processing operation; the user interaction event processing operation is used to add a listening and response function for user interaction events to the second data processing result.
[0184] The text output module 304 is configured to combine the first data processing result, the second data processing result, and the third data processing result, and output the target rich text data.
[0185] It can be seen that implementing Figure 3 the described rich text intelligent processing device, through the text parser and the structure conversion operation, can support the parsing of rich texts in different formats, improving the compatibility of text processing in the HarmonyOS system; and, based on the structure traversal and component generation mechanism, can map rich text nodes to HarmonyOS native UI components, optimizing the rendering path and reducing the rendering overhead in complex text scenarios; and, through the rule parsing and interface style adaptation operations, can automatically match the design specifications of the HarmonyOS system, further improving the rich text parsing efficiency and overall rendering accuracy; in addition, it also integrates a user interaction event processing module, which can support flexible user text editing, style adjustment, and event listening, enhancing the user interaction experience while improving the response accuracy of the interaction function.
[0186] In an optional embodiment, the manner in which the first data processing module 301 performs the first data processing operation on the obtained text to be processed according to a preset text parser to obtain a first data processing result corresponding to the text to be processed specifically includes:
[0187] Convert the obtained text to be processed into multiple target tokens according to a preset text parser. All target tokens include any one of the elements, attributes, and text parameters in the text node of the text to be processed.
[0188] Construct a DOM tree corresponding to all tokens according to the text parser. The DOM tree includes multiple target nodes. All target nodes include at least element nodes, and also include text nodes and / or comment nodes.
[0189] Perform tag parsing on the text to be processed to obtain the tag attributes corresponding to the text to be processed, and store the tag attributes in the element nodes to update the DOM tree.
[0190] Perform a structure conversion operation on the DOM tree to obtain a structure conversion result corresponding to the DOM tree as the first data processing result. This structure conversion operation is used to convert the DOM tree into a JSON structure.
[0191] It can be seen that in this optional embodiment, the text to be processed is converted into multiple target tokens through a preset text parser, and the corresponding DOM tree is constructed. Then, the tag attributes are further parsed and stored in the element nodes. Finally, the DOM tree is converted into the first data processing result in JSON structure, realizing the efficient and structured processing of the text to be processed. That is, it is beneficial to improve the processing efficiency and accuracy of rich text.
[0192] In another optional embodiment, the manner in which the first data processing module 301 converts the obtained text to be processed into multiple target tokens according to a preset text parser specifically includes:
[0193] According to a regular expression or a preset text parser, taking the preset text parameters as a reference, perform parameter recognition, parameter matching, and token conversion on the obtained text to be processed in sequence to obtain multiple target tokens corresponding to the text to be processed and the text parameters.
[0194] Moreover, the manner in which the first data processing module 301 performs a structure conversion operation on the DOM tree to obtain a structure conversion result corresponding to the DOM tree specifically includes:
[0195] Starting from the root node of the DOM tree, access all target nodes on the DOM tree.
[0196] For each accessed target node, create a JSON object corresponding to the target node, and set the filling fields corresponding to the JSON object corresponding to the target node. The filling fields are used to fill the node type, tag name, text content, and node attributes corresponding to the target node.
[0197] For each child node in the element node, recursively perform operations of creating a JSON object corresponding to the child node and setting the filling fields corresponding to the JSON object corresponding to the child node for the child node, and add the JSON object corresponding to each child node to the target array corresponding to the parent node of the child node;
[0198] After determining that all target nodes have been visited and converted into JSON objects, determine the DOM tree after conversion as the structure conversion result.
[0199] It can be seen that in this alternative embodiment, through regular expressions or preset text parsers, the text to be processed is accurately converted into multiple target tags, improving the efficiency of parameterization of the text to be processed; subsequently, starting from the DOM tree root node, all target nodes are recursively visited and converted into JSON objects, while filling in key information such as node type, tag name, text content, and node attributes. Finally, structured JSON format data is obtained as the conversion result, greatly improving the processing efficiency and usability of text data.
[0200] In another alternative embodiment, the specific manner in which the second data processing module 302 performs a second data processing operation on the first data processing result to obtain a second data processing result corresponding to the first data processing result includes:
[0201] Perform a structure traversal on the first data processing result in a recursive or iterative manner;
[0202] During the process of performing a structure traversal on the first data processing result, identify the target filling fields corresponding to each target node to obtain the element type corresponding to the target node; the target filling fields include the node type or the tag name;
[0203] According to the element type corresponding to each target node, create or fill the data structure of the preset interface component to obtain the component data corresponding to the target interface component to be generated; the target interface component is a HarmonyOS UI component;
[0204] Create a component instance corresponding to the first data processing result according to the component data, and update the node attributes and their corresponding attribute values in the filling fields corresponding to each target node to the component instance;
[0205] According to the parent-child relationship corresponding to each JSON object in the first data processing result, combine the component instance and the preset component decorator to construct a component tree corresponding to the target interface component as the second data processing result.
[0206] It can be seen that in this alternative embodiment, through the specific manner of performing the second data processing operation on the first data processing result, the automatic mapping from structured data to UI components is achieved. At the same time, it also supports the dynamic creation and population of HarmonyOS UI components, ensures the consistency between component instances and data sources, and constructs a component tree with a hierarchical structure. Through the setting of this step, the development efficiency and code maintainability are improved.
[0207] In another alternative embodiment, the manner in which the third data processing module 303 performs a third data processing operation on the second data processing result to obtain a third data processing result corresponding to the second data processing result specifically includes:
[0208] Performing a rule parsing operation on the second data processing result to obtain a rule parsing result corresponding to the second data processing result;
[0209] Filling the rule parsing result into the corresponding interface component to be filled, and performing an adaptation processing operation on the interface component to be filled to obtain a first interface component corresponding to the interface component to be filled; the adaptation processing operation includes at least one of version update check, style change, and style attribute change;
[0210] According to the user interaction requirements, adding an event listener, a hyperlink component, and a user-defined component to the first interface component to obtain a second interface component as the third data processing result.
[0211] In this alternative embodiment, the event listener is used to monitor user interaction events and respond to user interaction events, and the user interaction events include click, long press, and hover;
[0212] The hyperlink component is used to respond to the user's page jump or URL jump corresponding requirements;
[0213] The custom component is used to respond to the user's requirement for custom binding of event callback functions.
[0214] It can be seen that in this alternative embodiment, by performing further rule parsing operations on the second data processing result (usually the rich text data that has been preliminarily processed), specific rules or format requirements in the rich text can be intelligently identified and understood, which is conducive to improving the accuracy of subsequent rich text processing; and, the rule parsing result can be filled into the corresponding interface component to be filled, and an adaptation processing operation is performed on the interface component to be filled. This setting ensures that the rich text content can be correctly and beautifully displayed on the interface components in the HarmonyOS; at the same time, the setting of this adaptation processing operation enables the interface component to be flexibly adjusted as the HarmonyOS is updated or the user's needs change, maintaining the compatibility of the interface and the consistency of the user experience; in addition, event listeners, hyperlink components, and user-defined components can be added to the first interface component according to the user interaction requirements to obtain a second interface component (i.e., the third data processing result). This setting enables the rich text interface to not only display information but also respond to user interaction operations such as clicks and swipes, which is conducive to improving the user's sense of participation and satisfaction in using the rich text processing function.
[0215] In yet another alternative embodiment, the manner in which the third data processing module 303 performs a rule parsing operation on the second data processing result to obtain a rule parsing result corresponding to the second data processing result specifically includes:
[0216] Determine a style information reading method for the second data processing result. The style information reading method includes a first reading method based on a JSON structure and / or a second reading method based on a CSS file;
[0217] When the style information reading method includes the first reading method, parse the JSON structure in the second data processing result according to a JSON parsing library to obtain a target JSON object;
[0218] Perform style attribute or class name access and information extraction on the target JSON object according to predefined keys to obtain style attribute information and class name information corresponding to the target JSON object as the rule parsing result corresponding to the second data processing result;
[0219] When the style information reading method includes the second reading method, load the target CSS file to be analyzed and parse the target CSS file to obtain multiple rule set objects corresponding to the target CSS file. Each rule set object includes a selector and a style declaration;
[0220] Perform class name parsing on the JSON structure in the second data processing result to obtain class name information corresponding to the JSON structure in the second data processing result;
[0221] For each rule set object, match the selectors and class name information included in the rule set object to obtain the target rule set objects that meet the preset matching requirements among all rule set objects, and add the style attributes and style values included in the style declarations corresponding to the target rule set objects to the rule parsing result corresponding to the second data processing result.
[0222] It can be seen that in this optional embodiment, multiple reading methods for the second data processing result are set, enabling the rich text processing to flexibly adapt to style information from different sources and formats, improving the compatibility and adaptability of the rich text processing method; moreover, the two set style information reading methods ensure the accuracy and integrity of the style information, providing a reliable basis for subsequent rich text rendering and processing.
[0223] Embodiment Four
[0224] Please refer to Figure 4 , Figure 4 which is a schematic structural diagram of a network attached storage device disclosed in an embodiment of the present invention. As Figure 4 shown, the network attached storage device is configured with a display screen and is used for interactive communication with an electronic device. Among them, the network attached storage device is used to execute the steps in the rich text intelligent processing method described in Embodiment One or Embodiment Two of the present invention.
[0225] In an embodiment of the present invention, the network attached storage device is dedicated to storing network data and can perform operations such as uploading, centralized storage, data sharing, backup, and recovery on the interaction data generated when executing the steps in the rich text intelligent processing method described in Embodiment One or Embodiment Two of the present invention; the network attached storage device can also support multimedia services; among them, the interaction data includes data such as the to-be-processed text, the first data processing result, the second data processing result, the third data processing result, and the target rich text data described above.
[0226] Embodiment Five
[0227] Please refer to Figure 5 , Figure 5 which is a schematic structural diagram of an electronic device disclosed in an embodiment of the present invention. As Figure 5 shown, the electronic device may include:
[0228] A memory 401 storing executable program code;
[0229] A processor 402 coupled to the memory 401;
[0230] The processor 402 calls the executable program code stored in the memory 401 and executes the steps in the rich text intelligent processing method described in Embodiment 1 or Embodiment 2 of the present invention.
[0231] Embodiment 6
[0232] Embodiment of the present invention discloses a computer storage medium storing computer instructions which, when called, are used to execute the steps in the rich text intelligent processing method described in Embodiment 1 or Embodiment 2 of the present invention.
[0233] Embodiment 7
[0234] Please refer to Figure 6 , Figure 6 which is a schematic structural diagram of a rich text intelligent processing system disclosed in an embodiment of the present invention. As Figure 6 shown, the system includes the rich text intelligent processing device disclosed in Embodiment 3 of the present invention and a network attached storage device communicatively connected to the device; or,
[0235] Please refer to Figure 7 , Figure 7 which is a schematic structural diagram of another rich text intelligent processing system disclosed in an embodiment of the present invention. As Figure 7 shown, the system includes the electronic device disclosed in Embodiment 5 of the present invention and a network attached storage device communicatively connected to the electronic device.
[0236] Embodiment 8
[0237] Embodiment of the present invention discloses a computer program product which includes a non-transitory computer storage medium storing a computer program, and the computer program is operable to cause a computer to execute the steps in the rich text intelligent processing method described in Embodiment 1 or Embodiment 2.
[0238] The above-described device / system-side embodiments are merely illustrative. The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed to multiple network modules. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative labor.
[0239] Through the specific descriptions of the above embodiments, those skilled in the art can clearly understand that each implementation can be realized by means of software plus a necessary general hardware platform, and of course, it can also be realized by hardware. Based on such an understanding, the essence of the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer storage medium, and the storage medium includes read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc memories, magnetic disk memories, tape memories, or any other computer-readable medium that can be used to carry or store data.
[0240] Finally, it should be noted that: What is disclosed in an intelligent rich text processing method, device, network attached storage device and system according to the embodiments of the present invention is only the preferred embodiments of the present invention, which are only used to illustrate the technical solutions of the present invention, rather than to limit them; Although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for intelligent processing of rich text, characterized in that, The method is applied to the HarmonyOS, and the method includes: Performing a first data processing operation on the obtained text to be processed according to a preset text parser to obtain a first data processing result corresponding to the text to be processed; the first data processing operation includes a text parsing operation, a structure conversion operation, and a label attribute extraction operation, and the structure conversion operation is used to convert the text parsing result corresponding to the text to be processed after performing the text parsing operation into a lightweight data exchange structure that meets the preset data processing requirements; both the text parsing operation and the label attribute extraction operation are used to determine the core text information of the text to be processed; Performing a second data processing operation on the first data processing result to obtain a second data processing result corresponding to the first data processing result; the second data processing operation includes a structure traversal operation for the lightweight data exchange structure, and further includes a component generation operation, and the component generation operation is used to generate an interface component that meets the preset rich text display requirements; Performing a third data processing operation on the second data processing result to obtain a third data processing result corresponding to the second data processing result; the third data processing operation includes a rule parsing operation and an interface style adaptation operation for the interface component, and further includes a user interaction event processing operation; the user interaction event processing operation is used to add a listening and response function for user interaction events to the second data processing result; Combining the first data processing result, the second data processing result, and the third data processing result, and outputting target rich text data.
2. The rich text intelligent processing method according to claim 1, wherein The performing a first data processing operation on the obtained text to be processed according to a preset text parser to obtain a first data processing result corresponding to the text to be processed includes: Converting the obtained text to be processed into a plurality of target tags according to a preset text parser, and all the target tags include any one of the elements, attributes, and text nodes of the text to be processed; Constructing a DOM tree corresponding to all the tags according to the text parser; the DOM tree includes a plurality of target nodes, and all the target nodes at least include element nodes, and further include text nodes and / or comment nodes; Performing a label parsing on the text to be processed to obtain label attributes corresponding to the text to be processed, and storing the label attributes in the element nodes to update the DOM tree; Performing a structure conversion operation on the DOM tree to obtain a structure conversion result corresponding to the DOM tree as the first data processing result, and the structure conversion operation is used to convert the DOM tree into a JSON structure.
3. The rich text intelligent processing method according to claim 2, wherein The converting the obtained text to be processed into a plurality of target tags according to a preset text parser includes: Performing parameter recognition, parameter matching, and tag conversion on the obtained text to be processed in sequence based on a preset text parameter according to a regular expression or a preset text parser to obtain a plurality of target tags corresponding to the text to be processed and the text parameter; Moreover, performing a structure conversion operation on the DOM tree to obtain a structure conversion result corresponding to the DOM tree includes: Starting from the root node of the DOM tree, accessing all the target nodes on the DOM tree; For each accessed target node, creating a JSON object corresponding to the target node and setting the filling fields corresponding to the JSON object corresponding to the target node. The filling fields are used to fill the node type, tag name, text content, and node attributes corresponding to the target node; For each child node in the element node, recursively performing the operations of creating a JSON object corresponding to the child node and setting the filling fields corresponding to the JSON object corresponding to the child node, and adding the JSON object corresponding to each child node to the target array corresponding to the parent node of the child node; After determining that all the target nodes have been accessed and converted into JSON objects, determining the DOM tree after the conversion as the structure conversion result.
4. The rich text intelligent processing method according to claim 3, wherein Performing a second data processing operation on the first data processing result to obtain a second data processing result corresponding to the first data processing result includes: Performing a structure traversal on the first data processing result in a recursive or iterative manner; During the process of performing the structure traversal on the first data processing result, identifying the target filling fields corresponding to each target node to obtain the element type corresponding to the target node; the target filling fields include the node type or the tag name; According to the element type corresponding to each target node, creating or filling the data structure of a preset interface component to obtain the component data corresponding to the target interface component to be generated; the target interface component is a HarmonyOS UI component; Creating a component instance corresponding to the first data processing result according to the component data, and updating the node attributes and their corresponding attribute values in the filling fields corresponding to each target node to the component instance; According to the parent-child relationship corresponding to each JSON object in the first data processing result, combining the component instance and a preset component decorator to construct a component tree corresponding to the target interface component as the second data processing result.
5. The rich text intelligent processing method according to any one of claims 1-4, characterized in that Performing a third data processing operation on the second data processing result to obtain a third data processing result corresponding to the second data processing result includes: Performing a rule parsing operation on the second data processing result to obtain a rule parsing result corresponding to the second data processing result; Filling the rule parsing result into the corresponding interface component to be filled, and performing an adaptation processing operation on the interface component to be filled to obtain a first interface component corresponding to the interface component to be filled; the adaptation processing operation includes at least one of version update check, style change, and style attribute change; According to the user interaction requirements, adding an event listener, a hyperlink component, and a user-defined component to the first interface component to obtain a second interface component as the third data processing result.
6. The rich text intelligent processing method according to claim 5, wherein Performing a rule parsing operation on the second data processing result to obtain a rule parsing result corresponding to the second data processing result includes: Determining a style information reading method for the second data processing result, where the style information reading method includes a first reading method based on a JSON structure and / or a second reading method based on a CSS file; When the style information reading method includes the first reading method, parsing the JSON structure in the second data processing result according to a JSON parsing library to obtain a target JSON object; Performing style attribute or class name access and information extraction on the target JSON object according to predefined keys to obtain style attribute information and class name information corresponding to the target JSON object as the rule parsing result corresponding to the second data processing result; When the style information reading method includes the second reading method, loading a target CSS file to be analyzed and parsing the target CSS file to obtain a plurality of rule set objects corresponding to the target CSS file, where each rule set object includes a selector and a style declaration; Performing class name parsing on the JSON structure in the second data processing result to obtain class name information corresponding to the JSON structure in the second data processing result; For each of the rule set objects, matching the selector included in the rule set object with the class name information to obtain target rule set objects that meet a preset matching requirement among all the rule set objects, and adding the style attributes and style values included in the style declaration corresponding to the target rule set objects to the rule parsing result corresponding to the second data processing result.
7. The rich text intelligent processing method according to claim 5 or 6, characterized in that, The event listener is used to listen for user interaction events and respond to user interaction events, where the user interaction events include click, long press, and hover; The hyperlink component is used to respond to the user's need for page jump or URL jump; The custom component is used to respond to the user's need for custom binding of an event callback function.
8. A rich text intelligent processing device, characterized in that, The device is applied to the HarmonyOS, and the device includes: A first data processing module, configured to perform a first data processing operation on the obtained text to be processed according to a preset text parser to obtain a first data processing result corresponding to the text to be processed; the first data processing operation includes a text parsing operation, a structure conversion operation, and a tag attribute extraction operation, where the structure conversion operation is used to convert the text parsing result obtained after performing the text parsing operation on the text to be processed into a lightweight data exchange structure that meets the preset data processing requirements; both the text parsing operation and the tag attribute extraction operation are used to determine the core text information of the text to be processed; A second data processing module, configured to perform a second data processing operation on the first data processing result to obtain a second data processing result corresponding to the first data processing result; the second data processing operation includes a structure traversal operation for the lightweight data exchange structure, and further includes a component generation operation for generating interface components that meet the preset rich text display requirements. A third data processing module, configured to perform a third data processing operation on the second data processing result to obtain a third data processing result corresponding to the second data processing result; the third data processing operation includes a rule parsing operation and an interface style adaptation operation for the interface components, and further includes a user interaction event processing operation; the user interaction event processing operation is used to add a listening and response function for user interaction events to the second data processing result. A text output module, configured to combine the first data processing result, the second data processing result, and the third data processing result, and output target rich text data.
9. A network attached storage device, characterized in that, The network attached storage device is configured with a display screen, and the network attached storage device is used for interactive communication with an electronic device, wherein the network attached storage device is used to execute the rich text intelligent processing method according to any one of claims 1-7.
10. An electronic device, characterized in that, The electronic device includes; A memory storing executable program code; A processor coupled to the memory; The processor calls the executable program code stored in the memory and executes the rich text intelligent processing method according to any one of claims 1-7.
11. A computer storage medium, characterized in that, The computer storage medium stores computer instructions, which are used to execute the rich text intelligent processing method according to any one of claims 1-7 when called.
12. A rich text intelligent processing system, characterized in that, The system includes the rich text intelligent processing device according to claim 8, and a network attached storage device communicatively connected to the device; Or, The system includes the electronic device according to claim 10, and a network attached storage device communicatively connected to the electronic device.
Citation Information
Cited By
System element dynamic color marking method
CN121300893A