A method and terminal for displaying and refreshing rich text

By combining pre-customized JSON Schema and rendering components, the problem of limited data format of traditional rich text editors is solved, high scalability and maintainability is achieved, and real-time rendering and updates are performed during user operations, improving user experience .

CN114510907BActive Publication Date: 2024-11-22FUJIAN TIANQUAN EDUCATION TECH LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011277775.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-11-16
Publication Date
2024-11-22
Estimated Expiration
2040-11-16

AI Technical Summary

Technical Problem

The data format of traditional front-end rich text editors is limited by the DOM tree format, which has poor scalability, resulting in reduced maintenance.

Method used

The pre-customized data storage format JSON Schema is used to render according to element types and attributes. It supports nested rendering of custom elements and text nodes, and converts it into atomic operations to update JSON Schema when the user operates.

Benefits of technology

It improves the scalability of the data format and maintainability of the code, realizes nested rendering of custom elements and real-time page updates, and improves the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114510907B_ABST
    Figure CN114510907B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and terminal for displaying and refreshing rich text. The present invention obtains all custom elements and text nodes according to a pre-customized data storage format JSON Schema. If it is a custom element, a rendering component corresponding to the element type in a rich text editor is called according to the element type and custom attributes of the custom element, and the corresponding rendering component renders and generates page content corresponding to the custom attribute. If it is a text node, the text rendering component renders the text content of the text node according to the custom attribute of the text node to generate the text content. Based on the background and idea of ​​front-end componentization, the present invention pre-customizes the data storage format JSON Schema, has a high degree of freedom, improves the extensibility of the data format, and selects the corresponding component for rendering according to the type of page element, thereby improving the maintainability of the code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of Web front-end development, and in particular to a method and a terminal for displaying and refreshing rich text. Background Art

[0002] Traditional front-end rich text editors use data based on the DOM tree (Document Object Model), and rendering is done by calling the DOM API interface to perform various operations. In this way, the data format is limited by the format of the DOM tree, and the scalability is limited. As the code size increases, maintainability decreases rapidly. Summary of the invention

[0003] The technical problem to be solved by the present invention is to provide a method and terminal for displaying and refreshing rich text, so as to improve the extensibility of data format and the maintainability of code.

[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is:

[0005] A method for displaying and refreshing rich text, comprising:

[0006] S1. Obtain all custom elements and text nodes according to the pre-defined data storage format JSON Schema;

[0007] S2. If it is a custom element, then according to the element type and custom attributes of the custom element, a rendering component corresponding to the element type in the rich text editor is called, and the corresponding rendering component renders and generates page content corresponding to the custom attributes;

[0008] S3. If it is a text node, a text rendering component renders the text content of the text node according to the custom attributes of the text node to generate text content.

[0009] In order to solve the above technical problems, the technical solution adopted by the present invention is:

[0010] A terminal for rich text display and refresh includes a processor, a memory, and an executable computer program stored in the memory and run on the processor, wherein when the processor executes the executable computer program, the following steps are implemented:

[0011] S1. Obtain all custom elements and text nodes according to the pre-defined data storage format JSON Schema;

[0012] S2. If it is a custom element, then according to the element type and custom attributes of the custom element, a rendering component corresponding to the element type in the rich text editor is called, and the corresponding rendering component renders and generates page content corresponding to the custom attributes;

[0013] S3. If it is a text node, a text rendering component renders the text content of the text node according to the custom attributes of the text node to generate text content.

[0014] The beneficial effects of the present invention are as follows: based on the background and ideas of front-end componentization, the present invention pre-customizes the data storage format JSON Schema, has a high degree of freedom, improves the scalability of the data format, and selects corresponding components for rendering according to the type of page elements, thereby improving the maintainability of the code. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 A flowchart of a method for displaying and refreshing rich text according to an embodiment of the present invention;

[0016] Figure 2 A structural diagram of a terminal for rich text display and refresh according to an embodiment of the present invention;

[0017] Description of labels:

[0018] 1. A terminal for displaying and refreshing rich text; 2. A processor; 3. A memory. DETAILED DESCRIPTION

[0019] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.

[0020] Please refer to Figure 1 , a method for rich text display and refresh, comprising:

[0021] S1. Obtain all custom elements and text nodes according to the pre-defined data storage format JSON Schema;

[0022] S2. If it is a custom element, then according to the element type and custom attributes of the custom element, a rendering component corresponding to the element type in the rich text editor is called, and the corresponding rendering component renders and generates page content corresponding to the custom attributes;

[0023] S3. If it is a text node, a text rendering component renders the text content of the text node according to the custom attributes of the text node to generate text content.

[0024] From the above description, it can be seen that the beneficial effects of the present invention are: based on the background and ideas of front-end componentization, the present invention pre-customizes the data storage format JSON Schema, has a high degree of freedom, improves the scalability of the data format, and selects the corresponding component for rendering according to the type of page element, thereby improving the maintainability of the code.

[0025] Furthermore, the custom elements can be nested with each other, but the text nodes cannot be nested.

[0026] It can be seen from the above description that the custom elements can be nested with each other, and the degree of freedom and scalability are higher.

[0027] Furthermore, the step S2 further includes:

[0028] The corresponding rendering component determines whether there is a nested child node in the custom element. If there is a child node, the custom element is the corresponding parent node, and the content of the child node is rendered at the corresponding position of the page content of the parent node according to the attributes of the child node.

[0029] From the above description, we can see that for nested custom elements, rendering the child node content at the corresponding position of the parent node according to its attributes is more in line with the needs of page design and more rigorous.

[0030] Furthermore, after step S3, the following steps are further included:

[0031] S4. Obtain an operation request from the user, and according to the selected content in the operation request, call a first rendering component corresponding to the selected content to process the operation request, where the operation request includes an operation that does not change the JSON Schema and an operation that changes the JSON Schema.

[0032] From the above description, it can be seen that according to the clicked content in the user request, the corresponding rendering component responsible for rendering the content is selected for processing, and the conditions for selecting the component for processing are clear, which further improves maintainability.

[0033] Furthermore, in step S4, calling the first rendering component corresponding to the selected content to process the operation request is specifically as follows:

[0034] Calling a first rendering component corresponding to the selected content;

[0035] Determine whether the operation request is an operation that does not change the JSON Schema. If so, the first rendering component performs corresponding processing according to the operation request.

[0036] Otherwise, the first rendering component converts the operation request into one or more atomic operations corresponding to the JSON Schema, modifies the JSON Schema according to the atomic operations, generates a new JSON Schema, obtains all custom elements and text nodes according to the new JSON Schema, and executes steps S2 and S3 to refresh and re-render the page.

[0037] From the above description, it can be seen that when a user changes the JSON Schema, the operation needs to be converted into an atomic operation for processing, and then the page is refreshed and re-rendered, so that the user's modification can get real-time feedback, improving the user experience.

[0038] Please refer to Figure 2 , a terminal for rich text display and refresh, comprising a processor, a memory, and an executable computer program stored in the memory and executable on the processor, wherein when the processor executes the executable computer program, the following steps are implemented:

[0039] S1. Obtain all custom elements and text nodes according to the pre-defined data storage format JSON Schema;

[0040] S2. If it is a custom element, then according to the element type and custom attributes of the custom element, a rendering component corresponding to the element type in the rich text editor is called, and the corresponding rendering component renders and generates page content corresponding to the custom attributes;

[0041] S3. If it is a text node, a text rendering component renders the text content of the text node according to the custom attributes of the text node to generate text content.

[0042] From the above description, it can be seen that the beneficial effects of the present invention are: based on the background and ideas of front-end componentization, the present invention pre-customizes the data storage format JSON Schema, has a high degree of freedom, improves the scalability of the data format, and selects the corresponding component for rendering according to the type of page element, thereby improving the maintainability of the code.

[0043] Furthermore, the custom elements can be nested with each other, but the text nodes cannot be nested.

[0044] It can be seen from the above description that the custom elements can be nested with each other, and the degree of freedom and scalability are higher.

[0045] Furthermore, the step S2 further includes:

[0046] The corresponding rendering component determines whether there is a nested child node in the custom element. If there is a child node, the custom element is the corresponding parent node, and the content of the child node is rendered at the corresponding position of the page content of the parent node according to the attributes of the child node.

[0047] From the above description, we can see that for nested custom elements, rendering the child node content at the corresponding position of the parent node according to its attributes is more in line with the needs of page design and more rigorous.

[0048] Furthermore, after the processor executes step S3 of the computer program, the following steps are further included:

[0049] S4. Obtain an operation request from the user, and according to the selected content in the operation request, call a first rendering component corresponding to the selected content to process the operation request, where the operation request includes an operation that does not change the JSON Schema and an operation that changes the JSON Schema.

[0050] From the above description, it can be seen that the processing of user requests is based on the selected content in the user request, and the corresponding rendering component responsible for rendering the content is selected for processing. The conditions for selecting the component for processing are clear, which further improves maintainability.

[0051] Furthermore, in step S4, calling the first rendering component corresponding to the selected content to process the operation request is specifically as follows:

[0052] Calling a first rendering component corresponding to the selected content;

[0053] Determine whether the operation request is an operation that does not change the JSON Schema. If so, the first rendering component performs corresponding processing according to the operation request.

[0054] Otherwise, the first rendering component converts the operation request into one or more atomic operations corresponding to the JSON Schema, modifies the JSON Schema according to the atomic operations, generates a new JSON Schema, obtains all custom elements and text nodes according to the new JSON Schema, and executes steps S2 and S3 to refresh and re-render the page.

[0055] From the above description, it can be seen that when a user changes the JSON Schema, the operation needs to be converted into an atomic operation for processing, and then the page is refreshed and re-rendered, so that the user's modification can get real-time feedback, improving the user experience.

[0056] Please refer to Figure 1, Embodiment 1 of the present invention is:

[0057] A method for displaying and refreshing rich text. The preset JSON Schema is as follows:

[0058]

[0059]

[0060] S1. Obtain all custom elements and text nodes according to the pre-defined data storage format JSON Schema;

[0061] S2. If it is a custom element, then according to the element type and custom attributes of the custom element, a rendering component corresponding to the element type in the rich text editor is called, and the corresponding rendering component renders and generates page content corresponding to the custom attributes;

[0062] The custom elements can be nested with each other, but the text nodes cannot be nested;

[0063] The step S2 further comprises:

[0064] The corresponding rendering component determines whether there is a nested child node in the custom element. If there is a child node, the custom element is the corresponding parent node, and the content of the child node is rendered at the corresponding position of the page content of the parent node according to the attribute of the child node;

[0065] S3. If it is a text node, a text rendering component renders the text content of the text node according to the custom attributes of the text node to generate text content.

[0066] In this embodiment, as shown in the above code, the first custom element type is list, and two child nodes of type list-item are nested. Therefore, the corresponding List and ListItem components defined in the rich text editor are called for rendering. The List component renders the content rendered by ListItem at the corresponding position of the list. The second custom element type is image, and similarly, the Image component is called for rendering.

[0067] S4. Obtaining an operation request from the user, and calling a first rendering component corresponding to the selected content according to the selected content in the operation request to process the operation request, wherein the operation request includes an operation that does not change the JSON Schema and an operation that changes the JSON Schema;

[0068] In step S4, calling the first rendering component corresponding to the selected content to process the operation request is specifically as follows:

[0069] Calling a first rendering component corresponding to the selected content;

[0070] Determine whether the operation request is an operation that does not change the JSON Schema. If so, the first rendering component performs corresponding processing according to the operation request.

[0071] Otherwise, the first rendering component converts the operation request into one or more atomic operations corresponding to the JSON Schema, modifies the JSON Schema according to the atomic operations, generates a new JSON Schema, obtains all custom elements and text nodes according to the new JSON Schema, and executes steps S2 and S3 to refresh and re-render the page.

[0072] In this embodiment, the operation that does not change the JSON Schema may be: when the user clicks on the image, the edge is highlighted, and the Image component renders the highlighted edge;

[0073] The operation of changing the JSON Schema may be: if the user needs to insert a new list-item after the last list-item in the list, the ListItem component is called to convert the user's operation request into a corresponding atomic operation Operation (Insert_Node), and according to the atomic operation, the JSON Schema is modified accordingly to generate a new JSON Schema, and the rich text editor will be refreshed and re-rendered.

[0074] Please refer to Figure 2 , Embodiment 2 of the present invention is:

[0075] A terminal 1 for rich text display and refresh includes a processor 2, a memory 3, and an executable computer program stored in the memory 3 and run on the processor 2. When the processor 2 executes the executable computer program, a method for rich text display and refresh in Example 1 is implemented.

[0076] In summary, the present invention provides a method and terminal for rich text display and refresh. Based on the background and idea of ​​front-end componentization, the data storage format JSON Schema is customized in advance, with high freedom, which improves the scalability of the data format. According to the type of page element, the corresponding component is selected for rendering, which improves the maintainability of the code. The custom elements can be nested with each other, which further improves the freedom and scalability. According to the content clicked by the user, the rendering component of the content is selected for processing. The conditions for selecting the component for processing are clear, which further improves the maintainability. When the JSON Schema changes, the page content is automatically refreshed and re-rendered, which improves the user experience.

[0077] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A method for displaying and refreshing rich text, characterized in that: include: S1. Obtain all custom elements and text nodes according to the pre-defined data storage format JSON Schema; S2. If it is a custom element, then according to the element type and custom attributes of the custom element, a rendering component corresponding to the element type in the rich text editor is called, and the corresponding rendering component renders and generates page content corresponding to the custom attributes; S3. If it is a text node, the text rendering component renders the text content of the text node according to the custom attributes of the text node to generate text content; S4. Obtaining an operation request from the user, and calling a first rendering component corresponding to the selected content according to the selected content in the operation request to process the operation request, wherein the operation request includes an operation that does not change the JSON Schema and an operation that changes the JSON Schema; In step S4, calling the first rendering component corresponding to the selected content to process the operation request is specifically as follows: Calling a first rendering component corresponding to the selected content; Determine whether the operation request is an operation that does not change the JSON Schema. If so, the first rendering component performs corresponding processing according to the operation request. Otherwise, the first rendering component converts the operation request into one or more atomic operations corresponding to the JSON Schema, modifies the JSON Schema according to the atomic operations, generates a new JSON Schema, obtains all custom elements and text nodes according to the new JSON Schema, and executes steps S2 and S3 to refresh and re-render the page.

2. A method for displaying and refreshing rich text according to claim 1, characterized in that: The custom elements can be nested with each other, but the text nodes cannot be nested.

3. A method for displaying and refreshing rich text according to claim 2, characterized in that: The step S2 further comprises: The corresponding rendering component determines whether there is a nested child node in the custom element. If there is a child node, the custom element is the corresponding parent node, and the content of the child node is rendered at the corresponding position of the page content of the parent node according to the attributes of the child node.

4. A terminal for rich text display and refresh, comprising a processor, a memory, and an executable computer program stored in the memory and running on the processor, characterized in that: When the processor executes the executable computer program, the following steps are implemented: S1. Obtain all custom elements and text nodes according to the pre-defined data storage format JSON Schema; S2. If it is a custom element, then according to the element type and custom attributes of the custom element, a rendering component corresponding to the element type in the rich text editor is called, and the corresponding rendering component renders and generates page content corresponding to the custom attributes; S3. If it is a text node, the text rendering component renders the text content of the text node according to the custom attributes of the text node to generate text content; S4. Obtaining an operation request from the user, and calling a first rendering component corresponding to the selected content according to the selected content in the operation request to process the operation request, wherein the operation request includes an operation that does not change the JSON Schema and an operation that changes the JSON Schema; In step S4, calling the first rendering component corresponding to the selected content to process the operation request is specifically as follows: Calling a first rendering component corresponding to the selected content; Determine whether the operation request is an operation that does not change the JSON Schema. If so, the first rendering component performs corresponding processing according to the operation request. Otherwise, the first rendering component converts the operation request into one or more atomic operations corresponding to the JSON Schema, modifies the JSON Schema according to the atomic operations, generates a new JSON Schema, obtains all custom elements and text nodes according to the new JSON Schema, and executes steps S2 and S3 to refresh and re-render the page.

5. A rich text display and refresh terminal according to claim 4, characterized in that: The custom elements can be nested with each other, but the text nodes cannot be nested.

6. A rich text display and refresh terminal according to claim 5, characterized in that: The step S2 further comprises: The corresponding rendering component determines whether there is a nested child node in the custom element. If there is a child node, the custom element is the corresponding parent node, and the content of the child node is rendered at the corresponding position of the page content of the parent node according to the attributes of the child node.