Special character display method and device, equipment and medium
By identifying and processing special character tags, creating a target element container and replacing the original element container, the problem of special character display when copying web page content is solved, and the effect of data consistency and format maintenance is achieved.
Patent Information
- Application Number
- CN202410817987.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-24
- Publication Date
- 2024-09-10
AI Technical Summary
When copying web page content to a rich text editor, special characters may be ignored or mishandled, resulting in incorrect display and affecting data consistency.
By identifying and processing special character tags, creating a target element container, and replacing the original element container in the rich text editor, it ensures that the format and style of special characters are maintained during the copying process, and data consistency is displayed.
It effectively solves the problem of special characters being ignored or mishandled during the copy process, ensuring that the content of elements carrying special character tags is correctly displayed in the rich text editor, maintaining the format and style of the original content.
Smart Images

Figure CN118627475A
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and more specifically, to a method, device, equipment and medium for displaying special characters in the field of communication technology. Background Art
[0002] With the rapid development of digital information, the editing, processing and display of web page content have become important links in Internet applications. In the process of processing web page content, users can copy part of the content in the web page to a rich text editor for further editing and display.
[0003] Due to the complexity of web page content, it may contain various special characters. These special characters may cause display problems when they are directly copied into the rich text editor. Summary of the invention
[0004] The present application provides a method, apparatus, device and medium for displaying special characters, which can solve the display problem caused when special characters are directly copied to a rich text editor.
[0005] In a first aspect, a method for displaying special characters is provided, the method comprising:
[0006] In response to a copy operation on rich text content, a copy of the rich text content is displayed in a rich text editor, and special characters in the rich text content are not displayed in the copy; a target program structure of the copy content is obtained, and the target program structure includes multiple element containers representing the copy content; a first element container carrying a special character tag is determined from the multiple element containers, and the element content and content attribute tags in the first element container are obtained; a second element container is created based on the element content and the content attribute tags, and a special character tag is set for the second element container to obtain a target element container; the target element container is used to replace the first element container in the copy content, so as to display the element content carrying special characters corresponding to the special character tags in the rich text editor.
[0007] Through the above technical solution, when the rich text content of the browser is copied to the rich text editor, the format of the original rich text content, such as font, color, size, etc., can be maintained by maintaining multiple element containers. In the process of copying to the rich text editor, special characters may be ignored or processed incorrectly, resulting in failure to display in the rich text editor. By identifying and processing these special character tags, it can be ensured that they correctly display the special characters in the rich text content in the rich text editor. This solution can be used to display element content carrying special characters corresponding to special character tags in the rich text editor to achieve data consistency.
[0008] In conjunction with the first aspect, in some possible implementations, obtaining a target program structure of the copy content includes:
[0009] The internal interface of the rich text editor is used to obtain the web page content program of the rich text content from the web page program structure corresponding to the rich text content; and the web page content program is converted into the target program structure of the copy content.
[0010] Through the above technical solution, the purpose of modifying the copy content displayed in the rich text editor by subsequently modifying the target program structure can be achieved.
[0011] In combination with the first aspect and the foregoing implementation manner, in some possible implementation manners, determining a first element container carrying a special character tag from multiple element containers includes:
[0012] Traverse multiple element containers of the target program structure; if it is detected that multiple element containers carry special character tags, obtain the first element container carrying the special character tag.
[0013] In combination with the first aspect and the above implementations, in some possible implementations, obtaining the element content and the content attribute tag in the first element container includes:
[0014] The program content of the element content of the first element container is obtained from the web page program structure, and the style element tag of the first element container is obtained from the web page program structure.
[0015] In combination with the first aspect and the above implementations, in some possible implementations, creating a second element container based on element content and content attribute tags includes:
[0016] Create an initial element container; assign the program content and style element tag of the element content to the initial element container to obtain a second element container.
[0017] In combination with the first aspect and the above implementation manner, in some possible implementation manners, setting a special character tag for the second element container to obtain a target element container includes:
[0018] The tag of the element content of the second element container is set to a special character tag to obtain the target element container.
[0019] In combination with the first aspect and the above implementations, in some possible implementations, replacing the first element container with the target element container in the copy content includes:
[0020] The target element container is inserted into the target position of the copy content, and the first element container is deleted. The target position is the position after the position of the first element container in the copy content.
[0021] Through the above technical solution, it is possible to display element content carrying special characters in a rich text editor.
[0022] In a second aspect, a special character display device is provided, the device comprising:
[0023] A content display unit, configured to display a copy of the rich text content in the rich text editor in response to a copy operation on the rich text content, wherein the copy does not display special characters in the rich text content;
[0024] A structure acquisition unit, used to acquire a target program structure of the copy content, the target program structure including a plurality of element containers representing the copy content;
[0025] A container determination unit, used to determine a first element container carrying a special character tag from multiple element containers, and obtain element content and content attribute tags in the first element container;
[0026] A container creation unit, used to create a second element container based on the element content and the content attribute tag, and set a special character tag for the second element container to obtain a target element container;
[0027] The container replacement unit is used to replace the first element container with the target element container in the copy content, so as to display the element content carrying the special characters corresponding to the special character tag in the rich text editor.
[0028] According to a third aspect, an electronic device is provided, including:
[0029] A memory for storing executable program codes;
[0030] A processor is used to call and run executable program code from a memory, so that the electronic device executes the method in the above-mentioned first aspect or any possible implementation of the first aspect, or executes the method in the second aspect or any possible implementation of the second aspect.
[0031] In a fourth aspect, a computer program product is provided, comprising: a computer program code, which, when executed on a computer, enables the computer to execute the method in the first aspect or any possible implementation of the first aspect.
[0032] In a fifth aspect, a computer-readable storage medium is provided, which stores a computer program code. When the computer program code runs on a computer, the computer executes the method in the above-mentioned first aspect or any possible implementation manner of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1It is a scene schematic diagram of a method for displaying special characters provided in an embodiment of the present application;
[0034] Figure 2 It is a flowchart of a method for displaying special characters provided in an embodiment of the present application;
[0035] Figure 3 It is a flowchart of a method for displaying special characters provided in an embodiment of the present application;
[0036] Figure 4 It is a schematic diagram of a specific implementation process of a method for displaying special characters provided in an embodiment of the present application;
[0037] Figure 5 It is a structural schematic diagram of a display device for special characters provided in an embodiment of the present application;
[0038] Figure 6 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application;
[0039] Figure 7 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0040] The technical solution in the present application will be described clearly and in detail below in conjunction with the accompanying drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B: "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.
[0041] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.
[0042] Figure 1 It is a scene schematic diagram of a method for displaying special characters provided in an embodiment of the present application.
[0043] For example, due to the complexity of web page content, it may contain various special characters. These special characters may cause display problems when directly copied to a rich text editor. The element content carrying special characters corresponding to special character tags cannot be displayed in the rich text editor.
[0044] Based on the above situation, the embodiment of the present application proposes a method for displaying special characters. Figure 1 The electronic device in the browser 100 displays a copy 300 of the rich text content in the rich text editor 200 in response to a copy operation on the rich text content in the browser 100, and the special characters in the rich text content are not displayed in the copy; obtains a target program structure 400 of the copy content, and the target program structure 400 includes a plurality of element containers representing the copy content 300; determines a first element container carrying a special character tag from the plurality of element containers, and obtains the element content and content attribute tag in the first element container; creates a second element container based on the element content and the content attribute tag, and sets a special character tag for the second element container to obtain a target element container; replaces the first element container with the target element container in the copy content 300, so as to display the element content carrying the special characters corresponding to the special character tag in the rich text editor 200.
[0045] This method can maintain the format of the original rich text content, such as font, color, size, etc., by maintaining multiple element containers when copying the rich text content of the browser to the rich text editor. In the process of copying to the rich text editor, special characters may be ignored or processed incorrectly, resulting in failure to display in the rich text editor. By identifying and processing these special character tags, it can be ensured that they correctly display the special characters in the rich text content in the rich text editor. This solution can be used to display element content carrying special characters corresponding to special character tags in the rich text editor to achieve data consistency.
[0046] based on Figure 1 The scene shown is shown below. Figure 2-Figure 4 , a method for displaying special characters provided in an embodiment of the present application is introduced in detail.
[0047] See also Figure 2 , a flow chart of a method for displaying special characters is provided for an embodiment of the present application. Figure 2 As shown, the method of the embodiment of the present application may include the following steps S101-S105.
[0048] S101, in response to a copy operation on rich text content, displaying a copy of the rich text content in a rich text editor, wherein the copy does not display special characters in the rich text content;
[0049] Rich text content refers to web page content copied from a browser. Rich text content can contain text content in multiple formats and elements that can enhance the expressiveness and readability of the text. Compared with traditional plain text, rich text content can include the following features: font style, color, list, picture, link, table, embedded content, reference and comment, alignment and indentation, custom style, etc.
[0050] Among them, rich text editor refers to a tool that allows users to create and edit rich text content in a web page or application. Unlike traditional text editors (such as Notepad or plain text editors), rich text editors provide more formatting and element options, enabling users to create text content containing various formats (such as font styles, colors, pictures, links, etc.). For example, Editablejs is a rich text editor that can be embedded in a browser. It is a package of the NodePackage Manager (npm), and rich text content can be edited by installing this package. npm is the world's largest open source library ecosystem, containing a large number of libraries and tools that can help developers write scripting language (JavaScript) code more efficiently.
[0051] The copy content refers to the content without displaying the special characters in the rich text content.
[0052] Among them, special characters refer to characters used to decorate rich text content, such as overline, strikethrough (strikethrough), underline and other characters.
[0053] S102, obtaining a target program structure of the copy content, where the target program structure includes a plurality of element containers representing the copy content;
[0054] Among them, the target program structure refers to the document object model (DOM structure) formed when the copy content is described by markup languages such as HyperText Markup Language (HTML) and Cascading Style Sheets (CSS), and then presented in the browser. The DOM structure is the document object model that constitutes the page elements. In a rich text editor, the DOM structure is the basis for editing and displaying copy content. The DOM structure is a tree structure that represents an HTML or Extensible Markup Language (XML) document. This structure consists of multiple types of nodes, including element nodes, text nodes, attribute nodes, etc. Among them, element nodes correspond to elements in HTML or XML documents, such as strike elements.
[0055] Among them, the element container refers to the content represented by the element node of the target program structure (DOM structure), that is, the element container refers to the element node in the DOM structure, which contains the tags and their contents in the HTML or XML document. For example, the strike element is an element container, which is used to add a strikethrough effect to the text. Strike is an HTML tag used to indicate deleted text or text that is no longer accurate. It displays the strikethrough effect by adding a slash through the text.
[0056] S103: Determine a first element container carrying a special character tag from multiple element containers, and obtain element content and content attribute tags in the first element container;
[0057] Among them, special character tags refer to HTML tags, Cascading Style Sheets (CSS) styles, inline styles, etc. used to represent or create special decorative effects in the copy content. These tags and styles work together to enable the copy content to present diverse visual effects and semantic information.
[0058] The first element container refers to an element container that meets a specific condition found when traversing multiple element containers. The specific condition is that the element container must carry a tag representing a special character effect. The element content refers to the content of the copy content represented in the first element container.
[0059] The content attribute tag refers to the style element tag of the element content in the first element container. For example, the style element tag may be a style attribute (style), which is used to set or obtain the inline style of the element content.
[0060] S104: Create a second element container based on the element content and the content attribute tag, and set a special character tag for the second element container to obtain a target element container;
[0061] Among them, a second element container can be created, and then the element content and content attribute tags are assigned to the created second element container. After setting the special character tag for the second element container, the target element container is obtained. The second element container has not been added to any place in the document at this time, and the second element container can be added to the DOM structure.
[0062] S105: Replace the first element container with the target element container in the copy content, so as to display the element content carrying the special characters corresponding to the special character tag in the rich text editor.
[0063] The current target element container may be inserted as a sibling element after the first element container, and the first element container may be deleted to achieve replacement.
[0064] In an embodiment of the present application, when the rich text content of the browser is copied to the rich text editor, the format of the original rich text content, such as font, color, size, etc., can be maintained by maintaining multiple element containers. In the process of copying to the rich text editor, special characters may be ignored or processed incorrectly, resulting in failure to display in the rich text editor. By identifying and processing these special character tags, it is possible to ensure that they correctly display the special characters in the rich text content in the rich text editor. This solution can be used to display element content carrying special characters corresponding to special character tags in the rich text editor to achieve data consistency.
[0065] See also Figure 3 , a flow chart of a method for displaying special characters is provided for an embodiment of the present application. Figure 3 As shown, the method of the embodiment of the present application may include the following steps S201-S207.
[0066] S201, in response to a copy operation on rich text content, displaying a copy of the rich text content in a rich text editor, wherein the copy does not display special characters in the rich text content;
[0067] For details, please refer to step S101 in the above-mentioned embodiment of the specification, which will not be described in detail here.
[0068] S202, using the internal interface of the rich text editor, obtaining the web page content program of the rich text content from the web page program structure corresponding to the rich text content, and converting the web page content program into a target program structure of the copy content;
[0069] The web page program structure refers to the DOM structure of the rich text content. The web page content program refers to the HTML content. The target program structure refers to the DOM structure of the copy content.
[0070] Specifically, you can use the internal interface of Editablejs to get the HTML content of the rich text content copied to the editor from the DOM structure of the browser. For example, you can use the getContent() method to get the HTML content of the rich text content copied to the editor from the DOM structure of the browser. Then convert the HTML content into a DOM structure to get the DOM structure of the copy content. For example, you can use JavaScript's parser (DOMParser) to implement it, that is, you can directly call DOMParser to convert the HTML content into the DOM structure of the copy content.
[0071] The getContent() method is a DOM API method used to retrieve the HTML representation of the edited content from the internal DOM structure of the browser. The DOM API method refers to a set of programming interfaces used to operate, access and modify the Document Object Model (DOM).
[0072] S203, traversing multiple element containers of the target program structure, if it is detected that multiple element containers carry special character tags, obtaining the first element container carrying the special character tag;
[0073] Specifically, you can use the DOM interface to traverse and check whether it carries a special character tag, such as the strike tag. If it carries a special character tag, you can directly get the first element container carrying the special character tag through code. For example, use the following code to get the first element container: const strikes = child.getElementsByTagName('strike').
[0074] The line of code const strikes = child.getElementsByTagName('strike') means to traverse all child elements under the child element through the DOM interface and find those elements with the tag name strike.
[0075] S204, obtaining the program content of the element content of the first element container from the web page program structure, and obtaining the style element tag of the first element container from the web page program structure;
[0076] The program content refers to the HTML content of the element content of the first element container. Specifically, the HTML content refers to the web page content written using HTML tags and attributes. These contents include text, images, links, lists, tables, forms, etc.
[0077] Specifically, the HTML content of the element with the special character tag can be obtained from the DOM structure of the browser through: span.innerHTML = strike.innerHTML. The style element tag of the element with the special character tag can be obtained from the DOM structure of the browser through for (let property of strike.style). For example, the style attribute can be used to modify the CSS style of the element content of the second element container.
[0078] Among them, the line of code span.innerHTML = strike.innerHTML means to copy the HTML content of the strike element (including its internal HTML tags and text) to the innerHTML attribute of the span element.
[0079] Among them, the purpose of the line of code for (let property of strike.style) is to traverse the style attributes of the strike element.
[0080] S205, creating an initial element container, assigning the program content and style element tag of the element content to the initial element container, and obtaining a second element container;
[0081] Specifically, a new span can be created through const span = document.createElement('span'). This method will return a new DOM element node (initial element container), which has not been added to any place in the DOM structure. Then, the program content (such as HTML content) and style element tag (style attribute) of the original element content of the first element container are assigned to the created initial element container to obtain the second element container.
[0082] Among them, document.createElement('span') is used to create a new DOM element node in memory. The parameter 'span' here specifies the type of element to be created, that is, element. const span is a constant declaration.
[0083] S206, setting the tag of the element content of the second element container to a special character tag to obtain a target element container;
[0084] Specifically, by setting span.style.textDecoration = 'line-through', a special character tag can be set for the element content of the second element container, for example, a tag corresponding to an overline, a tag corresponding to a strikethrough, a tag corresponding to an underline, etc.
[0085] Among them, textDecoration is used to set the decorative effects on the text, such as underline, overline, strikethrough, etc. line-through refers to "through line" or "center line" or "strikethrough". span.style.textDecoration = 'line-through is used to set special character tags for the element content of the second element container.
[0086] S207: Insert the target element container into the target position of the copy content, and delete the first element container, where the target position is a position after the first element container in the copy content.
[0087] Specifically, the current target element container can be inserted as a sibling element behind the first element container in the DOM structure. After deleting the first element container, the target element container and the first element container are replaced. The element content carrying special characters can be displayed in a rich text editor.
[0088] In an embodiment of the present application, in response to a copy operation for rich text content, a copy of the rich text content can be displayed in a rich text editor, but the special characters in the rich text content are not displayed in the copy content. Therefore, the internal interface of the rich text editor can be used to obtain the web page content program of the rich text content from the web page program structure corresponding to the rich text content, and convert the web page content program into the target program structure of the copy content. When traversing multiple element containers of the target program structure, if it is detected that multiple element containers carry special character tags, then obtain the first element container carrying the special character tag. Obtain the program content of the element content of the first element container from the web page program structure, and obtain the style element tag of the first element container from the web page program structure. When creating an initial element container, assign the program content and style element tag of the element content to the initial element container to obtain a second element container. Set the tag of the element content of the second element container to the special character tag to obtain a target element container. Insert the target element container into the target position of the copy content, and delete the first element container. The target position is the position after the position of the first element container in the copy content. It is possible to display element content carrying special characters corresponding to special character tags in a rich text editor, thereby achieving data consistency between rich text content and copy content.
[0089] The following will be combined Figure 4 With reference to a specific example, the method for displaying special characters provided in an embodiment of the present application is described in detail.
[0090] like Figure 4 As shown, you can copy the web page content in the browser, get the rich text content, and display the copy of the copied rich text content in the rich text editor. Through the internal interface of the rich text editor (for example, Editablejs), get the DOM structure of the copy content, which contains multiple elements that can represent the web page content. If the strike tag is identified in the DOM structure, get all the elements with the strike tag from the DOM structure. Traverse the elements of the strike tag in sequence: create a span, and copy the HTML content and style of the element with the strike tag to the newly created span. Set the style of the span to line-through to get the target span. Insert the target span as a sibling element behind the element with the strike tag. After completing the operation on all strike tags, delete the elements with the strike tag, and you can restore the display of the strike line for the content that does not display the strike line in the rich text editor.
[0091] The DOM structure is a tree structure, which represents an HTML or Extensible Markup Language (XML) document. In the embodiment of the present application, the DOM structure refers to the copy content displayed in the DOM structure.
[0092] Among them, span is used to represent inline elements in the DOM structure.
[0093] Among them, strike is used to represent elements with a strikethrough in the DOM structure.
[0094] Among them, line-through refers to "through line" or "dash line" or "strikethrough". In Cascading Style Sheets (CSS), line-through is used to add a through line on text to indicate that the text has been deleted or is no longer valid.
[0095] The browser can be understood as a large container, including a rich text editor, which contains a copy of the web page content copied from the browser and a DOM structure that can edit the copy. When editing the DOM structure, if there is information or elements that need to be used, the corresponding code method is written to obtain the corresponding information, elements, etc. from the DOM structure in the browser.
[0096] In an embodiment of the present application, when a web page content is copied to a rich text editor in a browser, the copy content corresponding to the web page content displayed in the rich text editor does not display the special characters of the copied web page content because the strike of the DOM structure of the copy content is parsed as a span and no underline style is set. This can be done by creating a new span, assigning the innerHTML and style of the strike to the new span, and then setting the strike style for the span. For example, text-decoration:line-through, and then replacing the original strike with span, so that the special characters that originally disappeared can be displayed in the rich text editor, such as overline, strikethrough, underline, etc. Data consistency between the web page content and the copy content is achieved.
[0097] based on Figure 1 The following is a schematic diagram of the scene. Figure 5 , a display device for special characters provided in an embodiment of the present application is introduced in detail. It should be noted that, Figure 5 A display device for special characters in the present application Figure 2-Figure 4 For the convenience of explanation, only the part related to the embodiment of the present application is shown. For the specific technical details not disclosed, please refer to the present application. Figure 2-Figure 4 The embodiment shown.
[0098] See also Figure 5 , is a schematic diagram of a structure of a display device for special characters provided in an embodiment of the present application. Figure 5 As shown, the special character display device 1 of the embodiment of the present application may include: a content display unit 11, a structure acquisition unit 12, a container determination unit 13, a container creation unit 14 and a container replacement unit 15.
[0099] The content display unit 11 is used to display a copy of the rich text content in the rich text editor in response to a copy operation on the rich text content, wherein the copy does not display special characters in the rich text content;
[0100] A structure acquisition unit 12, used to acquire a target program structure of the copy content, the target program structure including a plurality of element containers representing the copy content;
[0101] The container determination unit 13 is used to determine a first element container carrying a special character tag from multiple element containers, and obtain element content and content attribute tags in the first element container;
[0102] The container creation unit 14 is used to create a second element container based on the element content and the content attribute tag, and set a special character tag for the second element container to obtain a target element container;
[0103] The container replacement unit 15 is used to replace the first element container with the target element container in the copy content, so as to display the element content carrying the special characters corresponding to the special character tag in the rich text editor.
[0104] Optionally, the structure acquisition unit 12 includes:
[0105] The program acquisition subunit 121 is used to acquire the web page content program of the rich text content from the web page program structure corresponding to the rich text content by using the internal interface of the rich text editor;
[0106] The structure conversion subunit 122 is used to convert the webpage content program into a target program structure of the copy content.
[0107] Optionally, the container determination unit 13 includes:
[0108] A traversal subunit 131, used for traversing multiple element containers of a target program structure;
[0109] The tag carrying subunit 132 is configured to obtain a first element container carrying a special character tag if it is detected that multiple element containers carry special character tags.
[0110] Optionally, the container determination unit 13 includes:
[0111] The acquisition subunit 133 is used to acquire the program content of the element content of the first element container from the web page program structure, and acquire the style element tag of the first element container from the web page program structure.
[0112] Optionally, the container creation unit 14 includes:
[0113] The container creation subunit 141 is used to create an initial element container;
[0114] The assignment subunit 142 is used to assign the program content and style element tag of the element content to the initial element container to obtain a second element container.
[0115] Optionally, the container creation unit 14 includes:
[0116] The tag setting subunit 143 is used to set the tag of the element content of the second element container to a special character tag to obtain a target element container.
[0117] Optionally, the container replacement unit 15 comprises:
[0118] The replacement subunit 151 is used to insert the target element container into the target position of the copy content and delete the first element container, where the target position is the position after the first element container in the copy content.
[0119] In an embodiment of the present application, in response to a copy operation for rich text content, a copy of the rich text content can be displayed in a rich text editor, but the special characters in the rich text content are not displayed in the copy content. Therefore, the internal interface of the rich text editor can be used to obtain the web page content program of the rich text content from the web page program structure corresponding to the rich text content, and convert the web page content program into the target program structure of the copy content. When traversing multiple element containers of the target program structure, if it is detected that multiple element containers carry special character tags, then obtain the first element container carrying the special character tag. Obtain the program content of the element content of the first element container from the web page program structure, and obtain the style element tag of the first element container from the web page program structure. When creating an initial element container, assign the program content and style element tag of the element content to the initial element container to obtain a second element container. Set the tag of the element content of the second element container to the special character tag to obtain a target element container. Insert the target element container into the target position of the copy content, and delete the first element container. The target position is the position after the position of the first element container in the copy content. It is possible to display element content carrying special characters corresponding to special character tags in a rich text editor, thereby achieving data consistency between rich text content and copy content.
[0120] See also Figure 6 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 6 As shown, the electronic device 500 includes a processor 501 and a memory 502. The processor 501 is electrically connected to the memory 502.
[0121] The processor 501 is the control center of the electronic device 500 and may include one or more processing cores. The processor 501 uses various interfaces and lines to connect various parts of the entire electronic device 500, and executes various functions and processes data of the electronic device 500 by running or calling computer programs stored in the memory 502, and calling data stored in the memory 502, so as to control the electronic device 500 as a whole. Optionally, the processor 501 can be implemented in at least one hardware form of digital signal processing (DSP), field programmable gate array (FPGA), and programmable logic array (PLA). The processor 501 can integrate one or a combination of CPU, graphics processing unit (GPU), modem, etc. Among them, the CPU mainly processes the operating system, user pages, and applications; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It is understandable that the above-mentioned modem may not be integrated into the processor 501, but may be implemented separately through a communication chip.
[0122] The memory 502 can be used to store software programs and modules, and the processor 501 executes various functional applications and data processing by running the computer programs and modules stored in the memory 502. The memory 502 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, a computer program required for at least one function, etc.; the data storage area can store data created according to the use of the electronic device 500, etc.
[0123] In addition, the memory 502 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. Accordingly, the memory 502 may also include a memory controller to provide the processor 501 with access to the memory 502.
[0124] In this embodiment, the processor 501 in the electronic device 500 loads instructions corresponding to the processes of one or more computer programs into the memory 502 according to the following steps, and the processor 501 runs the computer program stored in the memory 502 to implement various functions, as follows:
[0125] In response to a copy operation on rich text content, a copy of the rich text content is displayed in a rich text editor, and special characters in the rich text content are not displayed in the copy; a target program structure of the copy content is obtained, and the target program structure includes multiple element containers representing the copy content; a first element container carrying a special character tag is determined from the multiple element containers, and the element content and content attribute tags in the first element container are obtained; a second element container is created based on the element content and the content attribute tags, and a special character tag is set for the second element container to obtain a target element container; the target element container is used to replace the first element container in the copy content, so as to display the element content carrying special characters corresponding to the special character tags in the rich text editor.
[0126] Optionally, when executing the target program structure for obtaining the copy content, the processor 501 specifically performs:
[0127] The internal interface of the rich text editor is used to obtain the web page content program of the rich text content from the web page program structure corresponding to the rich text content; and the web page content program is converted into the target program structure of the copy content.
[0128] Optionally, when the processor 501 determines the first element container carrying the special character tag from the multiple element containers, it specifically performs:
[0129] Traverse multiple element containers of the target program structure; if it is detected that multiple element containers carry special character tags, obtain the first element container carrying the special character tag.
[0130] Optionally, when executing to obtain the element content and the content attribute tag in the first element container, the processor 501 specifically executes:
[0131] The program content of the element content of the first element container is obtained from the web page program structure, and the style element tag of the first element container is obtained from the web page program structure.
[0132] Optionally, when executing to create the second element container based on the element content and the content attribute tag, the processor 501 specifically executes:
[0133] Create an initial element container; assign the program content and style element tag of the element content to the initial element container to obtain a second element container.
[0134] Optionally, when the processor 501 sets a special character tag for the second element container to obtain a target element container, the processor 501 specifically performs:
[0135] The tag of the element content of the second element container is set to a special character tag to obtain the target element container.
[0136] Optionally, when the processor 501 replaces the first element container with the target element container in the copy content, the processor 501 specifically performs:
[0137] The target element container is inserted into the target position of the copy content, and the first element container is deleted. The target position is the position after the position of the first element container in the copy content.
[0138] In an embodiment of the present application, in response to a copy operation for rich text content, a copy of the rich text content can be displayed in a rich text editor, but the special characters in the rich text content are not displayed in the copy content. Therefore, the internal interface of the rich text editor can be used to obtain the web page content program of the rich text content from the web page program structure corresponding to the rich text content, and convert the web page content program into the target program structure of the copy content. When traversing multiple element containers of the target program structure, if it is detected that multiple element containers carry special character tags, then obtain the first element container carrying the special character tag. Obtain the program content of the element content of the first element container from the web page program structure, and obtain the style element tag of the first element container from the web page program structure. When creating an initial element container, assign the program content and style element tag of the element content to the initial element container to obtain a second element container. Set the tag of the element content of the second element container to the special character tag to obtain a target element container. Insert the target element container into the target position of the copy content, and delete the first element container. The target position is the position after the position of the first element container in the copy content. It is possible to display element content carrying special characters corresponding to special character tags in a rich text editor, thereby achieving data consistency between rich text content and copy content.
[0139] See also Figure 7 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 7 As shown, the electronic device 500 includes: a processor 501, a memory 502, a display screen 503 and a power supply 504. The processor 501 is electrically connected to the display screen 503 and the power supply 504 respectively.
[0140] The display screen 503 may be used to display information input by a user or information provided to a user and various graphical user interfaces of the electronic device 500 . These graphical user interfaces may be composed of images, texts, icons, videos and any combination thereof.
[0141] The power supply 504 is used to supply power to various components of the electronic device 500. In some embodiments, the power supply 504 may be logically connected to the processor 501 through a power management system, so that the power management system can manage charging, discharging, power consumption, and other functions.
[0142] It should be understood that the device provided in the embodiment of the present application is used to execute the above-mentioned method for displaying a special character, and thus can achieve the same effect as the above-mentioned implementation method.
[0143] In the case of an integrated unit, the device may include a processing module and a storage module. When the device is applied to an electronic device, the processing module may be used to control and manage the actions of the electronic device. The storage module may be used to support the electronic device in executing related program codes, etc.
[0144] The processing module may be a processor or a controller, which may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The storage module may be a memory.
[0145] In addition, the device provided in the embodiment of the present application can specifically be a chip, component or module, and the chip may include a connected processor and memory; wherein the memory is used to store instructions, and when the processor calls and executes the instructions, the chip can execute a special character display method provided in the above embodiment.
[0146] An embodiment of the present application also provides a computer-readable storage medium, in which a computer program code is stored. When the computer program code is executed on a computer, the computer executes the above-mentioned related method steps to implement a method for displaying special characters provided in the above-mentioned embodiment.
[0147] This embodiment further provides a computer program product. When the computer program product is run on a computer, the computer is caused to execute the above-mentioned related steps to implement a method for displaying special characters provided in the above-mentioned embodiment.
[0148] Among them, the device, computer-readable storage medium, computer program product or chip provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be repeated here.
[0149] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0150] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0151] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for displaying special characters, characterized in that: The method comprises: In response to a copy operation on the rich text content, displaying a copy of the rich text content in a rich text editor, wherein the copy does not display special characters in the rich text content; Acquire a target program structure of the copy content, wherein the target program structure includes a plurality of element containers representing the copy content; Determine a first element container carrying a special character tag from the multiple element containers, and obtain element content and content attribute tags in the first element container; Creating a second element container based on the element content and the content attribute tag, and setting the special character tag for the second element container to obtain a target element container; The target element container is used to replace the first element container in the copy content, so as to display the element content carrying the special characters corresponding to the special character tag in the rich text editor.
2. The method according to claim 1, characterized in that The target program structure for obtaining the copy content includes: Using the internal interface of the rich text editor, obtaining the web page content program of the rich text content from the web page program structure corresponding to the rich text content; The web page content program is converted into a target program structure of the copy content.
3. The method according to claim 1, characterized in that The determining the first element container carrying the special character tag from the multiple element containers includes: traversing a plurality of element containers of the target program structure; If it is detected that the multiple element containers carry special character tags, then a first element container carrying the special character tag is obtained.
4. The method according to claim 2, characterized in that: The obtaining of the element content and the content attribute tag in the first element container includes: The program content of the element content of the first element container is obtained from the web page program structure, and the style element tag of the first element container is obtained from the web page program structure.
5. The method according to claim 4, characterized in that The creating a second element container based on the element content and the content attribute tag includes: Create the initial element container; The program content of the element content and the style element tag are assigned to the initial element container to obtain a second element container.
6. The method according to claim 5, characterized in that The step of setting the special character tag on the second element container to obtain a target element container includes: The tag of the element content of the second element container is set to the special character tag to obtain a target element container.
7. The method according to claim 1, characterized in that The step of replacing the first element container with the target element container in the copy content includes: The target element container is inserted into a target position of the copy content, and the first element container is deleted, where the target position is a position after the position of the first element container in the copy content.
8. A display device for special characters, characterized in that: The device comprises: A content display unit, configured to display a copy of the rich text content in a rich text editor in response to a copy operation on the rich text content, wherein the copy does not display special characters in the rich text content; A structure acquisition unit, configured to acquire a target program structure of the copy content, wherein the target program structure includes a plurality of element containers representing the copy content; A container determining unit, configured to determine a first element container carrying a special character tag from the multiple element containers, and obtain element content and content attribute tags in the first element container; a container creation unit, configured to create a second element container based on the element content and the content attribute tag, and set the special character tag for the second element container to obtain a target element container; A container replacement unit is used to replace the first element container with the target element container in the copy content, so as to display the element content carrying the special characters corresponding to the special character tag in the rich text editor.
9. An electronic device, characterized in that: The electronic device comprises: A memory for storing executable program codes; A processor, configured to call and run the executable program code from the memory, so that the electronic device executes the method according to any one of claims 1 to 7.
10. A computer storage medium, characterized in that: The computer storage medium stores a plurality of instructions, which are suitable for being loaded by a processor and executing the steps of the method according to any one of claims 1 to 7.
