Text conversion method and device, electronic equipment and storage medium

By analyzing Markdown text as a hypertext markup language document and combining the processing of rendering components, the Markdown text conversion problems are solved, and the conversion effect is efficient, low-cost and consistent in structure is achieved.

CN119047425APending Publication Date: 2024-11-29TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202310619668.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-05-29
Publication Date
2024-11-29

AI Technical Summary

Technical Problem

In the prior art, the conversion of Markdown text to PDF or pictures is inefficient, costly and poorly restored, and the converted content is inconsistent with the content viewed by the browser.

Method used

By analyzing Markdown text as a hypertext markup language document, combining preset standard hypertext markup language templates, downloading and replacing the cascading style sheet, using the rendering components of the target format to render the text to generate efficient, low-cost and consistent structure Convert the result.

Benefits of technology

It realizes efficient and low-cost text conversion, and the converted HTML structure, CSS and content viewed by the browser are highly consistent, ensuring the quality of the converted content.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119047425A_ABST
    Figure CN119047425A_ABST
Patent Text Reader

Abstract

The invention discloses a text conversion method and device, electronic equipment and a storage medium, and the method comprises the steps: determining a hypertext markup language document of a to-be-converted text in response to a conversion request for the to-be-converted text written based on Markdown; the hypertext markup language document is used as main body content to be combined with a preset standard hypertext markup language template, and a cascading style sheet linked with the combined hypertext markup language text is downloaded to a local storage space; and replacing a cascading style outer link path in the combined hypertext markup language text based on a local storage path of the cascading style sheet, and then performing rendering processing on the replaced combined hypertext markup language text based on a rendering component corresponding to a target format requested to be converted to obtain a text conversion result corresponding to the to-be-converted text. Therefore, the conversion efficiency is high, the conversion cost is low, the restoration degree is good, and it is guaranteed that the converted content is highly consistent with the content viewed through the browser.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a text conversion method, device, electronic device and storage medium. Background Art

[0002] Markdown is a lightweight markup language that allows users to write documents in a plain text format that is easy to read and write, and then convert it into a valid HTML document. Due to Markdown's lightweight, easy to read and write features, and its support for images, charts, and mathematical formulas, many websites currently use Markdown to write documentation or post messages on forums.

[0003] like Figure 1a The following is an example of text written by a content provider using Markdown (hereinafter referred to as Markdown source text). Figure 1b for Figure 1a The actual content expressed by the Markdown source text shown in the figure. Therefore, if the content provider directly forwards the Markdown source text to the reader, due to the markup language characteristics of Markdown itself, the reader's reading experience is poor and it is difficult to fully understand what the content provider wants to express.

[0004] In the related art, in order to facilitate the reading party to view, it is usually necessary to convert the Markdown source text into a PDF or image format that is easy to read and spread. However, the conversion method in the related art not only has low conversion efficiency and high conversion cost, but also has poor restoration, and the converted content is inconsistent with the content of the Markdown source text viewed through the browser. Summary of the invention

[0005] In order to solve the problems of the prior art, the embodiments of the present application provide a document conversion method, device, electronic device and storage medium. The technical solution is as follows:

[0006] In one aspect, a text conversion method is provided, the method comprising:

[0007] In response to a conversion request indicating that a text to be converted is to be converted into a target format, determining a hypertext markup language document of the text to be converted; the text to be converted is a text written based on a lightweight markup language Markdown, and the hypertext markup language document is obtained by parsing the text to be converted;

[0008] The hypertext markup language document is used as the main content and combined with a preset standard hypertext markup language template to obtain a combined hypertext markup language text; the preset standard hypertext markup language template is linked to a cascading style sheet;

[0009] Downloading the cascading style sheet of the combined hypertext markup language text link to a local storage space, and replacing the cascading style external link path in the combined hypertext markup language text based on the local storage path of the cascading style sheet to obtain a replaced combined hypertext markup language text;

[0010] Based on the rendering component corresponding to the target format, the replaced combined hypertext markup language text is rendered to obtain a text conversion result corresponding to the text to be converted.

[0011] On the other hand, a text conversion device is provided, the device comprising:

[0012] A markup language document determination module is used to determine a hypertext markup language document of the text to be converted in response to a conversion request indicating that the text to be converted is converted into a target format; the text to be converted is a text written based on the lightweight markup language Markdown, and the hypertext markup language document is obtained by parsing the text to be converted;

[0013] A combination module, used to combine the hypertext markup language document as the main content with a preset standard hypertext markup language template to obtain a combined hypertext markup language text; the preset standard hypertext markup language template is linked to a cascading style sheet;

[0014] A cascading style processing module, used for downloading the cascading style sheet of the combined hypertext markup language text link to a local storage space, and replacing the cascading style external link path in the combined hypertext markup language text based on the local storage path of the cascading style sheet, to obtain the replaced combined hypertext markup language text;

[0015] The rendering module is used to render the replaced combined hypertext markup language text based on the rendering component corresponding to the target format to obtain a text conversion result corresponding to the text to be converted.

[0016] In some exemplary embodiments, the apparatus further comprises:

[0017] A traversal module, used for traversing the tags in the combined hypertext markup language text, and for a current tag traversed to, if the current tag has a resource attribute, obtaining the attribute value of the resource attribute;

[0018] A first replacement processing module is used to download a resource file corresponding to the third-party resource path to the local storage space and replace the attribute value with the local storage path of the resource file when the attribute value is a third-party resource path;

[0019] A second replacement processing module is used to verify the attribute value based on a preset local resource path when the attribute value is a local resource path, and replace the attribute value with the preset local resource path when the verification result indicates that the verification fails;

[0020] The third replacement processing module is used for, when the attribute value is the encoded content, if the encoded content is in an abnormal encoding format, processing the encoded content in the abnormal encoding format into a corresponding normal image and storing it in the local storage space, and replacing the attribute value with the local storage path of the normal image.

[0021] In some exemplary embodiments, after replacing the attribute value with the local storage path of the resource file, the first replacement processing module is further used to: determine the resource type of the resource file; when the resource type does not match the target format, perform preset processing on the resource file in the local storage space to obtain a processed resource; the resource type of the processed resource matches the target format.

[0022] In some exemplary embodiments, the rendering module includes:

[0023] A search module, used for searching the target tag of the replaced combined hypertext markup language text; the target tag is used for marking the container of the scalable vector graphics;

[0024] A first rendering submodule is configured to, when the target tag is found, call a first rendering component to convert the text content of the target tag into content in the target format;

[0025] A content replacement module, used to replace the corresponding text in the target tag combined with the hypertext markup language text after the replacement with the content in the target format, to obtain an intermediate text conversion result;

[0026] The second rendering submodule is used to call the second rendering component to convert the intermediate text conversion result into the target format to obtain a text conversion result corresponding to the text to be converted.

[0027] In some exemplary embodiments, the markup language document determination module is specifically used to: obtain a conversion request indicating that the text to be converted is converted into a target format, the conversion request carrying the text to be converted; extract the text to be converted in the conversion request, and parse the text to be converted into the hypertext markup language document; or, obtain a conversion request indicating that the text to be converted is converted into a target format, the conversion request carries a hypertext markup language document of the text to be converted, the hypertext markup language document is obtained by parsing the text to be converted when the client displays the text to be converted based on a browser; extract the hypertext markup language document from the conversion request.

[0028] In some exemplary embodiments, the markup language document determination module includes a parsing module, and the parsing module includes:

[0029] A first text segmentation module is used to determine the total length of the text to be converted, and if the total length of the text to be converted is greater than a preset text length, the text to be converted is segmented based on the first-level title to obtain a first-level segmented text sequence;

[0030] A second text segmentation module is used to take the first-level segmented text sequence as the current text sequence, and if there is a target text with a total text length greater than the preset text length in the current text sequence, and there is a next-level title in the target text, then the target text is segmented based on the next-level title to obtain a segmented text sequence corresponding to the next level;

[0031] A recursive execution module, used for recursively executing the segmented text sequence corresponding to the next level as the current text sequence, until the current text sequence satisfies a preset stop condition, thereby obtaining a segmented text sequence of a target level; the preset stop condition includes that the total text length of each text in the current text sequence is less than the preset text length, or the target level is a preset title level;

[0032] A parsing submodule, used for parsing each segmented text in the segmented text sequence of the target level into a hypertext markup language segment;

[0033] The markup language fragment combination module is used to combine the hypertext markup language fragments corresponding to each of the segmented texts based on the sorting rules of each of the segmented texts in the segmented text sequence at the target level to obtain the hypertext markup language document.

[0034] In some exemplary embodiments, the parsing submodule includes:

[0035] A parsing instruction generation module, used for generating a parsing instruction corresponding to each segmented text based on each segmented text in the segmented text sequence of the target level;

[0036] The parallel calling module is used to perform Markdown parsing service calls in parallel based on the parsing instructions corresponding to each of the segmented texts, so as to obtain the hypertext markup language fragments corresponding to each of the segmented texts.

[0037] In some exemplary embodiments, the parallel calling module includes:

[0038] A parsing engine matching module, configured to determine, for each of the segmented texts, a Markdown parsing engine that matches the segmented text based on the Markdown syntax in the segmented text;

[0039] The parallel calling submodule is used to call the Markdown parsing engines matched by each of the segmented texts in parallel based on the parsing instructions corresponding to each of the segmented texts, so as to obtain the hypertext markup language fragments corresponding to each of the segmented texts.

[0040] In some exemplary embodiments, when the conversion request includes custom content, the combination module is specifically used to: combine the hypertext markup language document and the custom content as main content with a preset standard hypertext markup language template to obtain a combined hypertext markup language text;

[0041] The cascading style sheet of the preset standard hypertext markup language template link includes cascading style information corresponding to the hypertext markup language document and cascading style information corresponding to the custom content.

[0042] On the other hand, an electronic device is provided, including a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the text conversion method of any of the above aspects.

[0043] On the other hand, a computer-readable storage medium is provided, in which at least one instruction or at least one program is stored, and the at least one instruction or the at least one program is loaded and executed by a processor to implement the text conversion method as described in any of the above aspects.

[0044] On the other hand, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the electronic device performs the text conversion method of any aspect above.

[0045] The embodiment of the present application determines the hypertext markup language document of the text to be converted by responding to a conversion request for the text to be converted written based on Markdown, and then combines the hypertext markup language document as the main content with a preset standard hypertext markup language template, and downloads the cascading style sheet linked to the combined hypertext markup language text to the local storage space, replaces the cascading style external link path in the combined hypertext markup language text based on the local storage path of the cascading style sheet, and then renders the replaced combined hypertext markup language text based on the rendering component corresponding to the target format requested for conversion, and obtains the text conversion result corresponding to the text to be converted. The above technical solution not only has high conversion efficiency and low conversion cost, but also has good restoration. The HTML structure and CSS of the converted text are consistent with the Markdown source text viewed on the browser, ensuring that the converted content is highly consistent with the content viewed through the browser. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0047] Figure 1a is an example of textual Markdown source text written by a content contributor using Markdown;

[0048] Figure 1b yes Figure 1a An example of what the Markdown source text actually expresses;

[0049] Figure 2 It is a schematic diagram of an implementation environment provided by an embodiment of the present application;

[0050] Figure 3 It is a flowchart of a text conversion method provided in an embodiment of the present application;

[0051] Figure 4a This is an example of an entry for exporting a single Markdown source text provided in an embodiment of the present application;

[0052] Figure 4b This is an entry example for batch exporting multiple Markdown source texts provided in an embodiment of the present application;

[0053] Figure 5 It is a schematic diagram of a process of parsing a text to be converted into a hypertext markup language document provided by an embodiment of the present application;

[0054] Figure 6 It is a flowchart of another text conversion method provided in an embodiment of the present application;

[0055] Figure 7 It is a flowchart of another text conversion method provided in an embodiment of the present application;

[0056] Figure 8 is a structural block diagram of a text conversion device provided in an embodiment of the present application;

[0057] Fig. 9 It is a hardware structure block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0058] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0059] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0060] It is understandable that in the specific implementation of this application, related data such as user information is involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.

[0061] In order to facilitate readers to view the content of Markdown text written by content providers based on Markdown, it is usually necessary to convert the Markdown source text into PDF or pictures and other easy-to-read and disseminate forms. One conversion method in the related art is to use the Pandoc conversion tool. Pandoc is a cross-platform, free open source and command line interface markup language conversion tool written in Haskell language. It can support the conversion of Markdown standard source files into PDF files through latex extension. However, Pandoc's Markdown rendering style is limited, and it is impossible to achieve complete customization like Cascading Style Sheets (CSS), and Pandoc can only process standard Markdown syntax. If there is a Markdown extension (such as Mermaid drawing extension, Mermaid is a Javascript-based chart drawing tool that implements the creation and dynamic modification of charts by parsing Markdown-like text syntax), it will cause Pandoc to be unable to recognize and convert it into PDF. Another conversion method in the related art is to directly convert the Markdown source text into PDF through programming. Since programming is required, it means that the more complex the Markdown source text is, the more complex the style information and text structure of the text described during programming are. Therefore, the conversion method in the related art not only has low conversion efficiency and high conversion cost, but also has poor restoration degree, and the converted content is inconsistent with the content of the Markdown source text viewed through the browser.

[0062] In view of this, an embodiment of the present application provides a text conversion method for text written based on Markdown. This method not only has high conversion efficiency and low conversion cost, but also has good restoration degree. The HTML (HyperText Markup Language) structure and CSS of the converted text are consistent with the Markdown source text viewed on the browser, ensuring that the converted content is highly consistent with the content viewed through the browser.

[0063] See also Figure 2 , which is a schematic diagram of an implementation environment provided by an embodiment of the present application, the implementation environment includes a terminal 210 and a server 220, wherein the terminal 210 and the server 220 can communicate via a wired or wireless network connection.

[0064] The terminal 210 includes but is not limited to a mobile phone, a computer, an intelligent voice interaction device, a smart home appliance, a vehicle terminal, an aircraft, etc. The terminal 210 runs a client software with a text conversion function, such as an application (Application, referred to as App), which can be an independent application or a subroutine in the application. In the embodiment of the present application, the above-mentioned text conversion function is used to convert the Markdown source text into a document in PDF format or image format.

[0065] The server 220 can provide background services for the application in the terminal 210, and the background services can specifically be text conversion services for Markdown source texts, so as to convert the Markdown source texts into formats that are easy to read and disseminate, such as PDF format, image format, and word document format.

[0066] It should be noted that the server involved in the embodiments of the present application can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network) and big data and artificial intelligence platforms.

[0067] In an exemplary embodiment, the terminal 210 and the server 220 can both be node devices in the blockchain system, and can share the acquired and generated information with other node devices in the blockchain system to achieve information sharing between multiple node devices. Multiple node devices in the blockchain system can be configured with the same blockchain, which is composed of multiple blocks, and the adjacent blocks have an association relationship, so that when the data in any block is tampered, it can be detected by the next block, thereby preventing the data in the blockchain from being tampered with, and ensuring the security and reliability of the data in the blockchain.

[0068] The embodiments of the present application can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving, etc.

[0069] See also Figure 3 , which is a flow chart of a text conversion method provided by an embodiment of the present application, which can be applied to Figure 2Server in. It should be noted that this specification provides method operation steps as described in the embodiments or flow charts, but more or fewer operation steps may be included based on routine or non-creative work. The order of steps listed in the embodiments is only one way of executing the steps among many orders, and does not represent the only order of execution. When the actual system or product is executed, it can be executed in sequence or in parallel (for example, in a parallel processor or multi-threaded processing environment) according to the method shown in the embodiments or drawings. Specific examples Figure 3 As shown, the method may include:

[0070] S301, in response to a conversion request instructing to convert a text to be converted into a target format, determining a hypertext markup language document of the text to be converted.

[0071] The text to be converted is a text written in the lightweight markup language Markdown, such as Figure 1a It can be used as an example of the text to be converted. The hypertext markup language HTML document of the text to be converted is obtained by parsing the text to be converted.

[0072] The target format is a format that is easy to read and spread, such as PDF format, image format, and word format. For example, you can request to convert the text to be converted based on Markdown into a document in PDF format, image format, or word format. The specific conversion can be set by the requester based on actual needs. In order to facilitate the description of the technical solution, the embodiment of the present application will be described below using the target format of PDF format or image format as an example.

[0073] In actual applications, when the user of the terminal needs to convert the Markdown source text into PDF format or image format, he can initiate a conversion instruction for the Markdown source text to the target format. Based on the conversion instruction, the terminal sends a conversion request to the server, and the conversion request is used to request that the Markdown source text, i.e., the text to be converted, be converted into the target format. Correspondingly, after the server completes the conversion in response to the conversion request, it can return the corresponding text conversion result to the terminal.

[0074] In a specific implementation, the terminal can provide two types of entrances for the above text conversion function. One type of entrance is used to export a single Markdown source text, such as Figure 4aThe figure shows an example of such an entry. When a user is browsing a Markdown source text, if he wants to export the Markdown source text, he can select "Export markdown" for the text to be converted, and then select the target format after export in the drop-down export formats "PDF document" and "long image". For example, the target format can be "PDF document", and then the terminal sends a conversion request to the server based on the target format to instruct the conversion of the single Markdown source text into the target format.

[0075] Another type of entry is used to batch export multiple Markdown source texts, such as Figure 4b The figure shows an example of such an entry. The terminal can display all documents written based on Markdown. The user can check the documents to be exported according to actual needs, and select the target format after export for the checked documents, such as "Export to PDF" or "Export to Image". Then, based on the target format, the terminal sends a conversion request to the server to instruct the selected Markdown source texts to be converted into the target format respectively. The server receives the conversion request and performs text conversion processing on each checked Markdown source text as the text to be converted.

[0076] In some exemplary embodiments, the above-mentioned step S301 may include: obtaining a conversion request indicating that the text to be converted is converted into a target format, the conversion request carrying a hypertext markup language document of the text to be converted, and the hypertext markup language document is obtained by parsing the text to be converted when the client displays the text to be converted based on the browser.

[0077] In a specific implementation, if the conversion request is issued under the Markdown viewing page of the browser, then the text to be converted has been parsed into a hypertext markup language HTML document by the parsing engine at this time, and a conversion request can be directly generated based on the hypertext markup language HTML document and sent to the server. At this time, the conversion request can carry the hypertext markup language HTML document of the text to be converted. After receiving the conversion request, the server can directly extract the hypertext markup language HTML document of the text to be converted from the conversion request, thereby avoiding the operation of parsing the Markdown source text into an HTML document again in the background, which is conducive to improving the efficiency of text conversion.

[0078] The parsing engine may be cherry markdown, a Javascript Markdown editor that is ready to use, lightweight, simple, and easy to expand. It can run on a browser or a server.

[0079] In other exemplary embodiments, the above step S301 may include: obtaining a conversion request indicating that the text to be converted is to a target format, the conversion request carrying the text to be converted; extracting the text to be converted in the conversion request, and parsing the text to be converted into a hypertext markup language document.

[0080] In a specific implementation, if the conversion request is issued in a non-browser Markdown viewing page (such as a list page or a non-browser environment), since the text to be converted has not been parsed into a hypertext markup language HTML document at this time, a conversion request can be generated based on the text to be converted and sent to the server, that is, the text to be converted is carried in the conversion request. After receiving the conversion request, the server can extract the text to be converted from the conversion request, and then parse the text to be converted into a corresponding hypertext markup language HTML document.

[0081] When the server parses the text to be converted into the corresponding hypertext markup language HTML document, it can call the cherry markdown service to implement it. The cherry markdown service is a background application running on node.js provided by the cherry markdown open source component, which supports converting markdown fragments into HTML fragments on the server side.

[0082] In some exemplary implementations, in order to speed up text conversion and improve text conversion efficiency, when parsing the text to be converted into a hypertext markup language HTML document, a Markdown slicing method can be used, such as Figure 5 The provided flowchart of parsing the text to be converted into a hypertext markup language document may include:

[0083] S501, determining the total length of the text to be converted.

[0084] S503: Determine whether the total length of the text to be converted is greater than a preset text length.

[0085] Specifically, if the judgment result is yes, that is, the total text length of the text to be converted is greater than the preset text length, it indicates that the text to be converted is a long text (super-long markdown content), and the following step S505 can be executed at this time; conversely, if the judgment result is no, that is, the total text length of the text to be converted is less than or equal to the preset text length, it indicates that the text to be converted is not a long text, and the following step S515 can be executed at this time.

[0086] Among them, the preset text length can be set based on actual experience, and the embodiment of the present application does not limit the specific value of the preset text length.

[0087] S505, segmenting the text to be converted based on the first-level title to obtain a first-level segmented text sequence.

[0088] Specifically, when the total length of the text to be converted is greater than the preset text length, the content of each first-level title in the text to be converted can be segmented as a segmentation unit, so that the segmented text corresponding to each first-level title can be obtained. The segmented texts can be arranged according to the order of each first-level title in the text to be converted, and a first-level segmented text sequence can be obtained.

[0089] For example, the first-level title can be matched and searched using a regular expression such as ^#.*.

[0090] S507, taking the above-mentioned first-level segmented text sequence as the current text sequence, if there is a target text in the current text sequence whose total text length is greater than the preset text length, and there is a next-level title in the target text, then the target text is segmented based on the next-level title to obtain a segmented text sequence corresponding to the next level.

[0091] Exemplarily, the next level title can use a corresponding regular expression to match the search, for example, the second level title can use the regular expression: ^##.*.

[0092] S509: recursively execute the segmented text sequence corresponding to the next level as the current text sequence until the current text sequence meets a preset stop condition, thereby obtaining a segmented text sequence of the target level.

[0093] The preset stop condition includes that the total text length of each text in the current text sequence is less than the preset text length, or the target level is a preset title level.

[0094] The above steps S507 and S509 are described below by taking the fifth-level title as an example.

[0095] For the first-level segmented text sequence, determine the total text length of each text in the first-level segmented text sequence, and search for the target text whose total text length in the first-level segmented text sequence is greater than the preset text length. If one or more such target texts are found, then for each target text: if there is a secondary title (the next level title of the first-level title) in the target text, then the target text is segmented using the content of each secondary title as the segmentation unit. If there is no secondary title in the target text, then the target text is not segmented to prevent the content from being fragmented. It should be noted that the above segmentation process is performed on the basis of the first-level segmented text sequence. When each target text is processed, the segmented text sequence corresponding to the secondary title can be obtained.

[0096] It can be understood that if no target text having a total text length greater than the preset text length is found in the first-level segmented text sequence, the first-level segmented text sequence is used as the segmented text sequence of the target level to perform the following step S511.

[0097] For the segmented text sequence corresponding to the secondary title, since the fifth-level title has not been reached, the total text length of each text in the segmented text sequence can be determined, and the target text whose total text length in the segmented text sequence is greater than the preset text length can be searched. If it is not found, it indicates that the total text length of each text in the segmented text sequence is less than the preset text length. At this time, the following steps S511 can be performed; if one or more such target texts are found in the segmented text sequence, then for each target text: if there is a third-level title (the next level title of the second-level title) in the target text, the target text is segmented with the content of each third-level title as the segmentation unit. If there is no third-level title in the target text, the target text is not segmented to prevent the content from being split. It should be noted that the above segmentation process is performed on the basis of the segmented text sequence corresponding to the secondary title. When each target text is processed, the segmented text sequence corresponding to the third-level title can be obtained.

[0098] Similarly, for the segmented text sequence corresponding to the third-level title, the same operation as the segmented text sequence corresponding to the second-level title is performed until the segmented text sequence corresponding to the fifth-level title is obtained and the recursive execution stops.

[0099] S511, parsing each segmented text in the segmented text sequence of the target level into a hypertext markup language segment.

[0100] Specifically, a Markdown parsing service such as Cherry Markdown may be called to parse each segmented text into a Hypertext Markup Language HTML fragment.

[0101] In some possible implementations, in order to further improve the text conversion efficiency, the above-mentioned step S511 may include: based on each segmented text in the segmented text sequence of the target level, generating a parsing instruction corresponding to each segmented text, and then performing Markdown parsing service calls in parallel based on the parsing instructions corresponding to each segmented text to obtain a hypertext markup language fragment corresponding to each segmented text.

[0102] Specifically, assuming that the segmented text sequence at the target level includes n segmented texts, n parsing instructions can be generated, each parsing instruction corresponds to one segmented text, and then the Markdown parsing service is called in parallel based on the n parsing instructions, so that the Markdown parsing service can synchronously and parallelly perform parsing based on the n parsing instructions to obtain the hypertext markup language fragment corresponding to each segmented text.

[0103] The above implementation method can further improve the text conversion efficiency by generating a parsing instruction corresponding to each segmented text and then calling the Markdown parsing service in parallel to perform parsing processing.

[0104] In some possible implementations, in order to improve the flexibility of text conversion, when calling the Markdown parsing service in parallel based on the parsing instructions corresponding to each segmented text to obtain the hypertext markup language fragment corresponding to each segmented text, for each segmented text, the Markdown parsing engine that matches the segmented text can be determined based on the Markdown syntax in the segmented text, and then the Markdown parsing engines that match each segmented text are called in parallel based on the parsing instructions corresponding to each segmented text to obtain the hypertext markup language fragment corresponding to each segmented text.

[0105] In the above implementation, by matching the Markdown parsing engine of the segmented text based on the Markdown syntax in the segmented text, special Markdown syntax can be supported, thereby improving the flexibility of text conversion.

[0106] S513, combining the hypertext markup language segments corresponding to the segmented texts based on the sorting rules of the segmented texts in the segmented text sequence at the target level to obtain the hypertext markup language document of the text to be converted.

[0107] Specifically, by combining the hypertext markup language segments corresponding to the segmented texts based on the sorting rules of the segmented texts, the final parsed hypertext markup language document of the long text can be restored.

[0108] S515, parsing the text to be converted into a corresponding hypertext markup language document.

[0109] Specifically, a corresponding parsing instruction may be directly generated based on the text to be converted, and then a Markdown parsing service may be called based on the parsing instruction, so that the Markdown parsing service parses the text to be converted into a hypertext markup language document.

[0110] In the above implementation, through steps S501 to S515, the Markdown long text is parsed and processed in a slice manner, which can greatly improve the text conversion efficiency.

[0111] S303, taking the hypertext markup language document of the text to be converted as the main content, and combining it with a preset standard hypertext markup language template to obtain a combined hypertext markup language text.

[0112] Among them, the preset standard hypertext markup language template is linked to a cascading style sheet.

[0113] Specifically, the preset standard hypertext markup language templates include three, namely DOCTYPE, and . Among them, DOCTYPE is used to describe the HTML type; it contains general information and metadata about the page, which is pre-set based on display requirements, and the cascading style external link path for linking the cascading style sheet is set in this tag; it is used to describe the content displayed on the page, that is, the main content. The content in the standard hypertext markup language template needs to be filled in through step S303.

[0114] In a specific implementation, the hypertext markup language document of the text to be converted can be combined with a preset standard hypertext markup language template as the main content (i.e., the content of the body tag) in a slot manner. Exemplarily, a string "${markwon_dom_tree}" can be set in the tag of the standard hypertext markup language template, and the string is replaced with the hypertext markup language document of the text to be converted based on string matching during combination to achieve the combination of the hypertext markup language document and the preset standard hypertext markup language template to obtain a combined hypertext markup language text.

[0115] S305, downloading the cascading style sheet of the combined hypertext markup language text link to the local storage space, and replacing the cascading style external link path in the combined hypertext markup language text based on the local storage path of the cascading style sheet to obtain the replaced combined hypertext markup language text.

[0116] The cascading style external link path in the combined hypertext markup language text comes from a preset standard hypertext markup language template, and the cascading style external link path points to the linked external cascading style sheet.

[0117] The local storage space may be a memory space on the server.

[0118] In a specific implementation, the preset standard hypertext markup language template can be used <link> The tag is used to link to the style sheet. The tag contains three attributes: rel, type, and href. Rel specifies the relationship between the html file and the external link style file. The value of stylesheet means that the referenced file is a style sheet. Type is used to specify the type of the external link style sheet. Href is used to specify the corresponding cascading style external link path, i.e., the URL address. Then, based on the attribute value of the href attribute, i.e., the URL address, the linked cascading style sheet can be downloaded, and then the cascading style sheet can be stored in the local storage space. The storage address of the cascading style sheet in the local storage space is obtained to obtain its corresponding local storage path. Then, the attribute value of the href attribute in the combined hypertext markup language text, i.e., the above-mentioned URL address, is replaced with the local storage path to obtain the replaced combined hypertext markup language text.

[0119] It should be noted that after replacing the cascading style external link path in the combined hypertext markup language text with the local storage path of the cascading style sheet, if there are special styles in the combined hypertext markup language text, the special styles will be processed again, and the specific secondary processing method can be determined based on the target format. For example, when the target format is PDF, corresponding secondary processing is required to avoid adding page breaks in the middle of the table.

[0120] S307, based on the rendering component corresponding to the target format, rendering processing is performed on the replaced combined hypertext markup language text to obtain a text conversion result corresponding to the text to be converted.

[0121] Specifically, when the target format is PDF, the rendering component can be wkhtmltopdf, which supports converting HTML to PDF via the command line; when the target format is image, the rendering component can be wkhtmltoimage, which supports converting HTML to image via the command line. Of course, other rendering components that can convert to the target format can also be used, such as the Chrome headless component and the open source component html-docx-js.

[0122] The conversion restoration degree of the above technical solution in the embodiment of the present application is reflected in two aspects: first, the converted HTML structure and CSS are consistent with those viewed on the browser, and second, the converted HTML and CSS are consistent with the browser rendering method. The specific analysis is as follows:

[0123] The first is the consistency of HTML structure: when the user opens the markdown document through the browser, the DOM tree structure of the public page is defined as common_dom_tree, and the DOM tree structure after parsing by calling the markdown conversion engine (such as cherry markdown) is defined as markwon_dom_tree. Then, when using the browser to view, through the browser API (such as innerHTML), insert markwon_dom_tree into the DOM tree node of common_dom_tree (such as the body tag), and the final complete DOM structure of the browser is browser_html=common_dom_tree+markwon_dom_tree. In the embodiment of the present application, the public DOM tree is consistent based on the preset standard hypertext markup language template, which is defined as common_dom_tree; markwon_dom_tree is replaced with the specified structure (such as the body tag) by combination, and the converted complete DOM structure is obtained as export_html=common_dom_tree+markwon_dom_tree. It can be seen that if the parsing rules of the markdown conversion engine are consistent, the converted export_html and the browser_html viewed by the browser can be completely consistent.

[0124] The second is the consistency of CSS. Since the external link address of CSS is written in common_dom_tree, and the common_dom_tree of the embodiment of the present application and the browser are viewed, the two are consistent. Therefore, the text conversion result after the conversion of the embodiment of the present application is consistent with the CSS viewed by the actual browser.

[0125] In addition, the embodiment of the present application uses rendering components of the target format, such as third-party open source components wkhtmltopdf and wkhtmltoimage, to achieve rendering. By comparing the display effects of the open source components, it is found that the same rendering effect as the browser can be achieved.

[0126] It can be seen that the technical solution of the embodiment of the present application not only has high conversion efficiency and low conversion cost, but also has good restoration degree. The HTML (HyperText Markup Language) structure and CSS of the converted text are consistent with the Markdown source text viewed on the browser, ensuring that the converted content is highly consistent with the content viewed through the browser.

[0127] In some exemplary implementations, in order to further improve the restoration degree of text conversion, such as Figure 6As shown, the above step S307 may include:

[0128] S601, searching for a target tag in the replaced combined hypertext markup language text, where the target tag is used to mark a container of a scalable vector graphics.

[0129] Specifically, Scalable Vector Graphics (SVG) is a graphic format based on Extensible Markup Language for describing two-dimensional vector graphics. When parsing the text to be converted into an HTML document, if there are markdown extensions (such as formulas and Mermaid drawing extensions) in the text to be converted, the markdown extensions (such as formulas and Mermaid drawing extensions) will be parsed into SVG.

[0130] In a specific implementation, the target tag for marking the container of the scalable vector graphics may be <svg>Tags can be used to search and replace the combination of HTML text <svg>Tags, if found <svg>tag, then the following steps S603 to S607 can be executed; otherwise, if no tag is found <svg>tag, the following step S609 can be executed.

[0131] S603: When the target tag is found, call the first rendering component to convert the text content of the target tag into content in a target format.

[0132] The first rendering component may be capable of <svg>The content of the tag is converted into a rendering component in PDF format or image format. Exemplarily, the first rendering component can be an SVG Rasterizer, which supports converting SVG text to PDF or images through the command line. SVG Rasterizer is a utility that can convert SVG files to raster formats. The tool can convert a single file or a set of files, so as to easily convert an entire directory of SVG files. The formats provided are JPEG, PNG and TIFF.

[0133] S605, replace the target tag with the corresponding text in the hypertext markup language text after replacement, and replace it with the content in the target format to obtain an intermediate text conversion result.

[0134] Specifically, after the SVG text is converted into the content of the target format, the content of the target format may be inserted into the corresponding position of the replaced HTML text, thereby obtaining the intermediate text conversion result.

[0135] S607, calling the second rendering component to convert the intermediate text conversion result into a target format, and obtaining a text conversion result corresponding to the text to be converted.

[0136] S609, calling the second rendering component to convert the replaced combined hypertext markup language text into a target format, and obtaining a text conversion result corresponding to the text to be converted.

[0137] Specifically, when the target format is PDF format, the second rendering component may be wkhtmltopdf, and when the target format is image format, the rendering component may be wkhtmltoimage. Of course, other rendering components that can be converted to the target format may also be used, such as Chrome headless component and open source component html-docx-js.

[0138] The above implementation method achieves consistency between the HTML structure, CSS and SVG in the final text conversion result and the text to be converted viewed on the browser through steps S601 to S609, further ensuring consistency between the converted content and the content viewed through the browser.

[0139] In some exemplary implementations, the conversion request of the aforementioned step S301 may include custom content. For example, when a user needs to add a watermark to the text conversion result, the content of the watermark (such as the company name) may be specified when initiating a conversion instruction for the text to be converted to the target format. Then, when the terminal generates a conversion request based on the conversion instruction, the content of the watermark may be carried as custom content, so that the server may extract the custom content from the conversion request. Based on this, the aforementioned step S303 may include:

[0140] The hypertext markup language document and the custom content are both used as main content, and combined with a preset standard hypertext markup language template to obtain a combined hypertext markup language text;

[0141] The cascading style sheet of the preset standard hypertext markup language template link includes cascading style information corresponding to the hypertext markup language document and cascading style information corresponding to the custom content.

[0142] In a specific implementation, the cascading style information corresponding to the HTML document in the standard HTML template can be linked through the link tag, and the cascading style information corresponding to the custom content can be implemented by setting the inline style, that is, setting the CSS style of the watermark in the style attribute inside the element tag.

[0143] Exemplarily, the strings ${markwon_dom_tree} and ${extra_dom_tree_before} can be set in the tag of the standard hypertext markup language template. During combination, based on string matching, the string ${markwon_dom_tree} is replaced with the hypertext markup language document of the text to be converted, and the string ${extra_dom_tree_before} is replaced with custom content such as a company name. In this way, the content with custom content such as a watermark can be written into the combined hypertext markup language text, so that the final converted text conversion result contains the custom content.

[0144] The above implementation method can realize that the converted HTML and CSS can expand the exported content (such as exporting watermarks and corporate logos) by adding additional content, so as to achieve the purpose of user-defined exported content and improve the flexibility of text conversion.

[0145] In some specific implementations, after obtaining the text conversion result of the text to be converted, the server may send the text conversion result to the terminal, and the terminal may store the text conversion result to realize the export of the Markdown source document.

[0146] In a specific implementation, the manner in which the server sends the text conversion result of the text to be converted to the terminal can be set based on the needs of actual applications. For example, when converting a single Markdown source document, the corresponding text conversion result can be directly returned to the terminal after obtaining the text conversion result of the Markdown source document; and when batch converting multiple Markdown source documents, after obtaining the text conversion result of each Markdown source document based on the aforementioned steps S301 to S307 for each Markdown source document, the text conversion results of the multiple Markdown source documents are compressed to obtain a compressed file, and then the compressed file is sent to the corresponding mailbox via the email address pre-registered by the terminal user, and when the sending is successful, an email reminder message is sent to the terminal user to remind the completion of the batch conversion, thereby improving the user experience.

[0147] In actual applications, considering that the content of the Markdown source document comes from user input, illegal users can use Markdown syntax to transform the content containing the server file path, resulting in the file content in the background server being exported when the text is converted. In addition, in some cases, the content of the Markdown source document contains executable code such as javascript, which may cause code injection problems. In order to improve the security of text conversion in the embodiments of this application, in some exemplary implementations, such as Figure 7 As shown, after obtaining the combined hypertext markup language text based on the aforementioned step S303, the method may further include:

[0148] S701, traverse the tags in the combined hypertext markup language text, and for the current tag traversed, if the current tag has a resource attribute, obtain the attribute value of the resource attribute.

[0149] Among them, the resource attribute may be a src attribute.

[0150] S703, when the attribute value of the resource attribute is a third-party resource path, download the resource file corresponding to the third-party resource path to the local storage space, and replace the attribute value of the resource attribute with the local storage path of the corresponding resource file.

[0151] The third-party resource path refers to an external resource path that needs to be accessed through the network.

[0152] In a specific implementation, if the attribute value of a resource attribute points to multiple resource files, multiple threads can be used to download the resource files in parallel, thereby facilitating improving the efficiency of text conversion.

[0153] In some possible implementations, in order to avoid errors in the export results, after replacing the attribute value of the resource attribute with the local storage path of the corresponding resource file, such as Figure 7 As shown, the method may also include:

[0154] S7031, determine the resource type of the resource file corresponding to the resource attribute.

[0155] Among them, resource types may include video, audio, etc.

[0156] S7033, determine whether the resource type of the resource file corresponding to the resource attribute matches the target format.

[0157] Specifically, if the resource type of the resource file corresponding to the resource attribute cannot be converted to the target format, it is considered that the resource type does not match the target format. Exemplarily, since the target format is either PDF or image, the resource type does not match the target format when it is video or audio.

[0158] When the judgment result is no, that is, the resource type of the resource file corresponding to the resource attribute does not match the target format, the following step S7035 can be executed; conversely, when the judgment result is yes, that is, the resource type of the resource file corresponding to the resource attribute matches the target format, it indicates that the resource file of this resource type can be converted to the target format without additional processing.

[0159] S7035, perform preset processing on the resource file corresponding to the resource attribute in the local storage space to obtain a processed resource, and the resource type of the processed resource matches the target format.

[0160] The specific processing method of the preset processing can be associated with the resource type of the resource text corresponding to the resource attribute. For example, when the resource type of the resource corresponding to the resource attribute is video, a frame (such as the first frame) of the video file can be intercepted, and then the resource file corresponding to the resource attribute in the local storage space is replaced with the frame image (i.e., the processed resource); when the resource type of the resource corresponding to the resource attribute is audio, the resource file corresponding to the resource attribute in the local storage space can be replaced with a preset image, and the preset image can be set based on actual needs.

[0161] S705, when the attribute value of the resource attribute is a local resource path, verify the attribute value based on a preset local resource path, and when the verification result indicates that the verification fails, replace the attribute value of the resource attribute with the preset local resource path.

[0162] Specifically, if the local resource path corresponding to the attribute value of the resource attribute is not the preset local resource path, it is determined that the verification fails, which may be an illegal export of the server text content. In the case of failure to pass the verification, the attribute value of the resource attribute is replaced with the preset local resource path, so that the content is exported to the preset safe file during subsequent conversion; on the contrary, if the local resource path corresponding to the attribute value of the resource attribute is the preset local resource path, it indicates that it is not an illegal export of the server file content, and there is no need to replace the attribute value of the resource attribute.

[0163] S707, when the attribute value of the resource attribute is the encoded content, if the encoded content is in an abnormal encoding format, the encoded content in the abnormal encoding format is processed into a corresponding normal image and stored in the local storage space, and the attribute value of the resource attribute is replaced with the local storage path of the above-mentioned normal image.

[0164] The abnormal encoding format refers to a format that cannot be converted into PDF and images. For example, the abnormal encoding format may be a base64 encoding format. If the attribute value of the resource attribute is a base64 encoding format content or an executable code such as javascript, the encoded content is considered to be a content of an abnormal encoding format.

[0165] Specifically, when the encoded content in the abnormal encoding format is processed into a corresponding normal picture, the encoded content is re-encoded to obtain the corresponding normal picture. If it cannot be re-encoded (such as executable code such as javascript), a preset picture can be used as its corresponding normal picture. The preset picture can be set based on actual needs.

[0166] The above implementation method executes the aforementioned steps S701 to S707 for each current tag traversed, thereby limiting the read folder to the preset local folder of the server during subsequent rendering, avoiding the problem of illegal users modifying the content containing the server file path through markdown syntax, resulting in the export of file contents in the background server. At the same time, the handling of exceptions can solve the problem of code injection, greatly improving the text conversion security of the embodiment of the present application.

[0167] Corresponding to the text conversion methods provided in the above-mentioned embodiments, the embodiment of the present application also provides a text conversion device. Since the text conversion device provided in the embodiment of the present application corresponds to the text conversion methods provided in the above-mentioned embodiments, the implementation methods of the aforementioned text conversion methods are also applicable to the text conversion device provided in this embodiment and will not be described in detail in this embodiment.

[0168] See also Figure 8 , which is a schematic diagram of the structure of a text conversion device provided in an embodiment of the present application, the device has the function of implementing the text conversion method in the above method embodiment, and the function can be implemented by hardware, or by hardware executing corresponding software. Figure 8 As shown, the text conversion device 800 may include:

[0169] The markup language document determination module 810 is used to determine the hypertext markup language document of the text to be converted in response to a conversion request indicating that the text to be converted is converted into a target format; the text to be converted is a text written based on the lightweight markup language Markdown, and the hypertext markup language document is obtained by parsing the text to be converted;

[0170] A combining module 820 is used to combine the hypertext markup language document as the main content with a preset standard hypertext markup language template to obtain a combined hypertext markup language text; the preset standard hypertext markup language template is linked to a cascading style sheet;

[0171] The cascading style processing module 830 is used to download the cascading style sheet linked to the combined hypertext markup language text to a local storage space, and replace the cascading style external link path in the combined hypertext markup language text based on the local storage path of the cascading style sheet to obtain the replaced combined hypertext markup language text;

[0172] The rendering module 840 is used to render the replaced combined hypertext markup language text based on the rendering component corresponding to the target format to obtain a text conversion result corresponding to the text to be converted.

[0173] In some exemplary embodiments, the apparatus further comprises:

[0174] A traversal module is used to traverse the tags in the combined hypertext markup language text, and for the current tag traversed, if the current tag has a resource attribute, obtain the attribute value of the resource attribute;

[0175] A first replacement processing module is used to download a resource file corresponding to the third-party resource path to the local storage space when the attribute value is a third-party resource path, and replace the attribute value with the local storage path of the resource file;

[0176] A second replacement processing module is used to verify the attribute value based on a preset local resource path when the attribute value is a local resource path, and replace the attribute value with the preset local resource path when the verification result indicates that the verification fails;

[0177] The third replacement processing module is used to, when the attribute value is the encoded content, if the encoded content is in an abnormal encoding format, process the encoded content in the abnormal encoding format into a corresponding normal image and store it in the local storage space, and replace the attribute value with the local storage path of the normal image.

[0178] In some exemplary embodiments, after replacing the attribute value with the local storage path of the resource file, the first replacement processing module is also used to: determine the resource type of the resource file; if the resource type does not match the target format, perform preset processing on the resource file in the local storage space to obtain a processed resource; the resource type of the processed resource matches the target format.

[0179] In some exemplary embodiments, the rendering module 840 includes:

[0180] A search module is used to search for a target tag in the replaced combined hypertext markup language text; the target tag is used to mark a container of a scalable vector graphic;

[0181] A first rendering submodule is used to call a first rendering component to convert the text content of the target tag into content in the target format when the target tag is found;

[0182] A content replacement module, used for replacing the target tag with the corresponding text in the hypertext markup language text after the replacement, and obtaining an intermediate text conversion result;

[0183] The second rendering submodule is used to call the second rendering component to convert the intermediate text conversion result into the target format to obtain a text conversion result corresponding to the text to be converted.

[0184] In some exemplary embodiments, the markup language document determination module 810 is specifically used to: obtain a conversion request indicating that the text to be converted is converted into a target format, and the conversion request carries the text to be converted; extract the text to be converted in the conversion request, and parse the text to be converted into the hypertext markup language document; or, obtain a conversion request indicating that the text to be converted is converted into a target format, and the conversion request carries a hypertext markup language document of the text to be converted, and the hypertext markup language document is obtained by parsing the text to be converted when the client displays the text to be converted based on the browser; extract the hypertext markup language document from the conversion request.

[0185] In some exemplary embodiments, the markup language document determination module 810 includes a parsing module, and the parsing module includes:

[0186] A first text segmentation module is used to determine the total length of the text to be converted. If the total length of the text to be converted is greater than a preset text length, the text to be converted is segmented based on the first-level title to obtain a first-level segmented text sequence;

[0187] The second text segmentation module is used to take the first-level segmented text sequence as the current text sequence, and if there is a target text with a total text length greater than the preset text length in the current text sequence, and there is a next-level title in the target text, then the target text is segmented based on the next-level title to obtain a segmented text sequence corresponding to the next level;

[0188] A recursive execution module, used for recursively executing the segmented text sequence corresponding to the next level as the current text sequence, until the current text sequence satisfies a preset stop condition, thereby obtaining a segmented text sequence of a target level; the preset stop condition includes that the total text length of each text in the current text sequence is less than the preset text length, or the target level is a preset title level;

[0189] A parsing submodule, used for parsing each segmented text in the segmented text sequence of the target level into a hypertext markup language fragment;

[0190] The markup language fragment combination module is used to combine the hypertext markup language fragments corresponding to each segmented text based on the sorting rule of each segmented text in the segmented text sequence of the target level to obtain the hypertext markup language document.

[0191] In some exemplary embodiments, the parsing submodule includes:

[0192] A parsing instruction generation module, used for generating a parsing instruction corresponding to each segmented text based on each segmented text in the segmented text sequence of the target level;

[0193] The parallel calling module is used to perform Markdown parsing service calls in parallel based on the parsing instructions corresponding to each of the segmented texts, so as to obtain the hypertext markup language fragments corresponding to each of the segmented texts.

[0194] In some exemplary embodiments, the parallel calling module includes:

[0195] A parsing engine matching module is used to determine, for each of the segmented texts, a Markdown parsing engine that matches the segmented text based on the Markdown syntax in the segmented text;

[0196] The parallel calling submodule is used to call the Markdown parsing engines respectively matched by each segmented text in parallel based on the parsing instructions corresponding to each segmented text, so as to obtain the hypertext markup language fragments corresponding to each segmented text.

[0197] In some exemplary embodiments, when the conversion request includes custom content, the combination module 820 is specifically used to: combine the hypertext markup language document and the custom content as body content with a preset standard hypertext markup language template to obtain a combined hypertext markup language text;

[0198] The cascading style sheet of the preset standard hypertext markup language template link includes cascading style information corresponding to the hypertext markup language document and cascading style information corresponding to the custom content.

[0199] It should be noted that the device provided in the above embodiment, when implementing its functions, is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.

[0200] An embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement any one of the text conversion methods provided in the above method embodiments.

[0201] The memory can be used to store software programs and modules. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, application programs required for functions, etc.; the data storage area can store data created according to the use of the device, etc. In addition, the memory can include a high-speed random access memory and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory can also include a memory controller to provide the processor with access to the memory.

[0202] The method embodiments provided in the embodiments of the present application may be executed in a computer terminal, a server or a similar computing device, that is, the above-mentioned electronic device may include a computer terminal, a server or a similar computing device. Fig. 9 is a hardware structure block diagram of an electronic device running a text conversion method provided in an embodiment of the present application, such as Fig. 9 As shown, the server 900 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 910 (the processor 910 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 930 for storing data, and one or more storage media 920 (such as one or more mass storage devices) for storing application programs 923 or data 922. Among them, the memory 930 and the storage medium 920 can be short-term storage or permanent storage. The program stored in the storage medium 920 may include one or more modules, each of which may include a series of instruction operations on the server. Furthermore, the central processing unit 910 can be configured to communicate with the storage medium 920 and execute a series of instruction operations in the storage medium 920 on the server 900. The server 900 may also include one or more power supplies 960, one or more wired or wireless network interfaces 950, one or more input and output interfaces 940, and / or one or more operating systems 921, such as Windows Server TM, Mac OS X TM, Unix TM, Linux TM, FreeBSD TM, etc.

[0203] The input / output interface 940 may be used to receive or send data via a network. The specific example of the network may include a wireless network provided by a communication provider of the server 900. In one example, the input / output interface 940 includes a network adapter (Network Interface Controller, NIC), which may be connected to other network devices via a base station so as to communicate with the Internet. In one example, the input / output interface 940 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0204] It can be understood by those skilled in the art that Fig. 9 The structure shown is only for illustration and does not limit the structure of the above electronic device. Fig. 9 More or fewer components as shown, or with Fig. 9 Different configurations are shown.

[0205] An embodiment of the present application also provides a computer-readable storage medium, which can be set in an electronic device to store at least one instruction or at least one program related to implementing a text conversion method. The at least one instruction or the at least one program is loaded and executed by the processor to implement any text conversion method provided by the above method embodiments.

[0206] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the electronic device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the electronic device performs any one of the text conversion methods provided in the above method embodiments.

[0207] Optionally, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.

[0208] It should be noted that the above-mentioned sequence of the embodiments of the present application is for description only and does not represent the advantages and disadvantages of the embodiments. The above-mentioned specific embodiments of this specification are described. Other embodiments are within the scope of the attached claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0209] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0210] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.

[0211] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.< / svg> < / svg> < / svg> < / svg> < / svg>

Claims

1. A text conversion method, It is characterized in that The method comprises: In response to a conversion request indicating that a text to be converted is to be converted into a target format, determining a hypertext markup language document of the text to be converted; the text to be converted is a text written based on a lightweight markup language Markdown, and the hypertext markup language document is obtained by parsing the text to be converted; The hypertext markup language document is used as the main content and combined with a preset standard hypertext markup language template to obtain a combined hypertext markup language text; the preset standard hypertext markup language template is linked to a cascading style sheet; Downloading the cascading style sheet of the combined hypertext markup language text link to a local storage space, and replacing the cascading style external link path in the combined hypertext markup language text based on the local storage path of the cascading style sheet to obtain a replaced combined hypertext markup language text; Based on the rendering component corresponding to the target format, the replaced combined hypertext markup language text is rendered to obtain a text conversion result corresponding to the text to be converted.

2. The method according to claim 1, It is characterized in that After obtaining the combined hypertext markup language text, the method further comprises: Traversing the tags in the combined hypertext markup language text, and for the traversed current tag, if the current tag has a resource attribute, obtaining the attribute value of the resource attribute; When the attribute value is a third-party resource path, downloading a resource file corresponding to the third-party resource path to the local storage space, and replacing the attribute value with the local storage path of the resource file; In the case where the attribute value is a local resource path, verifying the attribute value based on a preset local resource path, and when a result of the verification indicates that the verification fails, replacing the attribute value with the preset local resource path; In the case where the attribute value is the encoded content, if the encoded content is in an abnormal encoding format, the encoded content in the abnormal encoding format is processed into a corresponding normal image and stored in the local storage space, and the attribute value is replaced with the local storage path of the normal image.

3. The method according to claim 2, It is characterized in that After replacing the attribute value with the local storage path of the resource file, the method further includes: Determine the resource type of the resource file; In the case that the resource type does not match the target format, the resource file in the local storage space is processed in a preset manner to obtain a processed resource; the resource type of the processed resource matches the target format.

4. The method according to any one of claims 1 to 3, It is characterized in that The rendering component corresponding to the target format is used to render the replaced combined hypertext markup language text, including: Searching for a target tag on the replaced combined hypertext markup language text; the target tag is used to mark a container of a scalable vector graphics; In the case where the target tag is found, calling the first rendering component to convert the text content of the target tag into content in the target format; The target tag is combined with the corresponding text in the hypertext markup language text after the replacement, and replaced with the content in the target format to obtain an intermediate text conversion result; The second rendering component is called to convert the intermediate text conversion result into the target format to obtain a text conversion result corresponding to the text to be converted.

5. The method according to claim 1, It is characterized in that The step of determining a hypertext markup language document of the text to be converted in response to a conversion request to convert the text to be converted into a target format comprises: Obtaining a conversion request instructing to convert the text to be converted into a target format, wherein the conversion request carries the text to be converted; extracting the text to be converted in the conversion request, and parsing the text to be converted into the hypertext markup language document; or, Obtaining a conversion request instructing to convert the text to be converted into a target format, wherein the conversion request carries a hypertext markup language document of the text to be converted, and the hypertext markup language document is obtained by parsing the text to be converted when the client displays the text to be converted based on a browser; The hypertext markup language document is extracted from the conversion request.

6. The method according to claim 5, It is characterized in that The step of parsing the text to be converted into the hypertext markup language document comprises: Determine the total length of the text to be converted, and if the total length of the text to be converted is greater than a preset text length, segment the text to be converted based on the first-level title to obtain a first-level segmented text sequence; The first-level segmented text sequence is used as the current text sequence. If there is a target text whose total text length is greater than the preset text length in the current text sequence, and there is a next-level title in the target text, the target text is segmented based on the next-level title to obtain a segmented text sequence corresponding to the next level; The segmented text sequence corresponding to the next level is used as the current text sequence for recursive execution until the current text sequence meets a preset stop condition, thereby obtaining a segmented text sequence of a target level; the preset stop condition includes that the total text length of each text in the current text sequence is less than the preset text length, or the target level is a preset title level; Parsing each segmented text in the segmented text sequence of the target level into a hypertext markup language segment; Based on the sorting rule of each of the segmented texts in the segmented text sequence at the target level, the hypertext markup language fragments corresponding to each of the segmented texts are combined to obtain the hypertext markup language document.

7. The method according to claim 6, It is characterized in that The step of parsing each segmented text in the segmented text sequence at the target level into a hypertext markup language segment comprises: Based on each segmented text in the segmented text sequence of the target level, generating a parsing instruction corresponding to each segmented text; Based on the parsing instructions corresponding to each of the segmented texts, Markdown parsing service calls are performed in parallel to obtain hypertext markup language fragments corresponding to each of the segmented texts.

8. The method according to claim 7, It is characterized in that The Markdown parsing service call is performed in parallel based on the parsing instructions corresponding to each of the segmented texts to obtain a hypertext markup language fragment corresponding to each of the segmented texts, including: For each of the segmented texts, based on the Markdown syntax in the segmented texts, determining a Markdown parsing engine that matches the segmented texts; Based on the parsing instructions corresponding to the segmented texts, the Markdown parsing engines respectively matched to the segmented texts are called in parallel to obtain the hypertext markup language fragments corresponding to the segmented texts.

9. The method according to claim 1, It is characterized in that When the conversion request includes custom content, the hypertext markup language document is used as the main content and combined with a preset standard hypertext markup language template to obtain a combined hypertext markup language text, including: The hypertext markup language document and the custom content are both used as main content, and combined with a preset standard hypertext markup language template to obtain a combined hypertext markup language text; The cascading style sheet of the preset standard hypertext markup language template link includes cascading style information corresponding to the hypertext markup language document and cascading style information corresponding to the custom content.

10. A text conversion device, It is characterized in that The device comprises: A markup language document determination module is used to determine a hypertext markup language document of the text to be converted in response to a conversion request indicating that the text to be converted is converted into a target format; the text to be converted is a text written based on the lightweight markup language Markdown, and the hypertext markup language document is obtained by parsing the text to be converted; A combination module, used to combine the hypertext markup language document as the main content with a preset standard hypertext markup language template to obtain a combined hypertext markup language text; the preset standard hypertext markup language template is linked to a cascading style sheet; A cascading style processing module, used for downloading the cascading style sheet of the combined hypertext markup language text link to a local storage space, and replacing the cascading style external link path in the combined hypertext markup language text based on the local storage path of the cascading style sheet, to obtain the replaced combined hypertext markup language text; The rendering module is used to render the replaced combined hypertext markup language text based on the rendering component corresponding to the target format to obtain a text conversion result corresponding to the text to be converted.

11. An electronic device, It is characterized in that The method comprises a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the text conversion method according to any one of claims 1 to 9.

12. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by a processor to implement the text conversion method according to any one of claims 1 to 9.

13. A computer program, It is characterized in that When the computer program is executed by a processor, the text conversion method according to any one of claims 1 to 9 is implemented.

Citation Information

Cited By

  • Data rendering method, related device and computer program product

    CN120874812A

  • Data rendering method, related devices and computer program product

    CN120874812B

  • A stream data incremental parsing and rendering method, electronic equipment and computer program product

    CN122797527A