Rich Text Processing Method and Device
Through depth-first search and data structure analysis, the problem of copy-paste paragraph information of rich text content cannot be effectively retained in the prior art, and the segment consistency and comprehensive processing of pasted content in rich text editors are achieved.
Patent Information
- Application Number
- CN202211467955.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-22
- Publication Date
- 2025-06-10
- Estimated Expiration
- 2042-11-22
AI Technical Summary
When existing rich text editors process copy-paste rich text content, they cannot effectively retain paragraph information and style information, resulting in a lack of comprehensiveness in processing.
By analyzing the description text of the content to be pasted, building a data structure and performing a depth-first search, determining the indication information of the leaf nodes to divide the paragraphs, generating rich text data and rendering in a rich text editor.
The rich text content after pasting is consistent with the segmentation of the content to be pasted, and the comprehensiveness of the copy-paste data processing scenario is improved.
Smart Images

Figure CN118095199B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of terminals, and in particular, to a rich text processing method and apparatus. Background Art
[0002] With the development of intelligent terminals, when users record information through software such as memos, in addition to basic text, they also hope to record other content containing more information such as tables and pictures. Therefore, it is necessary to use a rich text editor to edit rich text content.
[0003] In addition to providing the function of allowing users to input rich text content by themselves, the rich text editor can also provide the function of pasting rich text content copied from elsewhere into the rich text editor. When processing the copied and pasted rich text content, the current common practice of the rich text editor is to only retain basic text information and unable to retain the paragraph information of the copied content, thus resulting in the lack of comprehensiveness in the processing of the rich text data copied and pasted. Summary of the Invention
[0004] This application provides a rich text processing method and apparatus, aiming to retain complete paragraph information for the content pasted from an external source.
[0005] In a first aspect, this application provides a rich text processing method, which is applied to a rich text editor in a first application program. The method includes:
[0006] Receiving a first description text corresponding to the content to be pasted, and parsing to obtain a data structure corresponding to the first description text, where the data structure includes at least one node;
[0007] Performing a depth-first search on the data structure to determine indication information corresponding to each of a plurality of leaf nodes in the data structure, where the indication information is used to indicate whether the leaf node and the previous leaf node of the leaf node in the data structure correspond to the same paragraph;
[0008] Determining at least one array according to the indication information corresponding to each of the leaf nodes in the data structure, where the array includes at least one leaf node, and the leaf nodes in the same array correspond to the same paragraph;
[0009] Generating first rich text data corresponding to the first description text according to the at least one array, and rendering and displaying rich text content corresponding to the first rich text data in the rich text editor.
[0010] In this implementation manner, the data structure corresponding to the first description text of the content to be pasted is obtained by parsing, and a depth-first search is performed on the first data structure. During this process, the indication information of each leaf node is determined to determine whether the leaf node and its previous leaf node correspond to the same paragraph. Then, the leaf nodes corresponding to the same paragraph are divided into an array, so as to obtain the data corresponding to each natural paragraph. Then, based on multiple arrays, the first rich text data corresponding to the first description text is generated. The text segmentation information in the first rich text data is the same as the text segmentation information in the first description text. Finally, the rich text content corresponding to the first rich text data is rendered, so that it can effectively achieve that the segmented situation shown by the rich text content after pasting is the same as that of the original content to be pasted, and further effectively improve the comprehensiveness of processing in the data processing scenario of copy and paste.
[0011] In some implementation manners, the depth-first search of the data structure to determine the indication information corresponding to each leaf node in the data structure includes:
[0012] Perform a depth-first search on the data structure, and during the depth-first search process, for any first leaf node among the multiple leaf nodes, record the node information of each intermediate node on the path traversed to the first leaf node. The node information includes at least one of the following: node category and node depth, and the node category is used to indicate whether the intermediate node is a block-level node;
[0013] Determine the bifurcation node where the first leaf node and the second leaf node bifurcate in the data structure, where the second leaf node is the previous leaf node of the first leaf node in the data structure;
[0014] Determine the indication information corresponding to the first leaf node according to the bifurcation node and the node information of each intermediate node.
[0015] In this implementation manner, during the depth-first search of the data structure, for each leaf node, the node information of each intermediate node on the path traversed to it can be recorded. The node information can include the node category and the node depth. Since the node information can be determined during the depth-first search process, the speed and efficiency of collecting node information can be effectively improved.
[0016] In some implementation manners, the determining the indication information corresponding to the first leaf node according to the bifurcation node and the node information of each intermediate node includes:
[0017] Determine, according to the first node depth corresponding to the bifurcation node, whether there is a block-level node among at least one intermediate node with a node depth greater than the first node depth on the first path and the second path, where the first path is the path traversed to the first leaf node during the depth-first search process, and the second path is the path traversed to the second leaf node during the depth-first search process;
[0018] If there is such a block-level node, determine that the indication information corresponding to the first leaf node is used to indicate that the first leaf node and the second leaf node do not belong to the same paragraph;
[0019] If there is no such block-level node, determine that the indication information corresponding to the first leaf node is used to indicate that the first leaf node and the second leaf node belong to the same paragraph.
[0020] In this implementation manner, according to the depth of the bifurcation node of each leaf node and its previous leaf node, determine whether there is a block-degree node among the nodes at a level after the bifurcation node on the first path and the second path, and then it can be determined whether each leaf node and its previous leaf node belong to the same paragraph. Therefore, the determination of the indication information of the leaf node can be simply and effectively realized. After that, based on the indication information of the leaf node, the array is partitioned, and the leaf nodes corresponding to the same paragraph are partitioned into the same array. Therefore, the determination of the paragraph partitioning situation in the copied content can be effectively realized.
[0021] In some implementation manners, the method further includes:
[0022] During the depth-first search process, for any traversed first node, obtain the attribute information of the parent node of the first node;
[0023] Determine the node attribute of the first node according to the attribute information of the parent node of the first node and the attribute information of the first node.
[0024] In some implementation manners, the attribute information includes at least one sub-attribute;
[0025] The determining the node attribute of the first node according to the attribute information of the parent node of the first node and the attribute information of the first node includes:
[0026] For any one of the sub-attributes, if the attribute information of the first node attribute does not include the sub-attribute, then determine the sub-attribute of the parent node of the first node as one item of the node attribute of the first node;
[0027] If the attribute information of the first node attribute includes the sub-attribute, then determine the sub-attribute of the first node as one of the node attributes of the first node.
[0028] In this implementation manner, the correctness of the node attributes determined for each leaf node can be effectively ensured.
[0029] In some implementation manners, each leaf node in the array carries its own node attribute;
[0030] Generating the first rich text data corresponding to the first description text according to the at least one array, and rendering and displaying the rich text content corresponding to the first rich text data in the rich text editor includes:
[0031] For any first array in the at least one array, obtain the node attributes of each leaf node in the first array;
[0032] Perform filtering processing on the node attributes of each leaf node in the first array to obtain the filtered node attributes of each leaf node;
[0033] According to each leaf node in the first array, determine the first sub-data corresponding to a paragraph in the first rich text data, and the first sub-data includes the data content of each leaf node and the filtered node attributes corresponding to each leaf node;
[0034] According to the first rich text data, render and display the rich text content corresponding to the first rich text data in the rich text editor, where each sub-data is displayed as a paragraph respectively.
[0035] In this implementation manner, when determining the first rich text data, each array can be processed separately, and the leaf nodes in an array are determined as a sub-data in the first rich text data. Each sub-data in the rich text data corresponds to a paragraph. Therefore, the paragraph information in the first description text can be effectively converted into the paragraph information in the first rich text data, thereby ensuring that the paragraph display in the first rich text content is consistent with the paragraph display in the content to be pasted.
[0036] In some implementation manners, the rich text editor includes a plugin unit;
[0037] Receiving the first description text corresponding to the content to be pasted includes:
[0038] The plug-in unit receives a first instruction, which includes the first description text, and the first instruction is used to instruct to insert the content to be pasted corresponding to the first description text in the rich text editor.
[0039] In this implementation, the function of external source pasting is realized through the plug-in in the plug-in unit, so that the flexibility of adjusting and controlling the rich text editor can be effectively improved.
[0040] In some implementation manners, the rich text editor further includes a first rendering unit;
[0041] Rendering and displaying the rich text content corresponding to the first rich text data in the rich text editor includes:
[0042] Through the first rendering unit, rendering and displaying the rich text content corresponding to the first rich text data in the rich text editor.
[0043] In a second aspect, an embodiment of the present application provides a rich text processing device. The device includes:
[0044] A receiving module, configured to receive the first description text corresponding to the content to be pasted, and parse to obtain a data structure corresponding to the first description text, where the data structure includes at least one node;
[0045] A determining module, configured to perform a depth-first search on the data structure to determine indication information corresponding to each of a plurality of leaf nodes in the data structure, where the indication information is used to indicate whether the leaf node and the previous leaf node of the leaf node in the data structure correspond to the same paragraph;
[0046] The determining module is further configured to determine at least one array according to the indication information corresponding to each of the leaf nodes in the data structure, where the array includes at least one leaf node, and the leaf nodes in the same array correspond to the same paragraph;
[0047] A processing module, configured to generate first rich text data corresponding to the first description text according to the at least one array, and render and display the rich text content corresponding to the first rich text data in the rich text editor.
[0048] In some implementation manners, the determining module is specifically configured to:
[0049] Perform a depth - first search on the data structure, and during the depth - first search, for any first leaf node among the multiple leaf nodes, record the node information of each intermediate node on the path traversed to the first leaf node. The node information includes at least one of the following: node category and node depth. The node category is used to indicate whether the intermediate node is a block - level node;
[0050] Determine the bifurcation node where the first leaf node and the second leaf node bifurcate in the data structure. The second leaf node is the previous leaf node of the first leaf node in the data structure;
[0051] Determine the indication information corresponding to the first leaf node according to the bifurcation node and the node information of each intermediate node.
[0052] In some implementation manners, the determining module is specifically configured to:
[0053] According to the first node depth corresponding to the bifurcation node, determine whether there is a block - level node among at least one intermediate node with a node depth greater than the first node depth on the first path and the second path. The first path is the path traversed to the first leaf node during the depth - first search, and the second path is the path traversed to the second leaf node during the depth - first search;
[0054] If there is such a block - level node, determine that the indication information corresponding to the first leaf node is used to indicate that the first leaf node and the second leaf node do not belong to the same paragraph;
[0055] If there is no such block - level node, determine that the indication information corresponding to the first leaf node is used to indicate that the first leaf node and the second leaf node belong to the same paragraph.
[0056] In some implementation manners, the processing module is further configured to:
[0057] During the depth - first search, for any first node traversed, obtain the attribute information of the parent node of the first node;
[0058] Determine the node attribute of the first node according to the attribute information of the parent node of the first node and the attribute information of the first node.
[0059] In some implementation manners, the attribute information includes at least one sub - attribute;
[0060] The determining module is specifically configured to:
[0061] For any one of the sub - attributes, if the attribute information of the first node attribute does not include the sub - attribute, then determine the sub - attribute of the parent node of the first node as one of the node attributes of the first node;
[0062] If the attribute information of the first node attribute includes the sub - attribute, then determine the sub - attribute of the first node as one of the node attributes of the first node.
[0063] In some implementation manners, each leaf node in the array carries its own node attribute;
[0064] The processing module is specifically configured to:
[0065] For any first array in the at least one array, obtain the node attributes of each leaf node in the first array;
[0066] Perform filtering processing on the node attributes of each leaf node in the first array to obtain the filtered node attributes of each leaf node;
[0067] According to each leaf node in the first array, determine first sub - data corresponding to a paragraph in the first rich text data, where the first sub - data includes the data content of each leaf node and the filtered node attributes corresponding to each leaf node;
[0068] According to the first rich text data, render and display the rich text content corresponding to the first rich text data in the rich text editor, where each sub - data is displayed as a paragraph respectively.
[0069] In some implementation manners, the rich text editor includes a plugin unit;
[0070] The receiving module is specifically configured to:
[0071] The plugin unit receives a first instruction, where the first instruction includes the first description text, and the first instruction is used to instruct to insert the content to be pasted corresponding to the first description text in the rich text editor.
[0072] In some implementation manners, the rich text editor further includes a first rendering unit;
[0073] The processing module is specifically configured to:
[0074] Through the first rendering unit, render and display the rich text content corresponding to the first rich text data in the rich text editor.
[0075] In a third aspect, embodiments of the present application provide a terminal device, which may also be referred to as a terminal, user equipment (UE), mobile station (MS), mobile terminal (MT), etc. The terminal device may be a mobile phone, smart TV, wearable device, tablet computer (Pad), a computer with wireless transceiver function, virtual reality (VR) terminal device, augmented reality (AR) terminal device, wireless terminal in industrial control, wireless terminal in self-driving, wireless terminal in remote medical surgery, wireless terminal in smart grid, wireless terminal in transportation safety, wireless terminal in smart city, wireless terminal in smart home, and so on.
[0076] The terminal device includes: a processor and a memory; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory, so that the terminal device executes the method as in the first aspect.
[0077] In a fourth aspect, embodiments of the present application provide a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the method as in the first aspect is implemented.
[0078] In a fifth aspect, embodiments of the present application provide a computer program product including a computer program. When the computer program is run, a computer is caused to execute the method as in the first aspect.
[0079] In a sixth aspect, embodiments of the present application provide a chip including a processor, and the processor is used to call a computer program in a memory to execute the method as described in the first aspect.
[0080] It should be understood that the second to fifth aspects of the present application correspond to the technical solutions of the first aspect of the present application, and the beneficial effects obtained by each aspect and the corresponding feasible embodiments are similar, and will not be elaborated herein.
[0081] The present application provides a rich text processing method and apparatus. The method parses to obtain the data structure corresponding to the first description text of the content to be pasted, and performs a depth-first search on the first data structure. During this process, the indication information of each leaf node is determined to determine whether the leaf node and its previous leaf node correspond to the same paragraph. Then, the leaf nodes corresponding to the same paragraph are divided into an array, so as to obtain the data corresponding to each natural paragraph. Then, based on multiple arrays, the first rich text data corresponding to the first description text is generated, where the text segmentation information in the first rich text data is consistent with the text segmentation information in the first description text. Finally, the rich text content corresponding to the first rich text data is rendered, so that it can effectively achieve that the segmented situation shown by the rich text content after pasting is consistent with the original content to be pasted, and further effectively improve the comprehensiveness of processing in the data processing scenario of copy and paste. BRIEF DESCRIPTION OF THE DRAWINGS
[0082] The accompanying drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.
[0083] Figure 1 It is a schematic diagram of the processing process of copy and paste provided by an embodiment of the present application;
[0084] Figure 2 It is a schematic diagram of the architecture of a rich text editor provided by an embodiment of the present application;
[0085] Figure 3 It is a schematic diagram of the interface of the first application program corresponding to the rich text editor provided by an embodiment of the present application Figure 1 ;
[0086] Figure 4 It is a schematic diagram of the interface of the first application program corresponding to the rich text editor provided by an embodiment of the present application Figure 2 ;
[0087] Figure 5 It is a flowchart of the rich text processing method provided by an embodiment of the present application;
[0088] Figure 6 It is the flow of the rich text processing method provided by an embodiment of the present application Figure 2 ;
[0089] Figure 7 It is a schematic diagram of the traversal path corresponding to the leaf node provided by an embodiment of the present application Figure 1 ;
[0090] Figure 8 It is a schematic diagram of the traversal path corresponding to the leaf node provided by an embodiment of the present application Figure 2 ;
[0091] Figure 9 Schematic diagram for implementing the determination of an array provided by an embodiment of the present application;
[0092] Figure 10 Flow of the rich text processing method provided by an embodiment of the present application Figure 3 ;
[0093] Figure 11 Schematic diagram for implementing the rich text processing method provided by an embodiment of the present application;
[0094] Figure 12 Schematic diagram of the structure of the rich text processing device provided by an embodiment of the present application;
[0095] Figure 13 Schematic diagram of the hardware structure of the terminal device provided by an embodiment of the present application.
[0096] Through the above-mentioned drawings, specific embodiments of the present application have been shown, and there will be more detailed descriptions hereinafter. These drawings and textual descriptions are not intended to limit the scope of the concept of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. Detailed implementation manners
[0097] Here, exemplary embodiments will be described in detail, and examples thereof are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementation manners described in the following exemplary embodiments do not represent all implementation manners consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0098] It should be noted that "when... " in the embodiments of the present application can be at the instant when a certain situation occurs, or within a period of time after a certain situation occurs. The embodiments of the present application do not make specific limitations in this regard. In addition, the display interface provided by the embodiments of the present application is only an example, and the display interface may also include more or less content.
[0099] With the development of information technology, intelligent terminals play an increasingly important role in people's lives. When users have to-do items or events that need to be recorded, they tend to record relevant content in application software such as memos. The content that users need to record may include not only simple basic text, but also information such as tables and pictures. At this time, it is required that applications such as memos have rich text editing functions.
[0100] Among them, in addition to providing the function of allowing users to input rich text content by themselves, the rich text editor can also provide the function of pasting rich text content copied from elsewhere into the rich text editor.
[0101] For example, it can be combined with Figure 1 to understand the processing process of processing copied and pasted content. Figure 1 This is a schematic diagram of the processing process of copying and pasting provided by the embodiment of the present application.
[0102] Such as Figure 1 shown, for example, when a user pastes externally copied content into rich text content, for example, it can be that first, the content is copied from a data source such as a web page or a document. After that, the data source at the copying end of the web page or the document will provide a text in html (Hyper Text Markup Language) format to the clipboard. The application corresponding to the rich text editor (such as a note application) as the receiving end will obtain the html data from the clipboard, and parse the html data into JSON (JavaScript Object Notation) data recognizable inside the application, and display it in the rich text editor.
[0103] However, because there are many types of html tags, various different attributes can be carried on the tags, and the tags are nested layer by layer and inherit from each other. These characteristics make it very difficult to parse html format data, and it is easy to have parsing errors.
[0104] Therefore, in the current related technologies, when a rich text editor processes rich text content copied and pasted, the common practice is to only retain basic text information, which will result in the inability to retain paragraph information between texts and the inability to retain the styles carried by the texts, thereby resulting in a lack of comprehensiveness in the processing of rich text data copied and pasted.
[0105] To solve the above technical problems, the present application provides a rich text processing method, aiming to achieve the following purposes: On the one hand, retain the paragraph information of html data, that is, the parsed JSON data needs to show the same segmentation as the data in the data source end. On the other hand, retain the style information of html data, that is, the parsed JSON data needs to show styles compatible with the first application corresponding to the rich text note.
[0106] Before introducing the rich text processing method provided by the present application, for example, it can be first combined with Figure 2 to understand the relevant architecture of the rich text editor. Figure 2 This is a schematic diagram of the architecture of the rich text editor provided by the embodiment of the present application.
[0107] Such as Figure 2As shown in the figure, in the technical solution of this application, a rich text editor product can be developed and then integrated into different terminal platforms.
[0108] In Figure 2 's example, taking the Android platform and the Windows platform as examples, the architecture of the rich text editor is introduced. Referring to Figure 2 It can be determined that the rich text editor in this embodiment can be used as both an Android product in the Android platform and a desktop product in the Windows platform.
[0109] In a possible implementation, the rich text editor is usually integrated into an application to provide rich text editing functions for the corresponding application. Here, two applications, namely the Android memo and the PC memo, are used as examples for illustration. However, it can be understood that the implementation methods for the remaining applications that need to integrate the rich text editor are similar and will not be elaborated here.
[0110] Next, in combination with Figure 2 First, the Android memo is described. The Android memo is an application with rich text editing functions. Referring to Figure 2 It can be determined that in the Android memo, there are a Native layer and a Webview layer.
[0111] Among them, the Native layer contains an Activity component, a View component, a Button component, and a user event processing unit. The Activity component, the View component, and the Button component are part of the Android native user interface (UI) framework and can implement UI rendering. The visual interface that the user interacts with during the use of this memo is rendered by the components in the Native layer. The user event processing unit can monitor events in the UI interface to obtain the user's intentions, such as setting bold, italic, or font size for the text part.
[0112] Through the JS-Android communication interface, the event processing unit can transfer the monitored events to the Webview layer. The Webview layer includes an interface layer and a rich text editor. The Html layout, CSS style, and JS loading unit in the interface layer are used to render components other than the rich text editor. The JS interface serves as the communication interface between JS and the Android layer. The rich text editor is used to implement the user's editing of rich text content.
[0113] Next, in combination with Figure 2 the memo on the personal computer (PC) side will be described. The memo on the PC side can run on the Windows platform. As Figure 2 shown, for the memo on the PC side, the application is built on the web view layer. Among them, the web view layer can include a UI rendering unit, a user event processing unit, an instruction processing unit, and a rich text editor.
[0114] The UI rendering unit further includes React components, an Html layout subunit, and a CSS style subunit. Among them, the memo on the PC side can perform UI rendering through the React framework, and the user event processing unit can listen to events in the UI layer and recognize the user's intention. In the instruction processing unit, the user's intention can be further converted into instructions, and through a series of operations such as instruction subscription, instruction matching, and instruction distribution, the instructions are passed to the rich text editor, and the rich text editor realizes the editing behavior of the user's intention according to the received instructions.
[0115] In Figure 2 the schematic diagram, a rich text editor is deployed in the memo on the PC side corresponding to the Windows platform, and a rich text editor is also deployed in the memo on the Android side corresponding to the Android platform. What is actually deployed on different platforms is Figure 2 the rich text editor shown in the middle part of Figure 2 . And
[0116] And with reference to Figure 2 it can be determined that the rich text editor in this embodiment can include five parts, namely: a rendering mechanism, a history record, a plugin mechanism, a behavior control, and a data model.
[0117] Among them, the rendering mechanism can also be called the first rendering unit, which is used to render and display the content in the rich text editor. The history record can also be called the recording unit, which is used to record the operations in the rich text editor. The plug-in mechanism can also be called the plugin unit. The plugin unit includes multiple plugins, and each plugin is used to implement different functions. For example, the copy and paste operation in this embodiment can be implemented by the external paste plugin in the plugin unit. The behavior control can also be called the execution unit, which is used to encapsulate the relevant data parsed by the plugin mechanism to obtain instructions that can be recognized by the data model. The data model can also be called the data processing unit, which is used to change the data model corresponding to the JSON format rich text data according to the instructions generated by the behavior control.
[0118] Based on the above introduction, for example, the following can be combined with Figure 3 and Figure 4 to understand the operation interfaces of the memo on the PC side and the memo on the Android side. Figure 3 Schematic diagram of the interface of the first application corresponding to the rich text editor provided by the embodiment of the present application Figure 1 , Figure 4 Schematic diagram of the interface of the first application corresponding to the rich text editor provided by the embodiment of the present application Figure 2 .
[0119] As Figure 3 shown, the graphical user interface of the memo includes a file list, a note list, and a user event response area. Among them, the file list displays the user's file classification, the note list displays the rich text list stored in the folder, and the user event response area displays the editing operations that the user can perform on the rich text content. And the graphical user interface of the memo also includes a rich text editor area where the user can edit the rich text content.
[0120] And Figure 4 schematically shows the interface diagram of the memo on the Android side, which is similar to the interface of the memo on the PC side introduced in Figure 3 , and will not be elaborated here.
[0121] Combined with Figure 3 and Figure 4 it can be understood that application programs including rich text editors can be set in devices on different platforms. Such application programs can provide rich text editing functions based on the rich text editor. The specific application devices and specific application platforms of the technical solution of the present application can be selected and set according to actual needs, and this embodiment does not limit this.
[0122] Based on the above introduction, the following combines Figure 5 to illustrate the specific implementation of the rich text processing method provided by the present application. Figure 5 Flowchart of the rich text processing method provided by the embodiment of the present application.
[0123] As Figure 5 shown, the method includes:
[0124] S501. Receive the first description text corresponding to the content to be pasted, and parse to obtain the data structure corresponding to the first description text, where the data structure includes at least one node.
[0125] The method of this embodiment can be applied to a first application, which includes a rich text editor. In the actual implementation process, the first application can be, for example, the memo application introduced above, but it is not limited to the memo introduced above. It can be any application that requires rich text editing functions, such as an instant messaging application that supports rich text editing functions, a document application that supports rich text editing functions, etc. This embodiment does not limit the specific implementation of the first application.
[0126] In this embodiment, the rich text editor can determine the content copied by the user as the content to be pasted. The specific implementation method of the content to be pasted can be selected and set according to actual needs, which depends on what the user specifically copies. Therefore, this embodiment does not limit the specific implementation method of the content to be pasted.
[0127] In addition, the rich text editor can receive the first description text corresponding to the content to be pasted. For example, if the content to be pasted is copied from other data sources, the first description text of the content to be pasted can be stored in the clipboard for pasting into the rich text editor. Then, the rich text editor can receive the first description text from the clipboard, for example.
[0128] In a possible implementation manner, the first description text in the clipboard can be, for example, text data in html format. The first description text can include the specific data content of the text to be pasted and the corresponding data format.
[0129] In this embodiment, the first data can be parsed to obtain the data structure corresponding to the first data. In a possible implementation manner, the data structure corresponding to the first data can be, for example, a DOM (Document Object Model) tree structure. The specific implementation of the DOM tree structure can refer to the description in related technologies, and this embodiment does not limit this.
[0130] Among them, the data structure can include at least one node. The nodes in the data structure can be, for example, tag nodes and content nodes. The tag nodes are some nodes used to represent the data structure of the first data, and the content nodes are nodes representing the specific data content in the first data. For example, the content nodes can include specific text, or the address and link of a picture, etc.
[0131] S502. Perform a depth-first search on the data structure to determine the indication information corresponding to each of the multiple leaf nodes in the data structure. The indication information is used to indicate whether the leaf node and the previous leaf node of the leaf node in the data structure correspond to the same paragraph.
[0132] After parsing the data structure corresponding to the first data, in this embodiment, a depth-first search can be performed on the data structure corresponding to the first data. During the depth-first search, for each leaf node in the data structure, the corresponding indication information can be determined.
[0133] Among them, taking the leaf node a as an example, the indication information of the leaf node a can indicate whether the leaf node a and the previous leaf node of the leaf node a in the data structure correspond to the same paragraph. The meaning of corresponding to the same paragraph is that the content in this leaf node and the content in its previous leaf node belong to the same natural paragraph in the data to be pasted.
[0134] It can be understood that the leaf nodes are often the content nodes introduced above, that is, what is usually included in the leaf nodes is the specific data content. Then, for each leaf node, the corresponding indication information is determined to determine whether each leaf node and its corresponding previous leaf node correspond to the same paragraph. Thus, in the subsequent display process, the content of the leaf nodes belonging to the same paragraph can be displayed in the same paragraph.
[0135] And it should be noted that in this embodiment, when determining the indication information of each leaf node in the data structure, it is determined based on a depth-first search of the data structure of the first description information. Therefore, it can be ensured that the segmentation information of each leaf node and the previous leaf node corresponds to the content segmentation situation included in the first description information.
[0136] S503. According to the indication information corresponding to each leaf node in the data structure, determine at least one array, where the array includes at least one leaf node, and the leaf nodes in the same array correspond to the same paragraph.
[0137] After determining the indication information corresponding to each leaf node in the data structure, in this embodiment, the array can be divided according to the indication information corresponding to each leaf node in the data structure.
[0138] In a possible implementation manner, the leaf nodes belonging to the same paragraph can be divided into the same array according to the indication information of each leaf node, so as to determine at least one array. Then, each array includes at least one leaf node, and the leaf nodes in the same array all correspond to the same paragraph.
[0139] S504. Generate the first rich text data corresponding to the first description text according to at least one array, and render and display the rich text content corresponding to the first rich text data in the rich text editor.
[0140] After determining the arrays introduced above, in this embodiment, first rich text data corresponding to the first description text may be generated according to at least one array. The first rich text data may be, for example, data in JSON format.
[0141] In a possible implementation manner, if there are corresponding segments in the first rich text data, for example, the content corresponding to the leaf nodes in the same array may be used as the content under the same segment in the first rich text content. And the content corresponding to the leaf nodes in different arrays may be used as the content under different segments in the first rich text content.
[0142] After rendering and displaying the rich text content corresponding to the first rich text data in a rich text editor, it can be ensured that the displayed rich text content and the content to be pasted exhibit the same segment effect, that is, the segment effect of the rich text content corresponding to the first rich text data is consistent with the segment effect of the content to be pasted.
[0143] The rich text processing method provided by the embodiment of the present application includes: receiving a first description text corresponding to the content to be pasted, and parsing to obtain a data structure corresponding to the first description text, where the data structure includes at least one node. Performing a depth-first search on the data structure to determine the indication information corresponding to each of the multiple leaf nodes in the data structure, where the indication information is used to indicate whether the leaf node and the previous leaf node of the leaf node in the data structure correspond to the same paragraph. Determining at least one array according to the indication information corresponding to each leaf node in the data structure, where the array includes at least one leaf node, and the leaf nodes in the same array correspond to the same paragraph. Generating first rich text data corresponding to the first description text according to at least one array, and rendering and displaying the rich text content corresponding to the first rich text data in a rich text editor. By parsing to obtain the data structure corresponding to the first description text of the content to be pasted, and performing a depth-first search on the first data structure, in the process, the indication information of each leaf node is determined to determine whether the leaf node and its previous leaf node correspond to the same paragraph, and then the leaf nodes corresponding to the same paragraph are divided into one array to obtain the data corresponding to each natural paragraph, and then based on multiple arrays, first rich text data corresponding to the first description text is generated, where the text segment information in the first rich text data is consistent with the text segment information in the first description text, and finally the rich text content corresponding to the first rich text data is rendered, so that it can effectively implement that the rich text content after pasting is consistent with the segment situation of the original content to be pasted, and further effectively improve the comprehensiveness of processing in the data processing scenario of copy and paste.
[0144] Based on the above-introduced content, the following is combined with Figures 6 to 9A further detailed introduction to the rich text processing method provided in this application is given. Figure 6 The process of the rich text processing method provided in the embodiments of this application Figure 2 , Figure 7 The schematic diagram of the traversal path corresponding to the leaf node provided in the embodiments of this application Figure 1 , Figure 8 The schematic diagram of the traversal path corresponding to the leaf node provided in the embodiments of this application Figure 2 , Figure 9 The implementation schematic diagram of determining the array provided in the embodiments of this application.
[0145] As Figure 6 shown, the method includes:
[0146] S601. Receive the first description text corresponding to the content to be pasted, and parse to obtain the data structure corresponding to the first description text, where the data structure includes at least one node.
[0147] Among them, the implementation manner of S601 is similar to the implementation manner of S501 introduced above, and the specific implementation manner will not be elaborated here.
[0148] Next, in combination with Figure 7 a further exemplary introduction to the data structure corresponding to the first description text is given. As Figure 7 shown, assuming that after parsing the first description text, the Figure 7 shown data structure is obtained. In this data structure, it includes multiple tag nodes and multiple content nodes.
[0149] Among them, the tag nodes include Figure 7 the main tag (body) node, hierarchical tag (div) node, block tag (section) node, paragraph tag (p) node, bold tag (b) node, inline tag (span) node, inline tag (span) node, and emphasis tag (em) node shown.
[0150] And, the content tags include, for example, Figure 7 the text 1 node to text 7 node shown, and the image 1 node, where text 1 to text 7 and image 1 correspond to the specific data content in the content to be pasted.
[0151] In the actual implementation process, the specific data structure, that is, the DOM tree structure, can be determined according to actual needs, and this embodiment does not limit this.
[0152] S602. Perform a depth - first search on the data structure. During the depth - first search, for any one of the multiple leaf nodes, which is a first leaf node, record the node information of each intermediate node on the path traversed to the first leaf node. The node information includes at least one of the following: node category and node depth. The node category is used to indicate whether the intermediate node is a block - level node.
[0153] Referring to Figure 7 the introduction, it can be determined that in fact all leaf nodes are content nodes. Therefore, in this embodiment, each leaf node in the data structure can be traversed by means of depth - first search, so as to determine the corresponding indication information for each leaf node.
[0154] Among them, during the depth - first search, the implementation methods for determining the indication information for each leaf node are similar. Therefore, the following takes any one of the multiple leaf nodes as an example for illustration. For example, any one of the leaf nodes is represented by the first leaf node, and the following is introduced based on this example.
[0155] In a possible implementation manner, during the depth - first search, record the node information of each intermediate node on the path traversed to the first leaf node. The node information may include the node category and the node depth. The node category is used to indicate whether the node is a block - level node, and the node depth is used to indicate which layer the node is located in the data structure.
[0156] In a possible implementation manner, when determining the node category, for example, the display information of each intermediate node can be determined. The display information can indicate whether the node is a block - level node or an inline node. For example, if the attribute value of display is set to block, it means that the node is a block - level node. If the attribute value of display is set to inline, it means that the node is an inline node.
[0157] For example, it can be understood in combination with Figure 7 For example, if the first leaf node is the Figure 7 "text4" node in Figure 7 it can be determined that the 6 intermediate nodes on the path traversed to the "text4" node are successively: the body tag (body) node, the hierarchical tag (div) node, the block tag (section) node, the paragraph tag (p) node, the bold tag (b) node, and the inline tag (span) node.
[0158] It can be determined that among the above 6 intermediate nodes, the node category corresponding to the body tag node is a block-level node, and the node depth is 1. The node category corresponding to the div tag node is a block-level node, and the node depth is 2. The node category corresponding to the section tag node is a block-level node, and the node depth is 3. The node category corresponding to the p tag node is an inline node, and the node depth is 4. The node category corresponding to the b tag node is an inline node, and the node depth is 5. The node category corresponding to the span tag node is an inline node, and the node depth is 6.
[0159] It can be understood that the node information of each intermediate node on the path is obtained and recorded during the process of Depth First Search (DFS).
[0160] S603. Determine the bifurcation node where the first leaf node and the second leaf node bifurcate in the data structure. The second leaf node is the previous leaf node of the first leaf node in the data structure.
[0161] After that, after traversing to the first leaf node, the bifurcation node where the first leaf node and the second leaf node bifurcate in the data structure can be determined. The second leaf node is the previous leaf node of the first leaf node in the data structure. That is to say, the bifurcation node can be determined for the first leaf node, where the bifurcation node is the node where the first leaf node and its previous leaf node bifurcate in the data structure.
[0162] For example, in Figure 7 the example, the first leaf node is Figure 7 the "Text 4" node in, then the second leaf node is the "Text 3" node. Referring to Figure 7 it can be determined that the bifurcation node where the "Text 4" node and the "Text 3" node bifurcate in the data structure is also the b tag node.
[0163] In a possible implementation, when determining the bifurcation node between a node and its previous node, since depth-first search is performed in this embodiment, and the principle of depth-first search is that after traversing a branch, it recursively returns to the nearest non-leaf node where there are still un-traversed leaf nodes below, and then continues to traverse the next branch from this non-leaf node. Therefore, when traversing to each leaf node, it can be determined that a branch traversal is completed, and then the specific node where the recursion returns can be recorded, and then the node where the return occurs is determined as the bifurcation node corresponding to the next leaf node traversed.
[0164] Among them, in order to quickly and effectively obtain the bifurcation node, for example, a global identifier can be made when the depth-first search reaches a leaf node.
[0165] For example, in Figure 7 the example of, assuming that the leaf node of the "Text 3" node is traversed, a global identifier can be made at this time, and it can be determined that all the leaf nodes on the left side of the "Text 3" node have been traversed. At this time, it is possible to return to the nearest non-leaf node where there are still un-traversed leaf nodes below, that is, Figure 7 the bold label (b) node in. Then at this time, the bold label (b) node can be determined as the bifurcation node corresponding to the next leaf node. For example, the bold label (b) node can be recorded first. When traversing to the next leaf node later, that is, the "Text 4" node, it can be determined that the bifurcation node corresponding to this leaf node is the previously recorded bold label (b) node.
[0166] S604. According to the first node depth corresponding to the bifurcation node, determine whether there is a block-level node among at least one intermediate node whose node depth is greater than the first node depth on the first path and the second path. The first path is the path traversed to the first leaf node during the depth-first search process, and the second path is the path traversed to the second leaf node during the depth-first search process.
[0167] After determining the bifurcation node of the first leaf node and the second leaf node, it can be understood that for the nodes on the path whose depth is less than or equal to the depth of the bifurcation node, they are the common parent nodes on the paths of the first leaf node and the second leaf node. Among them, the influence of the common parent node on the first leaf node and the second leaf node is the same. Therefore, there is no need to pay attention, and only the part of the nodes on the path whose depth is greater than the depth of the bifurcation node needs to be concerned, that is, to pay attention to the different parts of the paths of the two nodes, so as to determine whether the two nodes belong to the same paragraph.
[0168] Since the node depth of each intermediate node on the traversal path is determined in this embodiment, and the bifurcation node is also a node on the traversal path, the node depth of the bifurcation node can be directly determined. In this embodiment, the node depth of the bifurcation node is marked as the first node depth.
[0169] After that, according to the node depth of the bifurcation node, determine whether there is a block-level node among at least one intermediate node whose node depth is greater than the first node depth on the first path. The first path is the path traversed to the first leaf node during the depth-first search process.
[0170] Furthermore, it is necessary to determine whether there is a block-level node in at least one intermediate node on the second path whose node depth is greater than the first node depth, wherein the second path is a path traversed to the second leaf node during the depth-first search process.
[0171] For example, you can combine Figure 7 To understand, assume that the first leaf node is Figure 7 The "text 4" node in the second leaf node is the "text 3" node, and the bifurcation node corresponding to the first leaf node and the second leaf node is the bold label (b) node, refer to Figure 7 It can be determined that the first node depth of the bifurcation node is 5.
[0172] Among them, the six intermediate nodes on the first path corresponding to the "text 4" node include: body tag (body) node, hierarchy tag (div) node, block tag (section) node, paragraph tag (p) node, bold tag (b) node, inline tag (span) node.
[0173] And the first node depth of the bifurcation node is 5, then in the first path, the intermediate nodes with a depth greater than 5 only include inline label (span) nodes, and referring to the above introduction, it can be determined that inline label (span) nodes are not block-level nodes, so there are no block-level nodes in the first path.
[0174] And, the five intermediate nodes on the second path corresponding to the "text 3" node include: a body tag (body) node, a hierarchy tag (div) node, a block tag (section) node, a paragraph tag (p) node, and a bold tag (b) node.
[0175] And the first node depth of the bifurcation node is 5, then in the second path, there is no intermediate node with a depth greater than 5, which correspondingly means that there is no block-level node in the second path.
[0176] Combine the following Figure 8 An example of the situation where block-level nodes exist is given, for example, Figure 8 In the example, the first leaf node is Figure 8 The "text 3" node in the second leaf node is the "text 2" node, and the bifurcation node corresponding to the first leaf node and the second leaf node is the paragraph tag (p) node. Figure 8 It can be determined that the first node depth of the bifurcation node is 4.
[0177] Among them, the five intermediate nodes on the first path corresponding to the "Text 3" node successively include: a body tag (body) node, a hierarchical tag (div) node, a block tag (section) node, a paragraph tag (p) node, and a bold tag (b) node.
[0178] And the depth of the first node of the bifurcation node is 4. Then, in the first path, the intermediate nodes with a depth greater than 4 only include the bold tag (b) node. And it can be determined with reference to the above introduction that the bold tag (b) node is a block-level node. Therefore, there is a block-level node in the first path.
[0179] And the four intermediate nodes on the second path corresponding to the "Text 2" node successively include: a body tag (body) node, a hierarchical tag (div) node, a block tag (section) node, and a paragraph tag (p) node.
[0180] And the depth of the first node of the bifurcation node is 5. Then, in the second path, there are no intermediate nodes with a depth greater than 4. Correspondingly, it also means that there are no block-level nodes in the second path.
[0181] S605: If there are block-level nodes, then determine the indication information corresponding to the first leaf node to indicate that the first leaf node and the second leaf node do not belong to the same paragraph.
[0182] In a possible implementation, if there is a block-level node among at least one intermediate node on the first path whose node depth is greater than the depth of the first node, or if there is a block-level node among at least one intermediate node on the second path whose node depth is greater than the depth of the first node, then it can be determined that there is a block-level element between the first leaf node and the second leaf node. Since the block-level element can indicate segmentation, it can be determined that the indication information corresponding to the first leaf node indicates that the first leaf node and the second leaf node do not belong to the same paragraph.
[0183] For example, in the example of 8 introduced above, there is a block-level node in the first path of the "Text 3" node. Correspondingly, it means that there is a paragraph tag (p) node between the "Text 4" node and the "Text 3" node. In this way, the content corresponding to the "Text 4" node and the "Text 3" node is divided into two natural paragraphs. Therefore, it can be determined that these two leaf nodes, the "Text 4" node and the "Text 3" node, do not belong to the same paragraph.
[0184] S606: If there are no block-level nodes, then determine the indication information corresponding to the first leaf node to indicate that the first leaf node and the second leaf node belong to the same paragraph.
[0185] In another possible implementation, if there is no block-level node in at least one intermediate node on the first path whose node depth is greater than the first node depth, and there is no block-level node in at least one intermediate node on the second path whose node depth is greater than the first node depth, then it can be determined that there is no block-level element between the first leaf node and the second leaf node, and therefore it can be determined that the indication information corresponding to the first leaf node indicates that the first leaf node and the second leaf node do not belong to the same paragraph.
[0186] For example, in the example 7 introduced above, there are no block-level nodes in the first path corresponding to the "Text 4" node and the second path corresponding to the "Text 3" node. This means that the contents corresponding to the "Text 4" node and the "Text 3" node are in the same natural paragraph. Therefore, it can be determined that the two leaf nodes, the "Text 4" node and the "Text 3" node, belong to the same paragraph.
[0187] S607. Determine at least one array according to the indication information corresponding to each leaf node in the data structure. The array includes at least one leaf node. The leaf nodes in the same array correspond to the same paragraph.
[0188] After determining the indication information corresponding to each leaf node in the data structure, at least one array can be determined according to the indication information corresponding to each leaf node in the data structure. Figure 8 To understand, assume that the final leaf node indication information is as follows Figure 8 As shown, only the indication information of the "text 4" node and the "text 7" node indicates that they correspond to the same paragraph as the previous leaf node, and the rest do not correspond to the same paragraph.
[0189] Based on this, we can determine that the "text 3" node and the "text 4" node correspond to the same paragraph, and the "text 6" node and the "text 6" node correspond to the same paragraph. Apart from this, there are no leaf nodes corresponding to the same paragraph.
[0190] Therefore, it can be determined Figure 8 In the six arrays shown, array 1 includes only the "text 1" node, array 2 includes only the "text 2" node, array 3 includes the "text 3" node and the "text 4" node, array 4 includes only the "image 1" node, array 5 includes only the "text 5" node, and array 6 includes the "text 6" node and the "text 7" node. It can be understood that the leaf nodes in the same array correspond to the same paragraph.
[0191] S608. For any first array in the at least one array, obtain node attributes of each leaf node in the first array.
[0192] After obtaining multiple arrays, the processing methods for each array are similar. Below, any one of the arrays will be taken as an example for illustration. Suppose the first array is used to represent it.
[0193] It can be understood that each leaf node corresponds to its own node attributes. The node attributes can include, for example, bold, italic, color, and so on. The node attributes can determine the display method of the content in the final leaf node. The specific node attributes can be selected and set according to actual needs. Therefore, in this embodiment, the node attributes of each leaf node in the first array can be obtained.
[0194] S609. Filter the node attributes of each leaf node in the first array to obtain the filtered node attributes of each leaf node.
[0195] It can be understood that the node attributes of each leaf node in the first array are actually the relevant attribute information in the first description document. These attribute information can be effectively displayed at the data source end. However, after being pasted into the rich text editor of the first application, whether the styles of various node attributes can be displayed depends on the specific implementation of the first application.
[0196] Therefore, in order to avoid problems such as errors and garbled codes, in this embodiment, the node attributes of each leaf node in the first array can be further filtered to obtain the filtered node attributes of each leaf node.
[0197] In a possible implementation manner, for example, according to the display styles supported by the first application, the node attributes that the first application can display can be selected from the node attributes of the leaf nodes, so as to obtain the filtered node attributes corresponding to each leaf node. For example, the original node attributes of the leaf node include the attribute of displaying a strikethrough, but the first application does not support adding a strikethrough, then this attribute is filtered out, and the remaining data after filtering, that is, the data that the first application can support, is determined as the filtered node attribute corresponding to the leaf node.
[0198] Or, according to the display styles supported by the first application, some attribute information in the node attributes of the leaf nodes can also be changed to obtain the filtered node attributes. For example, the original node attributes of the leaf node include more than 50 font colors, but the first application only supports 10 displayable colors. Then, according to the corresponding processing logic, the colors that the first application does not support displaying in the node attributes can be replaced with the colors that the first application can display, so as to obtain the filtered node attributes.
[0199] Therefore, based on the above introduction, it can be determined that filtering the node attributes of leaf nodes aims to process the leaf nodes into a style compatible with the first application, so as to ensure that the content to be pasted can be displayed normally.
[0200] S610. Determine the first sub-data corresponding to a paragraph in the first rich text data according to each leaf node in the first array. The first sub-data includes the data content of each leaf node and the filtered node attributes corresponding to each leaf node respectively.
[0201] In this embodiment, the first rich text data corresponding to the first description text can be generated according to multiple arrays. In a possible implementation manner, for example, each array can be processed separately. For example, for any first array, according to each leaf node in the first array, determine the first sub-data corresponding to a paragraph in the first rich text data. The first sub-data can include the data content of each leaf node, and the first sub-data can also include the filtered node attributes corresponding to each leaf node respectively.
[0202] That is to say, each first array is determined as the corresponding sub-data, where one sub-data corresponds to one natural paragraph, and the sub-data corresponding to multiple arrays respectively constitute the first rich text data.
[0203] For example, in the example introduced above, Figure 8 the sub-data corresponding to the 6 arrays respectively are:
[0204] Array 1 corresponds to sub-data 1: {type: "paragraph", children: Array(1), align: "left", indent: "0"};
[0205] Array 2 corresponds to sub-data 2: {type: "paragraph", children: Array(1), align: "left", indent: "0"};
[0206] Array 3 corresponds to sub-data 3: {type: "paragraph", children: Array(2), align: "left", indent: "0"};
[0207] Array 4 corresponds to sub-data 4: {type: "image-wrapper", children: Array(2), align: "left"};
[0208] The array 5 corresponds to the sub-data 5: {type: "paragraph", children: Array(1), align: "left", indent: "0"};
[0209] The array 6 corresponds to the sub-data 6: {type: "paragraph", children: Array(2), align: "left", indent: "0"}.
[0210] Among them, type represents the type of the sub-data, paragraph is the text type, image-wrapper is the image type, Array(1) identifies the element content in the array, align: "left" means the centering method is left-aligned, and indent: "0" means the first-line indent is 0.
[0211] Based on the above example, it can be determined that each sub-data includes the data content of the leaf nodes in the array, and also includes the filtered node attributes corresponding to each leaf node in the array.
[0212] S611. Render and display the rich text content corresponding to the first rich text data in the rich text editor, where each sub-data is displayed as a paragraph respectively.
[0213] After determining the first rich text data, the rich text content corresponding to the first rich text data can be rendered and displayed in the rich text editor, where each sub-data is displayed as a paragraph respectively.
[0214] In the rich text processing method provided by the embodiment of the present application, during the process of performing a depth-first search on the data structure, for each leaf node, the node information of each intermediate node on the path traversed to it can be recorded. The node information may include the node category and the node depth. Since the node information can be determined during the depth-first search process, the speed and efficiency of collecting node information can be effectively improved. Then, according to the depth of the bifurcation node between each leaf node and its previous leaf node, it is determined whether there is a blockiness node among the nodes at the same level after the bifurcation node on the first path and the second path. Then, it can be determined whether each leaf node and its previous leaf node belong to the same paragraph. Therefore, the determination of the indication information of the leaf node can be simply and effectively realized. Then, based on the indication information of the leaf node, the array is partitioned, and the leaf nodes corresponding to the same paragraph are partitioned into the same array. Therefore, the determination of the paragraph division situation in the copied content can be effectively realized. And in this embodiment, the node attributes of each leaf node can also be filtered to ensure that the filtered node attributes of the leaf node are compatible with the first application program, so as to ensure that the copied content is displayed orderly and correctly in the first application program and avoid display errors. At the same time, in this embodiment, when determining the first rich text data, each array can be processed separately, and the leaf nodes in an array are determined as a sub-data in the first rich text data. Each sub-data in the rich text data corresponds to a paragraph. Therefore, the paragraph information in the first description text can be effectively converted into the paragraph information in the first rich text data, so as to ensure that the paragraph display in the first rich text content is consistent with the paragraph display in the content to be pasted.
[0215] Based on the above-described embodiment, the following further combines Figure 10 to introduce the specific implementation manner of determining the node attributes of each node during the depth traversal process. Figure 10 is the flow of the rich text processing method provided by the embodiment of the present application Figure 3 .
[0216] As Figure 10 shown, the method includes:
[0217] S1001. During the depth-first search process, for any first node traversed, obtain the attribute information of the parent node of the first node.
[0218] Since the child node can integrate the attribute information of the parent node, in the process of depth-first search, in this embodiment, for any first node traversed, the attribute information of the parent node of the first node can be obtained. It can be understood that in the process of depth-first search, the attribute information of each layer of nodes is passed down in sequence, so that the lower-layer nodes can obtain the attribute information of their parent nodes.
[0219] The attribute information can include multiple
[0220] S1002. Determine the node attribute of the first node according to the attribute information of the parent node of the first node and the attribute information of the first node.
[0221] After obtaining the attribute information of the parent node of the first node and the attribute information of the first node, the node attribute of the first node can be determined by comprehensively considering these two aspects.
[0222] Among them, the attribute information of the parent node can be inherited by the child node, but if there is a repeated declaration of a certain attribute information in the child node, the attribute information declared by the child node will overwrite the attribute information of the parent node. Therefore, in this embodiment, it is necessary to combine the attribute information of the parent node of the first node and the attribute information of the first node itself to determine the node attribute of the first node.
[0223] In a possible implementation manner, the attribute information can include multiple sub-attributes. For example, bold is a sub-attribute, and italic is also a sub-attribute, and so on. For any one of the sub-attributes, if the attribute information of the first node attribute does not include the sub-attribute, then the sub-attribute of the parent node of the first node is determined as one of the node attributes of the first node. That is to say, if the first node itself does not declare this sub-attribute, then the sub-attribute of the parent node shall prevail.
[0224] Or, if the attribute information of the first node attribute includes the sub-attribute, then the sub-attribute of the first node is determined as one of the node attributes of the first node. That is to say, if a certain sub-attribute is repeatedly declared in the first node, then the sub-attribute of the first node shall prevail.
[0225] Correspondingly, the determined node attribute of the first node includes multiple attribute contents, and one of the attribute contents can also be understood as a sub-attribute introduced above.
[0226] In this embodiment, during the process of depth-first search, as the depth of the depth-first search increases, the attribute information of each layer can be passed to the next layer, and the fusion and modification can be performed layer by layer according to the implementation method introduced above. For example, the attribute information collected and modified during the search process can be stored in an object, which can be called a node attribute object. This can ensure that when the leaf node is finally reached, the attribute information in the node attribute object storing the final style is determined as the node attribute of the leaf node. Therefore, the correctness of the node attributes determined for each leaf node can be effectively ensured.
[0227] The above embodiments introduce various possible implementation methods of the rich text processing method. It can be understood that the rich text processing method provided in this embodiment is implemented based on the architecture of the rich text editor introduced above.
[0228] In a possible implementation method, the first description text corresponding to the content to be pasted introduced above can be, for example, the first application program obtains the first description text from the clipboard and sends the first description text to the plugin unit of the rich text editor.
[0229] For example, what the first application program specifically sends can be a first instruction. Then the plugin unit can receive the first instruction, and the first description text can be included in the first instruction. The first instruction is used to indicate inserting the content to be pasted corresponding to the first description text in the rich text editor.
[0230] And, the depth-first search of the data structure introduced above to determine the indication information corresponding to each of the multiple leaf nodes in the data structure. And the determination of at least one array according to the indication information corresponding to each of the leaf nodes in the data structure, for example, can be performed by the first plugin in the plugin unit, where the first plugin is a plugin for processing external paste data.
[0231] In the plugin unit of this embodiment, different plugins can be set for different functions. The implementation method of realizing the corresponding functions through multiple plugins can ensure that the processing between each function is independent of each other. When it is necessary to update and iterate certain functions, only the corresponding plugins need to be processed to achieve the goal. Thus, the flexibility of adjusting and controlling the rich text editor can be effectively improved.
[0232] And it can also be determined based on the above introduction that the rich text editor can further include a first rendering unit. When rendering and displaying the rich text content corresponding to the first rich text data in the rich text editor, for example, it can be through the first rendering unit that the rich text content corresponding to the first rich text data is rendered and displayed in the rich text editor.
[0233] Therefore, the following will further combine Figure 10 , and introduce the functions played by each unit in the architecture of the rich text editor during the rich text processing process. Figure 10 It is a schematic diagram of the processing process of the rich text processing method provided by the embodiment of the present application.
[0234] As Figure 10 shown, the first application may include a second rendering unit, an event processing unit, an instruction processing unit, and a rich text editor. And the rich text editor includes a first rendering unit, a recording unit, a plug-in unit, an execution unit, and a data processing unit.
[0235] The process includes:
[0236] 1. When the first application starts, the second rendering unit renders the graphical user interface of the first application.
[0237] The second rendering unit can be understood as the UI rendering layer in the first application. When the first application starts, the second rendering unit can render the graphical user interface of the first application. Taking the memo as an example, for example, it can render the file list, note list, and user event response area in the graphical user interface of the memo introduced above. Among them, the file list displays the user's file classification, the note list displays the rich text list stored in the folder, and the user event response area displays the edit operations that the user can perform on the rich text content.
[0238] 2. The second rendering unit sends an initialization instruction to the rich text editor.
[0239] After the first application starts, it is necessary to initialize the data model of the rich text content displayed in the rich text editor.
[0240] In a possible implementation manner, there are multiple rich text content lists on the graphical user interface of the first application. For example, the user can select to open a certain rich text content in the list, then it is necessary to display the rich text content selected by the user in the rich text editor accordingly. Therefore, the current initialization instruction can be to indicate the processing of the rich text content selected by the user to determine its corresponding data model, that is, whatever content is displayed in the rich text editor, the data model corresponding to the displayed content is initialized and generated. The data model in this embodiment can be understood as the rich text data in the JSON format introduced above.
[0241] 3. The first rendering unit in the rich text editor initializes the data model of the rich text content in the rich text editor according to the initialization instruction.
[0242] In this embodiment, the initialization instruction is used to instruct the rich text editor to generate a data model for the rich text content displayed in the rich text editor. Therefore, after receiving the initialization instruction, the rich text editor can generate the data model for the rich text content corresponding to the above display operation.
[0243] For example, it can be understood with reference to Figure 3 When the user selects a note with the title "Test Document", the initialization instruction is used to instruct the rich text editor to generate a data model corresponding to "Test Document." in the note content. After that, for example, "Test Document." can be displayed in the rich text editor.
[0244] In a possible implementation manner, the data model corresponding to the rich text content exists in the form of a tree structure. For example, in Figure 3 the example of, if the rich text content is "Test Document.", the data model corresponding to the rich text content can be represented as:
[0245]
[0246] Among them, the type field can set the element type of the rich text content. Paragraph indicates that the element type is text, and the specific rich text content of the element of the paragraph type is stored in children. For example, in Figure 3 the example of, the content of the element of the paragraph type is "Test Document.".
[0247] 4. The second rendering unit sends a start instruction to the instruction processing unit. The start instruction is used to instruct the instruction processing unit to start.
[0248] When the memo is started, the second rendering unit can also instruct the instruction processing unit to start. In a possible implementation manner, the second rendering unit can, for example, send a corresponding start instruction to the instruction processing unit to start the instruction processing unit.
[0249] After the instruction processing unit starts, it can register the function instructions supported by the first application, such as the bold instruction, the italic setting instruction, etc. The instructions that the instruction unit needs to register can depend on the instructions specifically supported by the first application. This embodiment does not limit the specific implementation of registering instructions.
[0250] 5. When the second rendering unit detects a paste operation, it determines the first event triggered by the paste operation.
[0251] After the rich text editor finishes initializing the rich text content, the user can perform corresponding operations in the rich text editor. In this embodiment, for example, the user can perform external paste in the rich text editor, that is, copy data from other data sources and paste it into the rich text editor.
[0252] When the second rendering unit detects a paste operation, the second rendering unit can determine the first event triggered by the paste operation, where the first event can be understood as a paste event. The corresponding relationship between user operations and the events they trigger can be preset, for example. Therefore, this embodiment does not limit the specific implementation of the first event, and it can be selected and set according to actual needs.
[0253] 6. The second rendering unit sends the first event to the event processing unit.
[0254] 7. The event processing unit determines the operation intention corresponding to the first event.
[0255] After receiving the first event sent by the second rendering unit, the event processing unit can, for example, parse the first event to determine the operation intention corresponding to the first event. In one possible implementation, for example, it can parse the operation field in the indication information of the first event to determine the operation intention corresponding to the first event, or it can also determine the operation intention corresponding to the first event according to the matching relationship between the event and the intention. After determining the operation intention, the event processing unit can send the operation intention to the instruction processing unit.
[0256] 8. The event processing unit sends the operation intention to the instruction processing unit.
[0257] 9. The instruction processing unit determines the first instruction corresponding to the operation intention.
[0258] After receiving the operation intention sent by the event processing unit, since the instruction processing unit has registered instructions, it can match the operation intention with the registered instructions and convert the user's operation intention into the first instruction according to the matching result. For example, if the operation intention is to insert the content to be pasted in the rich text editor, the corresponding instruction that can be matched is the instruction to insert the paste content.
[0259] Among them, the corresponding relationship between the operation intention and the instruction can be selected and set according to actual needs, and this embodiment does not limit this.
[0260] 10. The instruction processing unit sends the first instruction to the plugin unit of the rich text editor.
[0261] In a possible implementation, if there is a first instruction in the instruction processing unit that matches the operation intention, that is, there is a corresponding instruction registered in the instruction processing unit, then the instruction processing unit can send the first instruction to the rich text editor so that the rich text editor can perform corresponding processing according to the first instruction.
[0262] 11. The plugin unit obtains the operation information corresponding to the first operation and the target operation type corresponding to the first instruction according to the first instruction.
[0263] In this embodiment, there are multiple plugins in the plugin unit, and different plugins are used to implement different functions. For example, there is a bold plugin for the bold function, an italic plugin for the italic function, and an external paste plugin for the external paste function. Or, it is also possible that the above-introduced bold function and italic function correspond to a property setting plugin. Therefore, it can be understood that in the actual implementation process, the specific implementation method of the plugin can be selected and set according to actual needs, as long as it is ensured that for each function, there is a corresponding plugin to implement the function.
[0264] After the rich text editor receives the first instruction, for example, it can first determine the target plugin corresponding to the first instruction in the plugin unit. For example, in this embodiment, assume that the first instruction is used to indicate inserting the content to be pasted corresponding to the first description text in the rich text editor, then, for example, the corresponding target plugin can be determined as the external paste plugin.
[0265] After that, the first instruction can be processed by the target plugin. For example, the first plugin can obtain the operation information corresponding to the first operation and the target operation type corresponding to the first instruction.
[0266] Among them, the operation information corresponding to the first operation can, for example, include the multiple arrays introduced above. That is, the first plugin can, based on the above-introduced content, receive the first instruction, obtain the first description text from the first instruction, and parse to obtain the data structure corresponding to the first description text. Then, a depth-first search can be performed on the data structure to determine the indication information corresponding to each of the multiple leaf nodes in the data structure, and at least one array can be determined according to the indication information corresponding to each leaf node in the data structure. The specific implementation method can refer to the introduction of the above embodiment and will not be elaborated here.
[0267] In addition, in this embodiment, the first instruction can also be processed by the target plugin to determine the target operation type corresponding to the first instruction among multiple preset operation types.
[0268] The preset operation types may include the following nine types: inserting a node, splitting a node, inserting a selection area, moving a node, inserting text, merging nodes, setting attributes, removing a node, and removing text.
[0269] Then, for the first instruction used to indicate the content to be pasted corresponding to inserting the first description text in the rich text editor, the corresponding target operation type may be inserting a node, that is, inserting a new node part at a specified position in the data model, and this new node part corresponds to the data part of the content to be pasted.
[0270] Inserting a node means inserting a new node in the data model. Splitting a node means splitting an existing node in the data structure into multiple nodes. Inserting a selection area means selecting content by mouse in the rich text content to obtain at least one selection area. Moving a node means moving the specific content in the rich text content to change the position of the corresponding node in the data model. Inserting text means inserting text into a node, and this operation only changes the content in the node without changing the tree structure of the data model. Merging nodes means merging two original independent nodes into one node. Setting attributes means setting attributes for the corresponding content in the rich text content, and the corresponding update in the data model is adding the corresponding attributes to the corresponding nodes. Removing a node means deleting the corresponding node in the data model when the corresponding content in the text is deleted. Removing text means removing a part of the text in a node, and this operation only changes the content in the node without changing the tree structure of the data model.
[0271] The nine operation types introduced above can also be understood as nine atomic operations. In the actual implementation process, the specific division of the operation types and the update method of the data model for each operation type can be selected and set according to actual needs, and this embodiment does not limit this.
[0272] 12. The plugin unit sends an identification instruction to the data processing unit.
[0273] It can be understood that after the plugin unit determines the operation information corresponding to the first operation and the target operation type of the first operation, in order to specifically implement the first operation, it is also necessary to determine the operation position corresponding to the first operation. Therefore, in a possible implementation manner, the plugin unit in the rich text editor can send an identification instruction to the data processing unit, where the identification instruction is used to instruct the data processing unit to determine the operation position corresponding to the first operation.
[0274] 13. The data processing unit determines the operation position corresponding to the first operation according to the identification instruction.
[0275] In this step, the data processing unit can determine the operation position corresponding to the first operation in response to the recognition instruction. In a possible implementation, the operation position corresponding to the first operation can be, for example, the cursor position or the selection area position in the rich text editor.
[0276] 14. The data processing unit sends the operation position corresponding to the first operation to the plugin unit.
[0277] After determining the operation position corresponding to the first operation, the data processing unit can send the operation position to the plugin unit so that the plugin unit can determine the specific operation position.
[0278] 15. The plugin unit sends the operation position, the target operation type, and the operation position to the execution unit.
[0279] After receiving the operation position sent by the data processing unit, the plugin unit has all the information for performing the first operation. Specifically, the plugin unit has determined the operation information of the first operation and the target operation type corresponding to the first operation, and currently has also determined the operation position corresponding to the first operation.
[0280] However, these information cannot be directly processed by the data processing unit and still need to be encapsulated by the execution unit. Therefore, in this embodiment, the plugin unit can send the operation information, the target operation type, and the operation position to the execution unit.
[0281] 16. The execution unit generates indication information based on the operation position, the target operation type, and the operation position.
[0282] After receiving the operation information, the target operation type, and the operation position, the execution unit can, for example, encapsulate these information to generate indication information that can be recognized by the data processing unit. Then it can be understood that the indication information actually includes the operation information, the target operation type, and the operation position.
[0283] 17. The execution unit sends the indication information to the data processing unit.
[0284] After generating the indication information, the execution unit can send the indication information to the data processing unit, where the indication information is used to instruct the data processing unit to update the data model corresponding to the rich text content displayed in the rich text editor.
[0285] 18. The data processing unit updates the data model according to the indication information.
[0286] After receiving the indication information, the data processing unit can update the data model in response to the indication information. For example, in the application scenario of external paste introduced in this embodiment, for the update of the data model, the first rich text data in JSON format determined above can be added to the data model corresponding to the rich text content in the rich text editor (which can also be understood as the original rich text data). Or it can also be understood as adding the sub-tree structure corresponding to the first rich text data to the tree structure corresponding to the rich text content in the rich text editor.
[0287] 19. The data processing unit sends indication information to the recording unit.
[0288] After the data processing unit updates the data structure corresponding to the rich text content according to the indication information, it only needs to render the rich text content based on the updated data structure.
[0289] In a possible implementation manner, to facilitate the backtracking of operations, a recording unit is further included in the rich text editor in this embodiment. Before rendering, the data processing unit can also send indication information to the recording unit.
[0290] 20. The recording unit stores the indication information to record the user's operations.
[0291] After receiving the indication information, the recording unit can store the indication information in the first stack, where the first stack is used to store the indication information corresponding to the completed operations.
[0292] Among them, the first stack can be understood as an undos (undo) stack. When the user needs to undo an operation, the indication information can be obtained from the top of the first stack, and the update operation corresponding to the indication information in the data structure corresponding to the rich text content can be undone to implement the undo of the corresponding instruction.
[0293] Based on the understanding of the first stack introduced above, in this embodiment, various rich text operations are divided into several preset operation types, which can facilitate the recording and management of operations, thereby improving the processing efficiency and standardization of the rich text editor.
[0294] And in the recording unit, for example, a second stack can also be included. When the rich text editor receives an undo instruction, the plugin unit can obtain the indication information located at the top of the first stack; the plugin unit undoes the update operation corresponding to the indication information located at the top of the stack in the data structure corresponding to the rich text content; renders and displays the rich text content according to the data structure after undoing the update operation; and stores the indication information located at the top of the stack into the second stack, where the second stack is used to store the indication information corresponding to the undone operations.
[0295] 21. The recording unit notifies the first rendering unit that the operation recording is completed.
[0296] 22. The first rendering unit renders and displays the rich text content after the first operation according to the updated data model.
[0297] After storing the indication information corresponding to the operation in the first stack, the first rendering unit can render and display the rich text content according to the updated data structure, because the updated data structure already includes the updates of the corresponding content. Therefore, the rich text content after rendering and display can show the changes corresponding to the first operation. That is, the data to be pasted is processed into the corresponding rich text content and displayed in the rich text editor. And because the rich text content has been processed as described above, the rich text content can show the same paragraph format as the content to be pasted and the style compatible with the first application.
[0298] 23. The first rendering unit sends feedback information to the second rendering unit to indicate that the first instruction processing is completed.
[0299] 24. The second rendering unit renders and displays the changes of the controls in the graphical user interface.
[0300] After the first rendering unit finishes rendering the interface transformation corresponding to the first instruction, it can send indication information to the second rendering unit. Then, the second rendering unit can make corresponding changes to the controls that need to be changed in the graphical user interface of the first application according to the indication information. For example, the bold control "B" may need to be highlighted, selected, etc. The specific control change situation can be selected and set according to actual needs.
[0301] The specific implementation of each operation in this embodiment can refer to the changes in the above embodiment and will not be elaborated here. To sum up.
[0302] In this embodiment, multiple subunits in the rich text editor cooperate with each other. The plugin unit is used to determine the operation data corresponding to the first operation. The data processing unit can determine the operation position. And then the plugin unit can send the information required for the first operation to the execution unit, encapsulated as indication information that can be recognized by the data processing unit. Then the data processing unit updates the data structure according to the indication information, and the recording unit records each update indication. Finally, the first rendering unit renders and displays the updated rich text content. Through the cooperation of the above five subunits, the rich text editing function of the rich text editor for external source pasted rich text can be effectively realized.
[0303] Next, it can be further combined with Figure 11 to visually illustrate the specific implementation of the rich text processing method provided in this application.Figure 11 Schematic diagram for implementing the rich text processing method provided by the embodiment of the present application.
[0304] As Figure 11 shown, assume that the user selects a part of the content on Web page A. This part of the content includes both text and pictures, and at the same time, these texts have their own paragraph formats and some display styles. Based on the method introduced in the above embodiment, paste this part of the content to be pasted into the rich text editor, and the rich text content as shown in the rich text editor in Figure 11 can be displayed.
[0305] Referring to Figure 11 it can be determined that the paragraph format and display style of the content pasted in the rich text editor are the same as those of the content copied from the source web page.
[0306] In summary, the rich text processing method provided by the present application can accurately and effectively parse the paragraph information of the content to be pasted, and can accurately and effectively parse the style information of the content to be pasted, and process it into the style information compatible with the first application program, and can parse the first description text in html format into the first rich text data in JSON format compatible with the rich text editor. Therefore, it can ensure that the content to be pasted is copied into the rich text editor while maintaining the paragraph format and display style of the content to be pasted, so as to effectively improve the comprehensiveness of data processing in the external source paste scenario.
[0307] Figure 12 Schematic diagram of the structure of the rich text processing device provided by the embodiment of the present application. As Figure 12 shown, the device 120 includes: a receiving module 1201, a determining module 1202, and a processing module 1203.
[0308] The receiving module 1201 is configured to receive the first description text corresponding to the content to be pasted, and parse to obtain the data structure corresponding to the first description text, where the data structure includes at least one node;
[0309] The determining module 1202 is configured to perform a depth-first search on the data structure to determine the indication information corresponding to each of the multiple leaf nodes in the data structure, where the indication information is used to indicate whether the leaf node and the previous leaf node of the leaf node in the data structure correspond to the same paragraph;
[0310] The determining module 1202 is further configured to determine at least one array according to the indication information corresponding to each of the leaf nodes in the data structure, where the array includes at least one leaf node, and the leaf nodes in the same array correspond to the same paragraph;
[0311] A processing module 1203 is configured to generate first rich text data corresponding to the first description text according to the at least one array, and render and display rich text content corresponding to the first rich text data in the rich text editor.
[0312] In a possible design, the determining module 1202 is specifically configured to:
[0313] Perform a depth-first search on the data structure, and during the depth-first search, for any first leaf node among the multiple leaf nodes, record node information of each intermediate node on the path traversed to the first leaf node, where the node information includes at least one of the following: node category and node depth, and the node category is used to indicate whether the intermediate node is a block-level node;
[0314] Determine a bifurcation node at which the first leaf node bifurcates from a second leaf node in the data structure, where the second leaf node is the leaf node preceding the first leaf node in the data structure;
[0315] Determine indication information corresponding to the first leaf node according to the bifurcation node and the node information of each intermediate node.
[0316] In a possible design, the determining module 1202 is specifically configured to:
[0317] According to a first node depth corresponding to the bifurcation node, determine whether there is a block-level node among at least one intermediate node with a node depth greater than the first node depth on a first path and a second path, where the first path is the path traversed to the first leaf node during the depth-first search, and the second path is the path traversed to the second leaf node during the depth-first search;
[0318] If there is the block-level node, determine that the indication information corresponding to the first leaf node is used to indicate that the first leaf node and the second leaf node do not belong to the same paragraph;
[0319] If there is no such block-level node, determine that the indication information corresponding to the first leaf node is used to indicate that the first leaf node and the second leaf node belong to the same paragraph.
[0320] In a possible design, the processing module 1203 is further configured to:
[0321] During the depth-first search, for any first node traversed, obtain attribute information of the parent node of the first node;
[0322] Determine the node attribute of the first node according to the attribute information of the parent node of the first node and the attribute information of the first node.
[0323] In a possible design, the attribute information includes at least one sub-attribute;
[0324] The determining module 1202 is specifically configured to:
[0325] For any one of the sub-attributes, if the attribute information of the first node attribute does not include the sub-attribute, then determine the sub-attribute of the parent node of the first node as one of the node attributes of the first node;
[0326] If the attribute information of the first node attribute includes the sub-attribute, then determine the sub-attribute of the first node as one of the node attributes of the first node.
[0327] In a possible design, each leaf node in the array carries its own node attribute;
[0328] The processing module 1203 is specifically configured to:
[0329] For any one first array in the at least one array, obtain the node attributes of each leaf node in the first array;
[0330] Perform filtering processing on the node attributes of each leaf node in the first array to obtain the filtered node attributes of each leaf node;
[0331] According to each leaf node in the first array, determine the first sub-data corresponding to a paragraph in the first rich text data, and the first sub-data includes the data content of each leaf node and the filtered node attributes corresponding to each leaf node;
[0332] Render and display the rich text content corresponding to the first rich text data in the rich text editor, where each sub-data is displayed as a paragraph.
[0333] In a possible design, the rich text editor includes a plugin unit;
[0334] The receiving module 1201 is specifically configured to:
[0335] The plugin unit receives a first instruction, and the first instruction includes the first description text, and the first instruction is used to instruct to insert the content to be pasted corresponding to the first description text in the rich text editor.
[0336] In a possible design, the rich text editor further includes a first rendering unit;
[0337] The processing module 1203 is specifically configured to:
[0338] Through the first rendering unit, render and display the rich text content corresponding to the first rich text data in the rich text editor.
[0339] The device provided in this embodiment can be used to execute the technical solutions of the above method embodiments. The implementation principles and technical effects are similar, and will not be elaborated here.
[0340] The rich text processing method provided in the embodiments of the present application can be applied to an electronic device with communication functions. The electronic device includes a terminal device. The specific device form of the terminal device and the like can refer to the above relevant description and will not be elaborated here.
[0341] The embodiments of the present application provide a terminal device, which can be understood by referring to Figure 13 for understanding, Figure 13 which is a schematic hardware structure diagram of the terminal device provided in the embodiments of the present application.
[0342] As Figure 13 shown, the terminal device 130 includes: a processor 1301 and a memory 1302; the memory 1302 stores computer execution instructions; the processor 1301 executes the computer execution instructions stored in the memory 1302, so that the terminal device 130 executes the above method.
[0343] When the memory 1302 is independently provided, the terminal device further includes a bus 1203 for connecting the memory 1202 and the processor 1301.
[0344] The embodiments of the present application provide a chip. The chip includes a processor, and the processor is used to call a computer program in the memory to execute the technical solutions in the above embodiments. The implementation principles and technical effects are similar to those of the above relevant embodiments and will not be elaborated here.
[0345] The embodiments of the present application also provide a computer-readable storage medium. The computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the above method is implemented. The methods described in the above embodiments can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. If implemented in software, the functions can be stored as one or more instructions or codes on a computer-readable medium or transmitted on a computer-readable medium. The computer-readable medium can include a computer storage medium and a communication medium, and can also include any medium that can transfer a computer program from one place to another. The storage medium can be any target medium accessible by a computer.
[0346] In one possible implementation, the computer-readable medium may include RAM, ROM, compact disc read-only memory (CD-ROM), or other optical disc storage, magnetic disk storage, or any other medium that is targeted to carry or store the desired program code in the form of instructions or data structures and that can be accessed by a computer. Moreover, any connection is properly termed a computer-readable medium. For example, if software is transmitted from a website, server, or other remote source using coaxial cable, fiber optic cable, twisted pair, Digital Subscriber Line (DSL), or wireless technologies such as infrared, radio, and microwave, then the coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of the medium. As used herein, disk and disc include optical disc, laser disc, optical disc, Digital Versatile Disc (DVD), floppy disk, and Blu-ray disc, where disks typically reproduce data magnetically, while discs reproduce data optically using lasers. Combinations of the above should also be included within the scope of computer-readable media.
[0347] An embodiment of the present application provides a computer program product. The computer program product includes a computer program that, when run, causes a computer to execute the above method.
[0348] Embodiments of the present application are described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and combinations of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processing unit of a general-purpose computer, special-purpose computer, embedded processor, or other programmable device to generate a machine such that the instructions executed by the processing unit of the computer or other programmable data processing device produce means for implementing the functions specified in one Figure 1 one flow or multiple flows and / or blocks Figure 1 one block or multiple blocks.
[0349] The above specific implementation manners further elaborate on the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above are only specific implementation manners of the present invention and are not used to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made on the basis of the technical solution of the present invention should be included within the protection scope of the present invention.
Claims
1. A rich text processing method, characterized in that, applied to a rich text editor in a first application, the method comprising: receiving a first description text corresponding to content to be pasted, and parsing to obtain a data structure corresponding to the first description text, the data structure including at least one node; performing a depth-first search on the data structure to determine indication information corresponding to each of a plurality of leaf nodes in the data structure, the indication information being used to indicate whether the leaf node and the previous leaf node of the leaf node in the data structure correspond to the same paragraph; determining at least one array according to the indication information corresponding to each of the leaf nodes in the data structure, the array including at least one leaf node, and the leaf nodes in the same array corresponding to the same paragraph; generating first rich text data corresponding to the first description text according to the at least one array, and rendering and displaying rich text content corresponding to the first rich text data in the rich text editor.
2. The method according to claim 1, characterized in that, the performing a depth-first search on the data structure to determine indication information corresponding to each of the leaf nodes in the data structure includes: performing a depth-first search on the data structure, and during the depth-first search, for any first leaf node among the plurality of leaf nodes, recording node information of each intermediate node on the path of traversing to the first leaf node, the node information including at least one of the following: node category and node depth, the node category being used to indicate whether the intermediate node is a block-level node; determining a bifurcation node at which the first leaf node and a second leaf node bifurcate in the data structure, the second leaf node being the previous leaf node of the first leaf node in the data structure; determining indication information corresponding to the first leaf node according to the bifurcation node and the node information of each of the intermediate nodes.
3. The method according to claim 2, characterized in that, the determining indication information corresponding to the first leaf node according to the bifurcation node and the node information of each of the intermediate nodes includes: determining whether there is a block-level node among at least one intermediate node with a node depth greater than the first node depth on a first path and a second path according to the first node depth corresponding to the bifurcation node, the first path being the path of traversing to the first leaf node during the depth-first search, and the second path being the path of traversing to the second leaf node during the depth-first search; if there is the block-level node, determining that the indication information corresponding to the first leaf node is used to indicate that the first leaf node and the second leaf node do not belong to the same paragraph; if there is no block-level node, determining that the indication information corresponding to the first leaf node is used to indicate that the first leaf node and the second leaf node belong to the same paragraph.
4. The method according to any one of claims 1-3, characterized in that, the method further includes: During the process of the depth - first search, for any first node traversed, obtain the attribute information of the parent node of the first node; Determine the node attribute of the first node according to the attribute information of the parent node of the first node and the attribute information of the first node.
5. The method according to claim 4, wherein, the attribute information includes at least one sub - attribute; The determining the node attribute of the first node according to the attribute information of the parent node of the first node and the attribute information of the first node includes: For any one of the sub - attributes, if the attribute information of the first node does not include the sub - attribute, then determine the sub - attribute of the parent node of the first node as one item of the node attribute of the first node; If the attribute information of the first node includes the sub - attribute, then determine the sub - attribute of the first node as one item of the node attribute of the first node.
6. The method according to claim 5, wherein, each leaf node in the array carries its own node attribute; The generating the first rich - text data corresponding to the first description text according to the at least one array, rendering and displaying the rich - text content corresponding to the first rich - text data in the rich - text editor includes: For any first array in the at least one array, obtain the respective node attributes of each leaf node in the first array; Perform filtering processing on the respective node attributes of each leaf node in the first array to obtain the respective filtered node attributes of each leaf node; According to each leaf node in the first array, determine the first sub - data corresponding to a paragraph in the first rich - text data, where the first sub - data includes the data content of each leaf node and the respective filtered node attributes corresponding to each leaf node; According to the first rich - text data, render and display the rich - text content corresponding to the first rich - text data in the rich - text editor, where each sub - data is displayed as a paragraph respectively.
7. The method according to any one of claims 1 - 6, wherein, the rich - text editor includes a plugin unit; The receiving the first description text corresponding to the content to be pasted includes: The plugin unit receives a first instruction, and the first instruction includes the first description text, and the first instruction is used to indicate inserting the content to be pasted corresponding to the first description text in the rich - text editor.
8. The method according to any one of claims 1 - 7, wherein, the rich - text editor further includes a first rendering unit; The rendering and displaying the rich - text content corresponding to the first rich - text data in the rich - text editor includes: Through the first rendering unit, render and display the rich - text content corresponding to the first rich - text data in the rich - text editor.
9. A rich - text processing device, wherein, applied to the rich - text editor in a first application program, the device includes: A receiving module, configured to receive a first description text corresponding to content to be pasted, and parse to obtain a data structure corresponding to the first description text, where the data structure includes at least one node; A determining module, configured to perform a depth-first search on the data structure to determine indication information corresponding to each of a plurality of leaf nodes in the data structure, where the indication information is used to indicate whether the leaf node and the previous leaf node of the leaf node in the data structure correspond to the same paragraph; The determining module is further configured to determine at least one array according to the indication information corresponding to each of the leaf nodes in the data structure, where the array includes at least one leaf node, and the leaf nodes in the same array correspond to the same paragraph; A processing module, configured to generate first rich text data corresponding to the first description text according to the at least one array, and render and display rich text content corresponding to the first rich text data in the rich text editor.
10. A terminal device Characterized in that It includes: A processor and a memory; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the terminal device executes the method according to any one of claims 1-8.
11. A computer-readable storage medium, where the computer-readable storage medium stores a computer program, Characterized in that When the computer program is executed by a processor, the method according to any one of claims 1-8 is implemented.
12. A computer program product Characterized in that It includes a computer program, and when the computer program is run, the computer is made to execute the method according to any one of claims 1-8.
Citation Information
Patent Citations
Page processing method and device
CN108874379A
Text processing method and device, computer equipment and storage medium
CN112001153A