Document content analysis method and device based on structural analysis and program product
Through a multi-stage modular parsing pipeline, in-depth contextual analysis of DOCX documents is performed, which solves the information loss and resource efficiency bottleneck problems of complex document parsing in existing technologies, and achieves efficient and accurate document structure reconstruction and content restoration.
Patent Information
- Application Number
- CN202511287239.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-09
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2045-09-09
AI Technical Summary
Existing document parsing technologies face problems such as information loss, formatting errors, and structural dimensionality reduction when processing complex DOCX documents. Shallow parsing tools cannot correctly restore complex structures, visual recognition methods are information-lossy and costly, and heavy AI models face serious resource and efficiency bottlenecks.
A multi-stage, modular parsing pipeline is adopted to perform deep context-aware analysis of DOCX documents directly through style and number pre-parsing, master control traversal and distribution, specialized content parsing and embedded resource processing, build a logical matrix to reconstruct the table structure, and use a state machine to maintain list context continuity.
It achieves high-fidelity, high-efficiency, and low-resource-consumption document structured conversion, can accurately parse complex elements, and generate Markdown documents with clear structure and complete content, providing a high-quality data foundation for downstream applications.
Smart Images

Figure CN120805892A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of document intelligent processing, and particularly relates to a document content analysis method and device based on structure analysis and a program product. BACKGROUND
[0002] Electronic documents have become the core medium of knowledge bearing, information exchange and business process. Among them, word processing documents represented by the DOCX format of Microsoft Word are widely used in writing technical reports, drafting legal contracts, compiling product manuals, generating experimental data records and many other professional fields due to their powerful content editing, complex layout design and rich formatting capabilities. These documents not only contain pure text information, but also carry rich structured information and logical relationships through the complex combination of various elements such as tables, lists, directories and charts. Therefore, realizing the automatic, accurate and efficient content extraction and structured conversion of massive DOCX documents has become an indispensable key technical prerequisite for realizing intelligent data mining, driving robot process automation (RPA), developing advanced question and answer systems and building intelligent agents and other downstream applications.
[0003] As an open format based on the OOXML international standard, the DOCX format is essentially a ZIP compressed file containing multiple XML files and resources. All information of the document, including text content, style definition, numbering rules, media resource relationship, etc., is stored in these XML files in a structured manner. In theory, by accurately analyzing these XML files, the entire content and structure of the document can be restored without loss. However, the existing document analysis technology has the following problems when dealing with real-world documents that are complex in structure and full of ambiguities, which are edited by human users through a graphical interface:
[0004] The mainstream direct parsing tools based on standard libraries are often limited to the extraction of shallow or idealized structures. These tools can effectively iterate through paragraphs and tables in a document and extract pure text content. However, their limitations are more pronounced when faced with complex document structures. For example, merged cells that span multiple columns (gridSpan) or rows (vMerge) in a table disrupt the regular matrix structure, and simple row traversal cannot correctly restore the logical dependencies between cells. In some special cases, new tables are nested inside cells, forming a recursive structure that traditional parsers struggle to handle. For numbered lists, context-dependent multi-level numbering (e.g., "1." -> "1.1" -> "a)") depends on a context state that changes dynamically in the document flow. The insertion of any ordinary paragraph or table can disrupt and reset this state, causing the parsed numbered list to lose its correct hierarchy and sequence. For tables of contents (TOC), the generation mechanism is diverse, and they can be dynamically generated by special field codes or composed of ordinary paragraphs with specific styles. Simple text extraction will confuse them with the main text and lose their meta-information as navigation structures. These problems collectively result in the existing shallow parsing tools losing information, format errors, and structure dimension reduction when processing complex documents.
[0005] To avoid the complexity of underlying XML structure parsing, some technical solutions turn to a visual recognition-based technical path, such as optical character recognition (OCR) or document layout analysis combined with computer vision (CV). This method first renders the document page as an image and then extracts text and infers layout through image processing and pattern recognition techniques. Although this method is necessary when dealing with scanned documents without source data, it has fundamental flaws when applied to DOCX documents with source data. First, the information loss in the conversion process: the fidelity of the document's metadata, vector graphics, text hyperlinks, and invisible formatting information (such as style definitions) is completely discarded during rendering. Second, the high processing cost and low efficiency: document rendering, image processing, and OCR recognition are computationally intensive tasks that are difficult to meet the needs of large-scale, real-time enterprise applications. Third, the accuracy of this method is severely limited by the complexity of the layout. For tightly typeset tables with many lines, or pages with multi-column layouts and mixed text and graphics, the error rate of OCR recognition will increase significantly. In addition, this visual inference-based method lacks determinism, and its results are difficult to reproduce and explain stably.
[0006] With the development of artificial intelligence technology, the method of using large language models (LLM) or multi-modal models to "understand" document content has gradually emerged. These models have certain document structure understanding and information extraction capabilities through pre-training on massive data. However, applying such heavy AI models to general document parsing tasks also faces resource and efficiency bottlenecks. The training and inference process of the model requires powerful computing resources (such as high-performance GPU clusters), resulting in high operating costs. At the same time, limited by the context window length, when processing long documents, complex text segmentation and context management are required, which not only increases the processing delay, but also may affect the global consistency of the parsing due to information fragmentation. In addition, the "black box" characteristics and probabilistic output of the model make it difficult to fully guarantee the stability and explainability of its results in structured conversion tasks that require 100% accurate restoration.
[0007] In summary, there is an urgent need for a technical solution that can avoid the loss of information in shallow parsing, while overcoming the resource and efficiency bottlenecks of visual recognition and heavy AI models. The ideal solution should be: instead of relying on image rendering, it analyzes the underlying OpenXML structure of DOCX documents in a deep and context-aware manner, so that it can accurately parse and reconstruct the content and structure of documents containing various complex elements in a lightweight, efficient, and high-fidelity deterministic manner. SUMMARY
[0008] In view of the deficiencies of the prior art, the present application proposes a document content parsing method, device and program product based on structure analysis, which realizes high-precision, high-efficiency and low-resource-consumption structured conversion of complex documents, especially suitable for high-fidelity content extraction and structure reconstruction of word processing documents (such as DOCX format) using Office Open XML (OOXML) standard, especially for handling complex structured and semi-structured elements such as multi-level lists, nested and merged tables, and dynamically generated tables of contents, etc.
[0009] The document content analysis method provided by the application constructs a multi-stage and modular analysis pipeline, decomposes the complex document analysis task into a series of defined and cooperative processing units. First, the style and numbering pre-analysis module is used to pre-load and model the global formatting rules of the document, establish the knowledge of the document "syntax"; then, the main control traversal and distribution module distributes the content blocks (such as paragraphs, tables) to the corresponding specialized parser according to the natural flow order of the document; the specialized content analysis module, as the core of the application, is composed of multiple sub-modules (including directory analysis, paragraph and list processing, complex table analysis, etc.), responsible for in-depth analysis and conversion of specific content based on context; finally, the embedded resource processing module and the post-processing and optimization module cooperate to complete the decoupling of binary resources and the final normalization of output text.
[0010] In a first aspect, the application provides a document content analysis method based on structural analysis, comprising the following steps:
[0011] S1: Numbering pre-analysis and style pre-analysis are performed on the XML document to extract the global structure and formatting rules of the document;
[0012] S2: The main document file of the XML document is processed, the content body is serialized and traversed, the block-level elements are read one by one according to the natural order defined in the XML document, the elements are type judged through the XML tags of the elements, and then the elements are distributed to the corresponding specialized analysis sub-modules;
[0013] S3: The specialized content analysis sub-modules are used to perform in-depth analysis and structural reconstruction on the directory, paragraph, list and table in the XML document, respectively, to generate a Markdown format document;
[0014] S4: During the entire analysis process, the XML document is processed synchronously.
[0015] As a further improvement of the application, the method further comprises step S5: post-processing and optimization; specifically including:
[0016] The post-processing and optimization module scans the Markdown format document and identifies the table part, temporarily converts the table back to a two-dimensional data structure, and performs structural analysis and optimization to remove columns with empty content and duplicate content in the table, and generates a more compact Markdown table.
[0017] As a further improvement of the application, the numbering pre-analysis in step S1 specifically includes:
[0018] By parsing the numbering definition file in the XML document, a mapping relationship between each list instance ID in the document and the abstract template ID it references is constructed;
[0019] The abstract template includes: formatting rules of all levels extracted from the abstract list template, specifically including: numbering format, indentation, prefix and suffix.
[0020] As a further improvement of the application, the style pre-parsing in step S1 includes the following specific steps:
[0021] By parsing the style definition file in the XML document, all paragraphs and character styles in the document are traversed;
[0022] For styles with embedded numbering attributes, the associated list instance ID is extracted, and a mapping relationship from style name to abstract template definition is established.
[0023] As a further improvement of the application, the processing step of the document table of contents in step S3 includes:
[0024] The table of contents is identified by detecting directory-specific string styles or directory field codes;
[0025] The table of contents is extracted using an XPath-based content extractor;
[0026] The table of contents is analyzed, the hierarchy of table of contents entries is restored, and the hierarchy is represented in the form of indentation.
[0027] As a further improvement of the application, the specific steps of extracting the table of contents include:
[0028] By using a specific path expression, the extractor accurately locates and extracts all text nodes inside the hyperlink tag that serves as the table of contents title, and filters out non-content parts including page numbers and leading symbols.
[0029] As a further improvement of the application, in step S3, the way to process paragraphs and lists is to maintain a global list context using a state machine, and the specific steps include:
[0030] For paragraphs with numbering attributes, the formatting rules are obtained through the pre-parsing results of step S1, and the state of the list context is updated accordingly, and the Markdown list prefix is generated;
[0031] When a paragraph without numbering attributes is encountered, the list context is reset, and the current list count is ended;
[0032] When a paragraph belonging to the same list is encountered again, the correct numbering sequence is restored.
[0033] As a further improvement of the present application, the list context is a data structure for tracking the state of the list currently being processed in real time, which includes the list instance ID of the current list, the current level depth and the counter of each level.
[0034] As a further improvement of the present application, the updating of the state of the list context includes updating by the counter, and the specific updating methods include:
[0035] Initializing the counter for a new list;
[0036] Increasing the level depth and resetting the lower-level counter for the next-level list;
[0037] Incrementing the current counter for the same-level list.
[0038] As a further improvement of the present application, the processing of the table in step S3 includes:
[0039] Calculating the exact total number of columns of the table by accumulating the horizontal span attribute values of each cell through a single fast traversal;
[0040] Creating a two-dimensional logical matrix in memory that is completely consistent with the visual layout of the table;
[0041] Processing the object reference relationship of the horizontally and vertically merged cells through two scans of the two-dimensional logical matrix, i.e., row-by-row scanning and column-by-column scanning;
[0042] Filling the two-dimensional logical matrix after the two scans with the table content to generate a Markdown-formatted table.
[0043] As a further improvement of the present application, the specific steps of the two scans include:
[0044] In the row-by-row scanning, the processing method for the horizontally merged cell spanning multiple columns is to place the object reference of the cell in the leftmost starting position of the cell, and keep the subsequent positions covered by the cell empty;
[0045] In the column-by-column scanning, the processing method for the vertically merged cell spanning multiple rows is to use the object reference of the topmost starting position of the cell to cover the merged positions below.
[0046] As a further improvement of the present application, the specific steps of the embedded resource processing in step S4 include:
[0047] When an embedded resource object is detected in the XML structure of a paragraph, extracting its relationship ID;
[0048] The corresponding binary file is found in the media component of the XML document through the ID;
[0049] The file is decoupled, saved locally, and a unique UUID file name is generated;
[0050] In the Markdown format document, a resource object reference link pointing to the local file is inserted;
[0051] The resource object includes a graphic object.
[0052] In a second aspect, the present application provides a computer device comprising a memory, a processor and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of the method of the first aspect.
[0053] In a third aspect, the present application provides a computer readable storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to implement the steps of the method of the first aspect.
[0054] In a fourth aspect, the present application provides a computer program product, wherein the computer program is executed by a processor to implement the steps of the method of the first aspect.
[0055] The technical effect of the method of the present application is that: without relying on visual rendering or probabilistic models, but by directly logically reconstructing the underlying data structure of the document, especially by introducing a logic matrix to restore the complex table structure, and by using a state machine to maintain the context continuity of the list, the accurate restoration of complex elements is achieved. The present application has the advantages of high fidelity, high efficiency, low resource consumption and strong adaptability, and can provide high-quality and reliable structured data basis for various downstream applications. BRIEF DESCRIPTION OF DRAWINGS
[0056] Figure 1 A flowchart of a document content parsing method disclosed by the present application is shown.
[0057] Figure 2 A schematic diagram of a sub-module in the document content parsing method is shown. DETAILED DESCRIPTION
[0058] In order to make the purposes, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the drawings. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments of the present application, wherein the steps S1, S2, … in the described embodiments of the present application do not limit the only execution steps of the present application; and various models, simulation environments and software described in the present application are not the only limited ways of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.
[0059] In the present application, the computer device / system refers to the related entities applied to the computer, such as hardware, combination of hardware and software, software or software in execution, etc. In detail, for example, the software includes but is not limited to the process running on the processor, the processor, the object, the executable software, the execution thread, the program and / or the computer. In addition, the application program or the script program running on the server or the server can be the software. One or more software can be in the process and / or thread of execution, and the software can be localized on one computer and / or distributed between two or more computers, and can be run by various computer readable media.
[0060] It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.
[0061] In a first aspect, the present application provides a document content analysis method based on structural analysis, the overall process of which can be summarized as an automatic analysis pipeline composed of multiple modules working cooperatively. As shown in the figure, the specific process can be as follows: Figure 1
[0062] S1: Use the pre-analysis module to perform style and numbering pre-analysis;
[0063] Before any actual processing of the main content of the document, the pre-analysis module is first started. The goal of this module is to “pre-read” and understand the global formatting conventions of the document, and to establish a rule model in memory for subsequent context-aware analysis. This module loads and analyzes the core configuration file in the DOCX compressed package, mainly performing two key tasks:
[0064] S11: Through numbering definition file (word / numbering.xml) analysis, a complete multi-level list definition model is constructed; in the OOXML standard, this XML file is the center of defining the format of all automatically numbered lists in the document. The pre-analysis module will systematically traverse two types of core elements in this file: abstract list template (abstractNum) <w:abstractnum>) and specific list examples ( <w:num>).
[0065] For each abstract list template, extract all its levels ( <w:lvl>The formatting rules of the list instance, including numbering format (number, letter, bullet), indentation, prefix and suffix, etc., are associated with its unique abstract template ID (w:abstractNumId).
[0066] For each concrete list instance, the mapping between its list instance ID (w:numId) and the referenced abstract template ID is established.
[0067] Through this process, the complete multi-level list definition model is constructed, so that in subsequent processing, any list item can be found through its list instance ID (w:numId) to find its complete formatting rules.
[0068] S12: Style definition file (word / styles.xml) parsing: The style definition file defines all the paragraph and character styles visible to the user in the document. The parser will traverse all the paragraph styles defined in the file ( <w:style>), and focus on those that have the number attribute embedded ( <w:numpr>) style. When such a style is detected, the parser extracts its associated list instance ID (numId), thus establishing an association map from the style name (e.g. "Heading 1") to the specific list definition.
[0069] This step greatly enhances the adaptability to different user editing habits by correctly handling numbered lists created by applying styles (rather than manual formatting).
[0070] The final output of the pre-parsing module is a structured model containing the global formatting rules of the document. This enables the subsequent parsers to "understand" the formatting conventions of the document, thus making correct, context-based parsing decisions.
[0071] S2: Master traversal and distribution using the master flow module;
[0072] After pre-parsing is complete, the master flow module starts the master traversal of the content body of the main document (word / document.xml) <w:body>) to perform a serialized traversal. This module functions as a smart dispatch center, reading block-level elements in the natural order defined by the document in XML. For each block-level element it reads, it determines the type of element by its XML tag and dispatches the element to the appropriate specialized parsing submodule for processing.
[0073] For example, when a paragraph element ( <w:p>) it passes it to the paragraph and list processing submodule; when it encounters a table element ( <w:tbl>) then it is passed to the complex table parsing submodule.
[0074] This distribution mechanism ensures that different types of elements are processed by the most suitable logical unit, achieving a high degree of modularity and scalability of the system.
[0075] S3: Deep parsing and structural reconstruction of the document using specialized content parsing submodules;
[0076] Specialized content parsing submodules are responsible for the deep parsing and structural reconstruction of specific content, including the use of multiple highly specialized submodules for processing:
[0077] S31: Table of Contents (TOC) parsing submodule: This module uses a flexible hybrid approach to identify and extract the table of contents.
[0078] It first checks if the paragraph has applied a dedicated style starting with the "TOC" string, which is the most common implementation of the table of contents in modern Word documents. At the same time, to be compatible with older or specially formatted documents, it also performs table of contents identification by detecting the presence of traditional table of contents field codes within the paragraph.
[0079] Once a paragraph is identified as a table of contents entry, the module will launch an XPath-based content extractor. XPath is a powerful language for querying nodes in XML documents. By designing specific path expressions, such as. / / w:hyperlink / / w:t, the extractor can accurately locate and extract hyperlinks as table of contents titles ( <w:hyperlink>All text nodes inside the tag, thus intelligently filtering out non-content parts such as page numbers generated by PAGEREF fields and leading tabs.
[0080] By analyzing the hierarchy of TOC styles (e.g. "TOC 1", "TOC 2"), restoring the hierarchy of the table of contents entries, and representing it in the final output with indentation.
[0081] S32: Paragraph and List Processing Submodule: This module is responsible for processing all regular paragraphs and multi-level lists that are not part of the table of contents or tables.
[0082] The core of this module is a state machine that maintains a global list context. This list context is a data structure that keeps track of the state of the list being processed, including the list instance ID (numId), the current level depth (ilvl), and a counter for each level.
[0083] When a paragraph with a numbered attribute is encountered, the module queries the numbering model established in the pre-processing phase to obtain its formatting rules and updates the list context accordingly (e.g. initializes the counter if it's a new list, increases the level depth and resets the lower level counter if it's a next level, or increments the current counter if it's the same level). Subsequently, it generates the correct Markdown list prefix based on the updated context. When a paragraph without a numbered attribute is encountered, the module resets the list context, marking the formal end of the list.
[0084] This state machine-based context management mechanism enables the parser to correctly handle lists interrupted by regular paragraphs or tables, and seamlessly resume the correct numbering sequence when subsequent paragraphs belonging to the same list are encountered, ensuring the logical continuity and accuracy of the list in the global scope.
[0085] S33: Complex Table Parsing Submodule: This module introduces the construction of a logical matrix and is responsible for parsing complex tables.
[0086] First, it calculates the exact total number of columns of the table by accumulating the gridSpan attribute values of each cell in a single pass. Then, it creates a two-dimensional logical matrix (cell_map) in memory that perfectly matches the visual layout of the table.
[0087] The module fills the matrix by a Two-Pass algorithm: the first pass scans the table by rows, handling hMerge. When a cell spanning multiple columns is encountered, the parser places the object reference of the cell at the start of the corresponding row in the matrix, and the subsequent positions are left empty, which accurately reflects the structure of hMerge. The second pass scans the table by columns, handling vMerge. The parser accurately reconstructs the vertical merge relationship of the table by covering the matrix entry of a lower merged cell with the object reference of the uppermost start cell of the merge.
[0088] In the content generation phase, the module accurately determines whether the current row is a continuation of the vertically merged cells by comparing the object references of the cells in the key columns of the matrix. Since all cells belonging to the same vertically merged region point to the same object after the second pass, this comparison based on object references fundamentally avoids the accumulation of errors in the list number within the merged region. In addition, the module can detect whether a cell contains a nested table by checking its content model when processing each cell, and recursively call itself to complete the complete parsing of any depth of nested tables, achieving comprehensive support for complex table layout.
[0089] S4: Embedded resource processing and post-processing;
[0090] In the entire parsing process, the embedded resource processing module works in a synchronous manner.
[0091] When the XML structure of a paragraph contains a nested table, the module will recursively call itself to parse the nested table. <w:r>detecting a graphical object (e.g., a <w:drawing>When it finds a reference to an image, it extracts its relationship ID (r:embed). This ID is a key to the document's relationship file (.rels). With this ID, it finds the corresponding binary image file in the document's media part. It decouples the file, saves it locally, and generates a unique UUID filename. Finally, it inserts a standard image reference link to this local file in the final Markdown text.
[0092] After all content conversion tasks are completed, an optional post-processing and optimization module can be started. This module is responsible for scanning the generated Markdown full text and identifying the table part in it. By temporarily converting the Markdown table back to a two-dimensional data structure, this module can perform structural analysis on the table and execute optimization operations, such as analyzing and removing redundant columns that are completely empty in all rows or columns that are completely duplicated with another column. Finally, it regenerates a more structurally optimal and compact Markdown table based on the cleaned data structure, thereby significantly improving the standardization and readability of the final output content.
[0093] Through the above steps, the method of the present application can efficiently and accurately convert Word documents containing various complex elements into Markdown format text with clear structure, complete content, and decoupled resources, providing a high-quality and reliable data foundation for downstream automated and intelligent applications.
[0094] In the second aspect, the present application provides a computer device embodiment, including a memory, a processor, and a computer program stored on the memory, wherein the processor executes the computer program to implement the steps of the method of the first aspect.
[0095] In the third aspect, the present application provides a computer-readable storage medium embodiment, which stores a computer program that, when executed by a processor, implements the steps of the method of the first aspect.
[0096] In the fourth aspect, the present application provides a computer program product embodiment, which, when executed by a processor, implements the steps of the method of the first aspect.< / w:drawing> < / w:r> < / w:hyperlink> < / w:tbl> < / w:p> < / w:body> < / w:numpr> < / w:style> < / w:lvl> < / w:num> < / w:abstractnum>
Claims
1. A document content parsing method based on structural analysis, characterized in that: The following steps are involved: S1: Perform number pre-parse and style pre-parse on XML documents to extract the global structure and formatting rules of the document; S2: Processes the main document file of the XML document, serializes and traverses the content body, reads the block-level elements one by one according to the natural order defined in the XML document, determines the type of the elements based on their XML tags, and then distributes the elements to the corresponding specialized parsing submodules; S3: Uses specialized content parsing submodules to perform in-depth parsing and structural reconstruction of the table of contents, paragraphs, lists, and tables in the XML document, generating a document in Markdown format. S4: During the entire parsing process, embedded resources are processed synchronously on the XML document.
2. The method according to claim 1, characterized in that The step S5 is also included: post-processing and optimization, which specifically includes: The post-processing and optimization module scans the Markdown format document and identifies the table part therein, temporarily converts the table back into a two-dimensional data structure, and performs structural analysis and optimization, removes columns with empty content and duplicate content in the table, and regenerates a Markdown table with a more compact structure.
3. The method according to claim 1, characterized in that The number pre-analysis in step S1 specifically includes the following steps: By parsing the number definition file in the XML document, a mapping relationship between each list instance ID in the document and the abstract template ID it references is constructed; The abstract template includes: formatting rules of all levels extracted from the abstract list template, including: numbering format, indentation, prefix and suffix.
4. The method according to claim 1, wherein The style pre-parsing in step S1 specifically includes the following steps: By parsing the style definition file in the XML document, it traverses all paragraph and character styles in the document; For styles with embedded number attributes, extract their associated list instance IDs and establish an association mapping from style names to abstract template definitions.
5. The method according to claim 1, wherein In step S3, the steps of processing the document directory include: Identify directories by detecting directory-specific string patterns or directory field codes; Extract directory contents using XPath-based content extractors; Analyzes the directory hierarchy, restores the hierarchical structure of directory entries, and reflects the hierarchy in indented form.
6. The method according to claim 5, characterized in that The specific steps of extracting the directory content include: Through specific path expressions, the extractor can accurately locate and extract all text nodes inside the hyperlink tags that serve as directory titles, filtering out non-content parts including page numbers and leading characters.
7. The method according to claim 1, characterized in that In step S3, the paragraphs and lists are processed by using a state machine to maintain a global list context. The specific steps include: For paragraphs with numbered attributes, obtain their formatting rules through the pre-parsing result of step S1, update the state of the list context accordingly, and generate a Markdown list prefix; When encountering a paragraph without a number attribute, the list context is reset and the current list count ends; When a paragraph belonging to the same list is encountered again, its correct numbering sequence is restored.
8. The method according to claim 7, characterized in that The list context is a data structure used to track the status of the currently processed list in real time. The data structure includes: the list instance ID of the current list, the current level depth, and a counter for each level.
9. The method according to claim 8, characterized in that The updating of the state of the list context includes updating through the counter, and the specific updating method includes: For the new list, initialize the counter; For the next level list, increase the level depth and reset the next level counter; For the sibling list, increment the current counter.
10. The method according to claim 1, characterized in that In step S3, the table is processed in the following manner: Through a quick traversal, the horizontal span attribute value of each cell is accumulated to calculate the exact total number of columns in the table; Create a two-dimensional logical matrix in memory that is exactly the same as the visual layout of the table; Scanning the two-dimensional logic matrix twice, i.e., scanning by row and scanning by column, and processing object reference relationships of horizontally merged and vertically merged cells; Fill the table content into the two-dimensional logic matrix that has been scanned twice and generate a table in Markdown format.
11. The method according to claim 10, characterized in that The specific steps of the two-pass scanning include: In row-by-row scanning, the horizontally merged cells across multiple columns are handled as follows: the object reference of the cell is placed at the leftmost starting position of the cell, and the subsequent positions covered by the cell remain empty; In column-by-column scanning, vertically merged cells across multiple rows are handled as follows: the object reference of the topmost starting position of the cell is used to overwrite the merged position below.
12. The method according to claim 1, characterized in that In step S4, the specific steps of performing embedded resource processing include: When an embedded resource object is detected in the XML structure of a paragraph, its relation ID is extracted; Use this ID to find the corresponding binary file in the media part of the XML document; Decouple the file, save it locally, generate a corresponding local file, and generate a unique UUID file name; Inserting a resource object reference link pointing to the local file into the Markdown format document; The resource object includes a graphic object.
13. A computer device comprising a memory, a processor, and a computer program stored in the memory, wherein: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 12.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 12 are implemented.
15. A computer program product, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 12 are implemented.
Citation Information
Patent Citations
Webpage content extracting method based on expectation list
CN103440294A
Method and system for converting Word file into EPUB file
CN110083805A
OOXML document entrainment detection method, storage medium and electronic equipment
CN116126349A
Document processing method and device based on rich text data, computer equipment, medium and product
CN119250036A
Document analysis and index construction method
CN119445603A