Method and device for realizing rich text effect, electronic equipment and medium

By generating a mapping table between Hypertext Markup Language tags and content styles, and using custom strategies to restore and render rich text elements, the problem of inconsistent display of rich text editors on different platforms is solved, and customized rich text effects with compatibility and scalability are achieved.

CN120633596APending Publication Date: 2025-09-12BEIJING FANGDUODUO INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510703398.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-28
Publication Date
2025-09-12

AI Technical Summary

Technical Problem

Existing rich text editors lack the ability to parse Hypertext Markup Language tags and are unable to parse custom tags, resulting in inconsistent text display.

Method used

By generating a mapping table between Hypertext Markup Language tags and content styles, using a custom style restoration strategy to restore tags to displayable rich text elements, and establishing mapping relationships for rendering and assembly, it supports rich text effects for common and custom tags.

Benefits of technology

It achieves good compatibility and scalability on different platforms and devices, and supports customized rich text effects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120633596A_ABST
    Figure CN120633596A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a method and device for achieving a rich text effect, electronic equipment and a medium, and relates to the technical field of computers. The method comprises the following steps: analyzing a text carrying hypertext markup language tags, and generating a mapping table between the hypertext markup language tags and content styles; restoring the hypertext markup language tags in the mapping table between the hypertext markup language tags and the content styles according to a self-defined style restoring strategy to obtain rich text elements which can be displayed on a specified system; the self-defined style restoration strategy is used for indicating style requirements of the hypertext markup language tag; and establishing a mapping relationship between the displayable rich text elements and the mapping table between the hypertext markup language tags and the content styles, and rendering and assembling the displayable rich text elements according to the mapping relationship to realize a rich text effect. The method can support rich text effects of various hypertext markup language tags, and is high in compatibility and expandability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method, device, electronic device and medium for achieving rich text effects. Background Art

[0002] Rich text is a text format that supports diverse formats (such as fonts, colors, images, hyperlinks, etc.), allowing rich styles and multimedia elements to be embedded in the text, so as to better present the structure and hierarchy of the text and enhance the effect of information transmission. Rich text is widely used in various design and content creation scenarios, such as online document editing, web design, etc. One of the core elements of rich text is implemented through Hypertext Markup Language (HTML) tags. However, the current common rich text editors lack the ability to parse tags carrying Hypertext Markup Language, and cannot implement the parsing of custom tags. And because rich text contains rich formats and elements, there may be compatibility issues on different platforms and devices, which may cause inconsistent text display. Summary of the Invention

[0003] To solve the above technical problems or at least partially solve the above technical problems, embodiments of the present invention provide a method, device, electronic device, and medium for achieving rich text effects.

[0004] In a first aspect, an embodiment of the present invention provides a method for achieving a rich text effect, comprising:

[0005] Parsing text with HTML tags to generate a mapping table between HTML tags and content styles;

[0006] According to a custom style restoration strategy, the hypertext markup language tags in the mapping table between hypertext markup language tags and content styles are restored to obtain rich text elements that can be displayed on a specified system; the custom style restoration strategy is used to indicate style requirements of the hypertext markup language tags;

[0007] A mapping relationship is established between displayable rich text elements and a mapping table between hypertext markup language tags and content styles, and the displayable rich text elements are rendered and assembled according to the mapping relationship to achieve a rich text effect.

[0008] Optionally, the text containing HTML tags is parsed to generate a mapping table between HTML tags and content styles, including:

[0009] Parse the text containing hypertext markup language tags to obtain the event stream corresponding to the text;

[0010] Parse the event stream using regular expressions to obtain the Hypertext Markup Language tags, content text, and style format text carried by the text;

[0011] A mapping table between the hypertext markup language tags and the content styles is generated according to the hypertext markup language tags, the content text and the style format text.

[0012] Optionally, the method further includes: defining a tag parsing strategy, the tag parsing strategy being used to parse hypertext markup language tags;

[0013] Parsing the text carrying the hypertext markup language tag includes: parsing the text carrying the hypertext markup language tag according to the tag parsing strategy.

[0014] Optionally, the method further includes: building a rich text rendering controller;

[0015] Rendering and assembling displayable rich text elements according to the mapping relationship to achieve a rich text effect, including: using the rich text rendering controller to render and assemble displayable rich text elements according to the mapping relationship to achieve a rich text effect.

[0016] In a second aspect, an embodiment of the present invention provides a device for achieving a rich text effect, including:

[0017] A parsing module, used to parse text carrying hypertext markup language tags and generate a mapping table between hypertext markup language tags and content styles;

[0018] A restoration module is used to restore the hypertext markup language tags in the mapping table between hypertext markup language tags and content styles according to a custom style restoration strategy to obtain rich text elements that can be displayed on a specified system; the custom style restoration strategy is used to indicate style requirements for hypertext markup language tags;

[0019] The rendering module is used to establish a mapping relationship between displayable rich text elements and a mapping table between hypertext markup language tags and content styles, and render and assemble the displayable rich text elements according to the mapping relationship to achieve a rich text effect.

[0020] Optionally, the parsing module is also used to: parse text carrying hypertext markup language tags to obtain the event stream corresponding to the text; parse the event stream through regular expressions to obtain the hypertext markup language tags, content text and style format text carried by the text; and generate a mapping table between hypertext markup language tags and content styles based on the hypertext markup language tags, content text and style format text.

[0021] Optionally, the device further includes a custom module for: defining a tag parsing strategy, the tag parsing strategy being used to parse hypertext markup language tags;

[0022] The parsing module is further used to parse texts carrying hypertext markup language tags according to a tag parsing strategy.

[0023] Optionally, the device further includes a construction module for constructing a rich text rendering controller;

[0024] The rendering module is further configured to utilize the rich text rendering controller to render and assemble displayable rich text elements according to the mapping relationship to achieve a rich text effect.

[0025] In a third aspect, an embodiment of the present invention provides an electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; the memory is used to store computer programs; and the processor is used to implement the method for achieving rich text effects provided by any embodiment of the present invention when executing the program stored in the memory.

[0026] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method for achieving a rich text effect provided by any embodiment of the present invention.

[0027] The technical solutions provided by the embodiments of the present disclosure bring at least the following beneficial effects:

[0028] The method for achieving rich text effects provided by an embodiment of the present invention parses text carrying hypertext markup language tags to generate a mapping table between hypertext markup language tags and content styles; according to a customized style restoration strategy, the hypertext markup language tags in the mapping table between hypertext markup language tags and content styles are restored to obtain rich text elements that can be displayed on a specified system; the customized style restoration strategy is used to indicate the style requirements of the hypertext markup language tags; a mapping relationship is established between the displayable rich text elements and the mapping table between hypertext markup language tags and content styles, and the displayable rich text elements are rendered and assembled according to the mapping relationship to achieve a rich text effect. The method restores the hypertext markup language tags to rich text elements that can be displayed on a specified system through a customized style restoration strategy, can support the rich text effects of common and commonly used hypertext markup language tags, and can also support the rich text effects of customized hypertext markup language tags, has good compatibility and scalability, and can achieve customized rich text effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for describing the embodiments or the prior art.

[0030] Figure 1 A schematic diagram of a process for achieving a rich text effect according to an embodiment of the present invention is shown;

[0031] Figure 2 A schematic diagram of a process for achieving a rich text effect according to another embodiment of the present invention is shown;

[0032] Figure 3 A schematic structural diagram of a device for achieving a rich text effect according to an embodiment of the present invention is shown;

[0033] Figure 4 A schematic structural diagram of an electronic device according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0034] The following description of exemplary embodiments of the present invention is made in conjunction with the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding. These details should be considered as merely exemplary. Therefore, it should be appreciated by those skilled in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0035] The terms "first," "second," and the like in the specification and claims of this application are used to distinguish similar objects, and are not used to describe a specific order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate, so that the embodiments of this application can be implemented in an order other than that illustrated or described herein, and that the objects distinguished by "first," "second," and the like are generally of the same type, and do not limit the number of objects; for example, the first object can be one or more. In addition, the term "and / or" in the specification and claims refers to at least one of the connected objects, and the character " / " generally indicates that the objects connected are in an "or" relationship.

[0036] Figure 1 The flowchart of the method for achieving rich text effect according to one embodiment of the present invention is shown schematically. Figure 1 As shown, the method includes:

[0037] Step S101: parsing text with HTML tags to generate a mapping table between HTML tags and content styles.

[0038] Hypertext Markup Language (HTML) is a standard markup language used to create web pages. It includes a series of tags that can be used to unify the format of documents on the Internet. For example, common Hypertext Markup Language tags (hereinafter referred to as HTML tags) include 、 <h1> arrive< / h1> <h6>、 、 、 、 、 、 and 。 Used to define a paragraph. <h1> arrive< / h1> <h6>Used to define the title. Used to define a hyperlink. Used to bold text. Used for italic text. Used to underline text. Used to insert pictures. and For layout and style control.

[0039] The purpose of parsing the text containing HTML tags in this step is to separate the text content and style format so as to achieve rich text effects later.

[0040] In an optional embodiment, step S101 includes:

[0041] Parse the text containing hypertext markup language tags to obtain the event stream corresponding to the text;

[0042] Parse the event stream using regular expressions to obtain the Hypertext Markup Language tags, content text, and style format text carried by the text;

[0043] A mapping table between the hypertext markup language tags and the content styles is generated according to the hypertext markup language tags, the content text and the style format text.

[0044] For example, the htmlparser2 library can be used to parse text containing HTML tags to obtain the event stream corresponding to the text. Regular expressions are then used to parse the event stream to determine the HTML tags, content text, and style format text (for example, when parsing the header tag, the header tag is pushed into a stack structure, and when parsing the tail tag, the stack is popped to obtain the HTML tags and their corresponding content text and style format text). The htmlparser2 library is an efficient and lightweight Node.js library for streaming parsing of Hypertext Markup Language in an event-driven manner, supporting block-by-block processing and extraction of document content.

[0045] In an optional embodiment, the hypertext markup language tags carried by the above text include not only common and commonly used HTML tags, but also custom tags that comply with the hypertext markup language specification.

[0046] The method for achieving rich text effects also includes: defining a tag parsing strategy, and parsing text carrying Hypertext Markup Language tags according to the tag parsing strategy. The tag parsing strategy is used to parse Hypertext Markup Language tags, which can not only parse common and commonly used HTML tags, but also parse custom HTML tags.

[0047] As an optional example, parse the text containing Hypertext Markup Language according to the tag parsing strategy shown in the following code:

[0048] export function parseHtmL(htmLStr: string) {1 / / Create a mapping table to store tag content

[0049] const tagContentMap = {}; / / Create an empty object tagContentMap to store the parsed tag content

[0050] const keyStack = new Stack <string>() / / Create an empty stack keyStack to record the hierarchical relationship of the current tag

[0051] Let counter = θ; / / Initialize a counter to 0 to record the order of text content

[0052] const parser = new htmlparser2.Parser({ / / Use the htmlparser2 library to create a new Parser instance to parse the incoming HTML string

[0053] on open tag(name,attributes){

[0054] / / script tag should be skipped

[0055] if(name===="script"&&attributes.type===="text / javascript")

[0056] {return}

[0057] keyStack.push(name)

[0058] tagContentMap[name]=tagContentMap[name]Il[];

[0059] tagContentMap[name].push(fname,attributes,children:[]});}

[0060] ontext(text){

[0061] / / Add the text content to the child node of the current tag

[0062] if(Object.keys(keyStack).Length>θ){

[0063] const currentTag=keyStack.peek();

[0064] if(currentTag){

[0065] const textLength=tagNeedBreakLine(currentTag)? text.Length+2:text.Length

[0066] tagContentMap[currentTag][tagContentHap[currentTag].Length-1].children.push({counter,text,textLength});}

[0067] else{

[0068] const name = 'no_tag'

[0069] / / No tag content

[0070] tagContentMap[name]=tagContentMap[name][];

[0071] tagContentMap[name].push({name,children:[]});

[0072] const textLength=text.Length

[0073] tagContentMap[name][tagContentMap[name].Length1].children.push({counter,text,textLength});

[0074] }}

[0075] onclosetag(tagname) / / Define a function called onclosetag, which receives a parameter tagname and is used to handle the closing event of the HTML tag

[0076] {

[0077] if(tagname==="script"){

[0078] return}

[0079] keyStack.pop()

[0080] if(tagNeedPlaceholder(tagname)){ / / br tag has no content, needs to be filled with placeholder content

[0081] tagContentMap[tagname][tagContentap[tagname].Length-1].children.push({counter,text:});

[0082] counter++

[0083] } else if (tagNeedBreakLine(tagname)) / / p tag needs to add line breaks

[0084] {

[0085] const pList = tagContentMap[tagname][tagContentMap[tagname].Length - 1].children

[0086] pList[pList.Length - 1].text = '\n' + pList[pList.Length - 1].text + '\n'}}

[0087] onend() {

[0088] Object.keys(tagContentMap).forEach(key => {

[0089] tagContentMap[key].forEach(item => {

[0090] item.children.forEach(child => {

[0091] fLatmapList.push({

[0092] position: child.counter,

[0093] content: child.text,

[0094] tag: item.name,

[0095] attributes: item.attributes,

[0096] textLength: child.textLength

[0097] );});});});

[0098] fLatmapList.sort((a, b) => {

[0099] const positionA = a.position || 0;

[0100] const positionB=b.position||θ;

[0101] returnpositionA-positionB;

[0102] })}});

[0103] parser.write(htmLStr);

[0104] parser.end();

[0105] return JSON.stringify(flatmapList);

[0106] The tag parsing strategy shown in the code above first defines a function named parseHtml that accepts an HTML string as a parameter. It then creates an empty tagContentMap object to store the parsed tag content. It also creates an empty stack, keyStack, to record the current tag hierarchy. It initializes a counter to 0 to record the order of the text content. It then uses the htmlparser2 library to create a new Parser instance to parse the incoming text containing HTML tags. When encountering an open tag (the on open tag event), it checks whether the tag name is script and its type attribute is text / javascript. If so, it skips parsing the tag. For other tags, it adds their names to the keyStack and creates an entry for them in the tagContentMap, recording the tag name, attributes, and an empty array for storing child tag information. When encountering text content (the ontext event), it first checks whether there is an active tag hierarchy (that is, keyStack is not empty). If there is an active tag hierarchy, it retrieves the name of the tag at the top of the stack as the current tag, currentTag. Add the text content to the subtag information of currentTag, and record the order of the text content (counter), the text itself, and the length of the text (after special processing, such as whether line breaks are required). If there is no active tag level, classify the text content as no_tag and record the relevant information as well. When a closed tag is encountered, the tag name should be popped from the keyStack to indicate the end of the current level. The tag and its subtag information are finalized and stored in tagContentMap.

[0107] Step S102: according to a customized style restoration strategy, restore the HTML tags in the mapping table between HTML tags and content styles to obtain rich text elements displayable on a specified system; the customized style restoration strategy is used to indicate the style requirements of the HTML tags.

[0108] Among them, the customized style restoration strategy is used to instruct the HTML tag to be restored to a displayable rich text element of a customized style for display on a specified system (such as the operating system Harmony OS, Android system, etc.). In an optional embodiment, taking the operating system Harmony OS as an example, the HTML tag is restored according to the customized style restoration strategy to generate a StyledString component that can be displayed on the Harmony OS. StyledString (attributed string) is a markup object used to set text styles at the character or paragraph level. Text can be changed in a variety of ways, including changing the font size, adding font color, making text clickable, and drawing text in a customized way. With HTML tags Take this as an example to illustrate the specific implementation as follows:

[0109] export const pTagStyLestring=(content:string,Length:number)=>newstyLedstring(content,[{

[0110] start:0,

[0111] Length:Length,

[0112] styLedKey:StyLedStringKey.FONT,

[0113] styLedValue:newTextStyle({fontCoLor:'#333333',fontSize:LengthMetrics.vp(14)})}]).

[0114] Step S103: establishing a mapping relationship between the displayable rich text elements and a mapping table between hypertext markup language tags and content styles, and rendering and assembling the displayable rich text elements according to the mapping relationship to achieve a rich text effect.

[0115] A mapping relationship is established between the displayable rich text elements and the mapping table between the hypertext markup language tags and content styles, the corresponding content and style of each displayable rich text element are determined, and the displayable rich text elements are rendered and assembled to achieve a rich text effect.

[0116] The method for achieving rich text effects provided by an embodiment of the present invention parses text carrying hypertext markup language tags to generate a mapping table between hypertext markup language tags and content styles; according to a customized style restoration strategy, the hypertext markup language tags in the mapping table between hypertext markup language tags and content styles are restored to obtain rich text elements that can be displayed on a specified system; the customized style restoration strategy is used to indicate the style requirements of the hypertext markup language tags; a mapping relationship is established between the displayable rich text elements and the mapping table between hypertext markup language tags and content styles, and the displayable rich text elements are rendered and assembled according to the mapping relationship to achieve a rich text effect. The method restores the hypertext markup language tags to rich text elements that can be displayed on a specified system through a customized style restoration strategy, can support the rich text effects of common and commonly used hypertext markup language tags, and can also support the rich text effects of customized hypertext markup language tags, has good compatibility and scalability, and can achieve customized rich text effects.

[0117] Figure 2 A schematic flow chart of a method for achieving rich text effects according to another embodiment of the present invention is shown.

[0118] like Figure 2 As shown, the method includes:

[0119] Step S201: Parse the text containing the Hypertext Markup Language tags to obtain the event stream corresponding to the text.

[0120] Step S202: Parse the event stream using regular expressions to obtain hypertext markup language tags, content text, and style format text carried by the text.

[0121] Step S203: Generate a mapping table between the hypertext markup language tags and the content style according to the hypertext markup language tags, the content text and the style format text.

[0122] Step S204: according to the customized style restoration strategy, restore the HTML tags in the mapping table between HTML tags and content styles to obtain rich text elements displayable on the specified system; the customized style restoration strategy is used to indicate the style requirements of the HTML tags.

[0123] Step S205: Construct a rich text rendering controller.

[0124] Step S206: Utilize the rich text rendering controller to render and assemble the displayable rich text elements according to the mapping relationship to achieve a rich text effect.

[0125] Among them, steps S201 to S204 can refer to Figure 1 To avoid repetition, the illustrated embodiments will not be described again here.

[0126] For steps S205-S206, the constructed controller is used to control the rendering and loading of each displayable rich text element to achieve the desired effect. For example, when the controller determines that the displayable rich text element is an image, it asynchronously loads and renders the image.

[0127] As an optional example, continuing with the above code, the controller renders and assembles the displayable rich text elements to achieve the specific implementation of the rich text effect, including:

[0128] this.richTexts.forEach(async(wrapper:RichTextWrapper,index:number)=>

[0129] if(wrapper.tag === 'p'){

[0130] this.styLe.appendstyLedstring(pTagstyLeString(wrapper.content,wrapper.content.Length))

[0131] }else if(wrapper.tag==='u'){

[0132] this.style.appendstyLedString(uTagStyLeString(wrapper.content,wrapper.content.Length))

[0133] }else if(wrapper.tag==='br'){

[0134] this.styLe.appendstyLedstring(brTagStyLeString())

[0135] }else if(wrapper.tag==='em'){

[0136] this.style.appendstyledstring(emTagStyleString(wrapper.content,wrapper.content.Length))

[0137] }else if(wrapper.tag==='b'){

[0138] this.styLe.appendstyLedstring(bTagstyLeString(wrapper.content,wrapper.content.Length))

[0139] }else if(wrapper.tag==='div'){

[0140] this.style.appendstyLedstring(divTagstyLestring(wrapper.content,wrapper.content.Length,wrapper.attributes))

[0141] }else if(wrapper.tag==='i'){

[0142] this.styLe.appendstylLedstring(iTagstyLeString(wrapper.content,wrapper.content.Length))

[0143] } else if (wrapper.tag === 'a') { this.style.appendstyLedstring(aTagStyLeString(wrapper.content,wrapper.content.Length,wrapper.attributes,this.onHyperLinkClickListener))

[0144] } else if (wrapper.tag === 'img') / / Asynchronous loading and rendering

[0145] {

[0146] const styLedstring = imgTagstylestring(wrapper.content,wrapper.attributes,

[0147] (image:ImageAttachment) => {...})

[0148] this.style.appendStyLedString(styLedstring)

[0149] } else if (wrapper.tag === 'h1') {

[0150] this.style.appendstyLedString(h1TagStyledstring(wrapper.content,wrapper.attributes))

[0151] } else if (wrapper.tag === 'h2') {

[0152] this.styLe.appendstyLedstring(h2TagstyLedString(wrapper.content,wrapper.attributes))

[0153] } else if (wrapper.tag === 'h3') {

[0154] It should be noted that there seem to be some misspellings in the original code (e.g., "styLe", "appendstylLedstring", etc.), which may affect the correct understanding and operation of the code.this.style.appendstyLedstring(h3TagStyLedString(wrapper.content,wrapper.attributes))

[0155] }else if(wrapper.tag==='h4'){

[0156] this.styLe.appendstyLedstring(h4TagstyLedString(wrapper.content,wrapper.attributes))

[0157] }else if(wrapper.tag==='h5'){

[0158] this.style.appendStyLedString(h5TagStyLedstring(wrapper.content,wrapper.attributes))

[0159] }else if(wrapper.tag==='h6'){

[0160] this.styLe.appendstyledstring(h6TagStyledstring(wrapper.content,wrapper.attributes))

[0161] }else{

[0162] this.style.appendstyLedString(new StyLedString(wrapper.content))

[0163] }

[0164] })

[0165] this.textController.setStyLedString(this.styLe)

[0166] build(){

[0167] Column(){

[0168] NodeContainer(this.richTextNodeController)

[0169] .onAppear(()=>{

[0170] this.refreshRichText()

[0171] })

[0172] @Builder

[0173] function richTextBuilder(textController:TextController){

[0174] Text(undefined,{controller:textController})

[0175] class HsRichTextNodeController extends NodeController

[0176] private textController:TextController

[0177] constructor(textController:TextController){

[0178] super();

[0179] this.textController=textController

[0180] private richTextMode:BuilderNode<[TextController]>|null=null

[0181] private wrapBuilder:

[0182] WrappedBuilder<[TextController]>=wrapBuilder(richTextBuilder);

[0183] makeNode(uiContext:UIContext):FrameNode|null{

[0184] if(this.richTextMode==null){

[0185] this.richTextMode=new BuilderNode(uiContext)

[0186] this.richTextMode.build(this.wrapBuilder,this.textController)

[0187] return this.richTextMode! .getFrameNode()

[0188] The rich text rendering controller implemented in the above code applies styles and renders content based on different HTML tag types. This rich text rendering controller uses a forEach loop to iterate through each RichTextWrapper object in the richTexts array, distinguishing different HTML tag types by judging the value of the wrapper.tag property. For each tag type, the corresponding style generation function (such as pTagStyleString, uTagStyleString, etc.) is called. The main tag processing logic includes: Normal paragraph (p tag): Adds paragraph styles. Underline (u tag): Adds underline styles. Line break (br tag): Adds line break styles. Emphasis (em tag): Adds italic emphasis styles. Bold (b tag): Adds bold styles. Images (img tag): Asynchronously loads and renders images. Titles (h1-h6): Adds title styles for different levels. Images (img) are loaded asynchronously, including callback functions for handling hyperlinks (a tags) and click event listeners. The div tag supports additional attribute processing. This rich text rendering controller uses NodeController and BuilderNode to build custom nodes, sets the final styled text content through TextController, and wraps the rich text node with NodeContainer in the build method. When rendering rich text elements, this rich text rendering controller uses the @Builder decorator to define the richTextBuilder construction function and triggers refreshRichText in the onAppear lifecycle to refresh the content.

[0189] Figure 3 A schematic structural diagram of an apparatus for achieving rich text effects provided by an embodiment of the present invention is shown.

[0190] like Figure 3 As shown, the apparatus 300 for achieving rich text effect includes:

[0191] The parsing module 301 is used to parse text containing HTML tags and generate a mapping table between HTML tags and content styles.

[0192] Restoration module 302 is used to restore the HTML tags in the mapping table between HTML tags and content styles according to a custom style restoration strategy to obtain rich text elements that can be displayed on a specified system; the custom style restoration strategy is used to indicate style requirements for HTML tags;

[0193] The rendering module 303 is used to establish a mapping relationship between the displayable rich text elements and the mapping table between the hypertext markup language tags and content styles, and render and assemble the displayable rich text elements according to the mapping relationship to achieve a rich text effect.

[0194] In an optional embodiment, the parsing module is also used to: parse text carrying hypertext markup language tags to obtain an event stream corresponding to the text; parse the event stream through regular expressions to obtain the hypertext markup language tags, content text and style format text carried by the text; and generate a mapping table between hypertext markup language tags and content styles based on the hypertext markup language tags, content text and style format text.

[0195] In an optional embodiment, the apparatus for achieving a rich text effect further includes a custom module for: defining a tag parsing strategy, the tag parsing strategy being used to parse hypertext markup language tags;

[0196] The parsing module is further configured to parse text carrying hypertext markup language tags according to a tag parsing strategy.

[0197] In an optional embodiment, the apparatus for achieving a rich text effect further includes a construction module for constructing a rich text rendering controller;

[0198] The rendering module is further configured to utilize the rich text rendering controller to render and assemble displayable rich text elements according to the mapping relationship to achieve a rich text effect.

[0199] The above device can execute the method provided by the embodiment of the present invention, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not fully described in this embodiment, please refer to the method for achieving rich text effects provided by the embodiment of the present invention.

[0200] Figure 4 FIG. 1 shows a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Figure 4 As shown, the electronic device includes:

[0201] Processor 401, communication interface 402, memory 403 and communication bus 404, wherein the processor 401, communication interface 402, memory 403 communicate with each other via the communication bus 404.

[0202] Memory 403, used for storing computer programs;

[0203] The processor 401 is configured to execute the program stored in the memory 403 by performing the following steps:

[0204] Parsing text with HTML tags to generate a mapping table between HTML tags and content styles;

[0205] According to a custom style restoration strategy, the hypertext markup language tags in the mapping table between hypertext markup language tags and content styles are restored to obtain rich text elements that can be displayed on a specified system; the custom style restoration strategy is used to indicate style requirements of the hypertext markup language tags;

[0206] A mapping relationship is established between displayable rich text elements and a mapping table between hypertext markup language tags and content styles, and the displayable rich text elements are rendered and assembled according to the mapping relationship to achieve a rich text effect.

[0207] The communication bus mentioned in the terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is used in the figure, but this does not mean that there is only one bus or only one type of bus.

[0208] The communication interface is used for communication between the above terminal and other devices.

[0209] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage. Alternatively, the memory may be at least one storage device located away from the processor.

[0210] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.

[0211] In another embodiment provided by the present invention, a computer-readable storage medium is also provided, in which instructions are stored. When the computer-readable storage medium is run on a computer, the computer executes any one of the methods for achieving rich text effects in the above embodiments.

[0212] In another embodiment provided by the present invention, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any of the methods for achieving rich text effects described in the above embodiments.

[0213] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).

[0214] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprise," "include," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or device comprising the element.

[0215] Each embodiment in this specification is described in a related manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiment is generally similar to the method embodiment, so the description is relatively simple. For related parts, refer to the description of the method embodiment.

[0216] The above description is only a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention are included in the scope of protection of the present invention. < / string> < / h6> < / h6>

Claims

1. A method for achieving rich text effect, characterized in that: include: Parsing text with HTML tags to generate a mapping table between HTML tags and content styles; According to a custom style restoration strategy, the hypertext markup language tags in the mapping table between hypertext markup language tags and content styles are restored to obtain rich text elements that can be displayed on a specified system; the custom style restoration strategy is used to indicate style requirements of the hypertext markup language tags; A mapping relationship is established between displayable rich text elements and a mapping table between hypertext markup language tags and content styles, and the displayable rich text elements are rendered and assembled according to the mapping relationship to achieve a rich text effect.

2. The method according to claim 1, characterized in that Parse the text containing HTML tags and generate a mapping table between HTML tags and content styles, including: Parse the text containing hypertext markup language tags to obtain the event stream corresponding to the text; Parse the event stream using regular expressions to obtain the Hypertext Markup Language tags, content text, and style format text carried by the text; A mapping table between the hypertext markup language tags and the content styles is generated according to the hypertext markup language tags, the content text and the style format text.

3. The method according to claim 1 or 2, characterized in that The method also includes: Define tag parsing strategy, which is used to parse Hypertext Markup Language tags; Parsing the text carrying the hypertext markup language tag includes: parsing the text carrying the hypertext markup language tag according to the tag parsing strategy.

4. The method according to claim 1, characterized in that The method also includes: constructing a rich text rendering controller; Rendering and assembling displayable rich text elements according to the mapping relationship to achieve a rich text effect, including: using the rich text rendering controller to render and assemble displayable rich text elements according to the mapping relationship to achieve a rich text effect.

5. A device for achieving rich text effect, characterized in that: include: A parsing module, used to parse text carrying hypertext markup language tags and generate a mapping table between hypertext markup language tags and content styles; A restoration module is used to restore the hypertext markup language tags in the mapping table between hypertext markup language tags and content styles according to a custom style restoration strategy to obtain rich text elements that can be displayed on a specified system; the custom style restoration strategy is used to indicate style requirements for hypertext markup language tags; The rendering module is used to establish a mapping relationship between displayable rich text elements and a mapping table between hypertext markup language tags and content styles, and render and assemble the displayable rich text elements according to the mapping relationship to achieve a rich text effect.

6. The device according to claim 5, characterized in that The parsing module is also used to: Parse the text containing hypertext markup language tags to obtain the event stream corresponding to the text; Parse the event stream using regular expressions to obtain the Hypertext Markup Language tags, content text, and style format text carried by the text; A mapping table between the hypertext markup language tags and the content styles is generated according to the hypertext markup language tags, the content text and the style format text.

7. The device according to claim 5 or 6, characterized in that The device also includes a custom module for: defining a tag parsing strategy, the tag parsing strategy being used to parse hypertext markup language tags; The parsing module is further used to parse texts carrying hypertext markup language tags according to a tag parsing strategy.

8. The device according to claim 5, characterized in that The device also includes a building module for building a rich text rendering controller; The rendering module is further configured to utilize the rich text rendering controller to render and assemble displayable rich text elements according to the mapping relationship to achieve a rich text effect.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory for storing computer programs; A processor, configured to implement the method according to any one of claims 1 to 4 when executing a program stored in a memory.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.