A document content analysis method, device and program product based on structural analysis
By employing a multi-stage modular parsing pipeline and deep context-aware technology, the problems of information loss and resource consumption in complex DOCX documents are solved, enabling efficient and accurate document structure reconstruction and data extraction.
Patent Information
- Application Number
- CN202511287239.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-09
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2045-09-09
AI Technical Summary
Existing technologies suffer from 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-destructive and costly, and heavy-duty AI models face severe resource and efficiency bottlenecks.
A multi-stage, modular document parsing pipeline is adopted. Through style and number pre-parsing, master traversal and distribution, specialized content parsing and embedded resource processing, it can achieve deep context-aware parsing of DOCX documents, construct a logical matrix to restore the table structure, and use a state machine to maintain the continuity of the list context.
It achieves high-fidelity, high-efficiency, and low-resource-consumption document structuring conversion, accurately restoring complex elements and providing a high-quality structured data foundation.
Smart Images

Figure CN120805892B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent document processing technology, and in particular to a document content parsing method, apparatus, and program product based on structural analysis. Background Technology
[0002] Electronic documents have become a core medium for knowledge transmission, information exchange, and business processes. Among them, word processing documents, represented by Microsoft Word's DOCX format, are widely used in numerous professional fields, such as writing technical reports, drafting legal contracts, compiling product manuals, and generating experimental data records, thanks to their powerful content editing, complex layout design, and rich formatting capabilities. These documents not only contain plain text information but also carry rich structured information and logical relationships through complex combinations of various elements such as tables, lists, tables of contents, and charts. Therefore, achieving automated, accurate, and efficient content extraction and structured transformation of massive amounts of DOCX documents has become an indispensable key technological prerequisite for realizing downstream applications such as intelligent data mining, driving robotic process automation (RPA), developing advanced question-answering systems, and building intelligent agents.
[0003] DOCX format, as an open format based on the OOXML international standard, is essentially a ZIP compressed file containing multiple XML files and resources. All document information, including text content, style definitions, numbering rules, and media resource relationships, is stored in a structured manner within these XML files. Theoretically, by accurately parsing these XML files, the entire content and structure of the document can be restored without loss. However, existing document parsing technologies suffer from the following problems when processing real-world documents—complex in structure and full of ambiguity—generated by human users through graphical interfaces:
[0004] Mainstream, standard library-based direct parsing tools are often limited to extracting text from shallow or idealized structures. These tools can effectively iterate through paragraphs and tables in a document and extract plain text. However, their limitations become more pronounced when faced with complex document structures. For example, for tables, merging cells that span multiple columns horizontally (gridSpan) or multiple rows vertically (vMerge) disrupt the table's orderly matrix structure, and simple row traversal cannot correctly restore the logical relationships between cells. In some special cases, new tables may be nested within cells, forming a form-like layout, a recursive structure that traditional parsers struggle to handle. For numbered lists, context-dependent multi-level numbering (e.g., "1." -> "1.1" -> "a") relies on a dynamically changing context state in the document flow for number generation. Insertion of any ordinary paragraph or table can interrupt and reset this state, causing the parsed numbered list to lose its correct hierarchy and sequence. The generation mechanism for a table of contents (TOC) varies. It may be dynamically generated using special field codes or composed of ordinary paragraphs with specific styles applied. Simple text extraction can confuse it with the main text, resulting in the loss of its meta-information as a navigation structure. These issues collectively lead to existing shallow parsing tools generally producing results with information loss, formatting errors, and structural dimensionality reduction when processing complex documents.
[0005] To circumvent the complexity of parsing the underlying XML structure, some technical solutions have shifted to a visual recognition-based approach, such as Optical Character Recognition (OCR) or document layout analysis combined with Computer Vision (CV). These methods first render the document page as an image, then extract text and infer layout using image processing and pattern recognition techniques. While this approach is necessary for processing scanned documents and other data without source data, its application to DOCX documents with source data has fundamental flaws. First, this method involves a lossy conversion process: the document's metadata, the fidelity of vector graphics, hyperlinks between text, and invisible formatting information (such as style definitions) are completely discarded during rendering. Second, it is costly and inefficient: document rendering, image processing, and OCR recognition are computationally intensive tasks, making it 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 formatted tables with many lines, or pages with multi-column layouts and mixed text and images, the error rate of OCR recognition increases significantly. Furthermore, this visual inference-based method lacks determinism, and its results are difficult to reproduce and interpret stably.
[0006] With the development of artificial intelligence technology, methods using large language models (LLMs) or multimodal models to "understand" document content have gradually emerged. These models, through pre-training on massive amounts of data, possess a certain ability to understand document structure and extract information. However, applying such heavy-duty AI models to general document parsing tasks also faces resource and efficiency bottlenecks. The training and inference processes of these models require powerful computing resources (such as high-performance GPU clusters), resulting in high operating costs. At the same time, limited by the length of the context window, processing long documents requires complex text segmentation and context management, which not only increases processing latency but may also affect the global consistency of parsing due to information fragmentation. Furthermore, the "black box" nature and probabilistic output of these models make it difficult to fully guarantee the stability and interpretability of their results in structured conversion tasks that require 100% accurate reconstruction.
[0007] In summary, there is an urgent need for a technical solution that can avoid information loss in shallow parsing while overcoming the resource and efficiency bottlenecks of visual recognition and heavy AI models. The ideal solution should not rely on image rendering, but rather perform deep, context-aware analysis of the underlying OpenXML structure of DOCX documents. This would enable a lightweight, efficient, and high-fidelity deterministic approach to accurately parse and reconstruct the content and structure of documents containing various complex elements. Summary of the Invention
[0008] To address the shortcomings of existing technologies, this invention proposes a document content parsing method, apparatus, and program product based on structural analysis. This enables high-precision, high-efficiency, and low-resource-consumption structured conversion of complex documents. It is particularly suitable for high-fidelity content extraction and structural reconstruction of word processing documents (such as DOCX format) using the 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.
[0009] The document content parsing method proposed in this invention constructs a multi-stage, modular parsing pipeline, deconstructing the complex document parsing task into a series of well-defined, collaborative processing units. First, a style and numbering pre-parsing module preloads and models the document's global formatting rules, establishing an understanding of the document's "syntax." Then, a master traversal and distribution module distributes content blocks (such as paragraphs and tables) to corresponding specialized parsers according to the document's natural flow. The specialized content parsing module, as the core of this invention, consists of multiple sub-modules (including directory parsing, paragraph and list processing, and complex table parsing), responsible for performing context-based deep parsing and transformation of specific content. Finally, an embedded resource processing module and a post-processing and optimization module collaborate to decouple binary resources and achieve final normalization of the output text.
[0010] In a first aspect, the present invention provides a document content parsing method based on structural analysis, comprising the following steps:
[0011] S1: Perform pre-parse of numbering and style in the XML document to extract the document's global structure and formatting rules;
[0012] S2: Processes the main document file of the XML document, performs serialization traversal on the content body, reads block-level elements one by one according to the natural order defined in the XML document, judges the type of the element by the XML tag, and then dispatches the element to the corresponding specialized parsing submodule.
[0013] S3: Uses a specialized content parsing submodule to perform in-depth parsing and structural reconstruction of the table of contents, paragraphs and lists, and tables in the XML document to generate Markdown format documents;
[0014] S4: Throughout the entire parsing process, embedded resource processing is performed on the XML document synchronously.
[0015] As a further improvement of the present invention, the method further includes step S5: post-processing and optimization; specifically including:
[0016] The post-processing and optimization module scans the Markdown document and identifies the table portion. It temporarily converts the table back into a two-dimensional data structure, performs structural analysis and optimization, removes columns with empty or duplicate content, and regenerates a more compact Markdown table.
[0017] As a further improvement of the present invention, the number pre-parse in step S1 specifically includes the following steps:
[0018] By parsing the numbering definition file in the XML document, a mapping relationship is constructed between the ID of each list instance in the document and the ID of the abstract template it references;
[0019] The abstract template includes formatting rules for all levels extracted from the abstract list template, specifically including numbering format, indentation, prefix, and suffix.
[0020] As a further improvement of the present invention, the style pre-parsing in step S1 specifically includes the following steps:
[0021] By parsing the style definition file in the XML document, all paragraph and character styles in the document are traversed.
[0022] For styles with embedded number attributes, extract their associated list instance IDs and establish an association mapping from style names to abstract template definitions.
[0023] As a further improvement of the present invention, step S3, the step of processing the document directory, includes:
[0024] Directory identification is achieved by detecting directory-specific string styles or directory field codes;
[0025] Extract directory content using an XPath-based content extractor;
[0026] Analyze the directory hierarchy, reconstruct the hierarchical structure of the directory entries, and represent the hierarchical structure using indentation.
[0027] As a further improvement of the present invention, the specific steps for extracting the directory content include:
[0028] By using specific path expressions, the extractor can accurately locate and extract all text nodes inside the hyperlink tags that serve as table of contents titles, filtering out non-content parts including page numbers and leader characters.
[0029] As a further improvement of the present invention, in step S3, the paragraphs and lists are processed by using a state machine to maintain the global list context, specifically including the following steps:
[0030] For paragraphs with numbered attributes, their formatting rules are obtained from the pre-parsing results of step S1, and the state of the list context is updated accordingly, and a Markdown list prefix is generated.
[0031] When a paragraph without a number attribute is encountered, the list context is reset and the current list count ends.
[0032] When you encounter a paragraph belonging to the same list again, restore its correct numbering sequence.
[0033] As a further improvement of the present invention, the list context is a data structure used to track the state of the list currently being processed 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.
[0034] As a further improvement of the present invention, the state of the updated list context includes updating via the counter, specifically including:
[0035] Initialize the counter for the new list;
[0036] For the next level of list, increase the level depth and reset the sub-level counter;
[0037] For the sibling list, increment the current counter.
[0038] As a further improvement of the present invention, the method of processing the table in step S3 includes:
[0039] By performing a quick traversal and accumulating the horizontal span attribute value of each cell, the exact total number of columns in the table can be calculated.
[0040] Create a two-dimensional logical matrix in memory that is completely consistent with the visual layout of the table;
[0041] The two-dimensional logical matrix is scanned twice, namely by row and by column, to handle the object reference relationships of horizontally merged and vertically merged cells;
[0042] Fill the table content into the two-dimensional logical matrix that has been scanned twice, and generate a table in Markdown format.
[0043] As a further improvement of the present invention, the specific steps of the two-pass scanning include:
[0044] In row-by-row scanning, the way to handle horizontally merged cells that span multiple columns is to place the object reference of the cell at the leftmost starting position of the cell, and leave the subsequent positions covered by the cell empty;
[0045] In column scanning, the way to handle vertically merged cells that span multiple rows is to use the object reference of the topmost starting position of the cell to overwrite the merged positions below.
[0046] As a further improvement of the present invention, the specific steps for embedded resource processing in step S4 include:
[0047] When an embedded resource object is detected in the XML structure of a paragraph, its relation ID is extracted;
[0048] This ID is used to locate the corresponding binary file in the media section of the XML document;
[0049] Decouple the file, save it locally, and generate a unique UUID filename;
[0050] Insert a resource object reference link pointing to the local file into the Markdown document;
[0051] The resource objects include graphical objects.
[0052] In a second aspect, the present invention provides a computer device including 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 described in the first aspect.
[0053] Thirdly, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in the first aspect.
[0054] Fourthly, the present invention provides a computer program product that, when executed by a processor, implements the steps of the method described in the first aspect.
[0055] The technical advantages of this invention lie in its ability to accurately reconstruct complex elements without relying on visual rendering or probabilistic models. This is achieved by directly reconstructing the underlying data structure of the document, particularly by introducing a logical matrix to restore complex table structures and using a state machine to maintain the contextual continuity of the list. This invention offers advantages such as high fidelity, high efficiency, low resource consumption, and strong adaptability, providing a high-quality, reliable structured data foundation for various downstream applications. Attached Figure Description
[0056] Figure 1 This is a flowchart of a document content parsing method disclosed in this invention.
[0057] Figure 2 This is a diagram illustrating the sub-modules in the document content parsing method. Detailed Implementation
[0058] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Steps S1, S2… in the described embodiments of the present invention do not limit the scope of execution of the present invention; the various models, simulation environments, and software described in the present invention are not considered as the only limiting methods of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.
[0059] In this invention, computer device / equipment / system refers to a related entity applied to a computer, such as hardware, a combination of hardware and software, software, or software in execution. More specifically, for example, software includes, but is not limited to, a process running on a processor, a processor, an object, executable software, an execution thread, a program, and / or a computer. Furthermore, an application program or script running on a server, and the server itself, can also be software. One or more software programs may be in an execution process and / or thread, and the software may be localized on one computer and / or distributed across two or more computers, and may be run on various computer-readable media.
[0060] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other.
[0061] Firstly, this invention provides an embodiment of a document content parsing method based on structural analysis, the overall process of which can be summarized as an automated parsing pipeline composed of multiple cooperating modules. For example... Figure 1 As shown, the specific process can be as follows:
[0062] S1: Use the pre-parse module to pre-parse styles and numbers;
[0063] Before any actual processing of the document's main content, the pre-parsing module is first started. The goal of this module is to "pre-read" and understand the document's global formatting conventions, building an in-memory rule model for subsequent context-aware parsing. This module loads and parses the core configuration files within the DOCX archive, primarily performing two key tasks:
[0064] S11: A complete multi-level list definition model is constructed by parsing the numbering definition file (word / numbering.xml); in the OOXML standard, this XML file is the central element defining all automatically numbered list formats in the document. The pre-parsing module systematically traverses two core elements in this file: the abstract list template (…). <w:abstractnum>) and specific list instances ( <w:num>).
[0065] For each abstract list template, extract all its levels ( <w:lvl>The formatting rules for the numbering include numbering format (number, letter, bullet), indentation, prefix and suffix, etc., and associate it with its unique abstract template ID (w:abstractNumId).
[0066] For each specific list instance, establish a mapping between its list instance ID (w:numId) and the referenced abstract template ID.
[0067] This process builds a complete multi-level list definition model, so that in subsequent processing, any list item can find its complete formatting rules by its list instance ID (w:numId).
[0068] S12: Parsing the style definition file (word / styles.xml): The style definition file defines all paragraph and character styles visible to the user in the document. The parser will iterate through all paragraph styles defined in this file ( <w:style>), and pay special attention to those with embedded number attributes ( <w:numpr>The parser extracts the associated list instance ID (numId) when it detects a style (e.g., "Heading 1"), thus establishing a mapping from the style name (e.g., "Heading 1") to a specific list definition.
[0069] This step greatly enhances adaptability to different user editing habits by properly 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 document's global formatting rules. This enables subsequent parsers to "understand" the document's formatting conventions and make correct, context-based parsing decisions.
[0071] S2: Use the main control process module to perform main control traversal and distribution;
[0072] After pre-parsing is completed, the main control flow module begins to process the main content of the main document (word / document.xml). <w:body>This module performs serialization traversal. It functions like an intelligent dispatch center, strictly following the natural order defined in the XML document, reading block-level elements one by one. For each read block-level element, it determines its type based on its XML tags and dispatches the element to the appropriate specialized parsing submodule for processing.
[0073] For example, when encountering a paragraph element ( <w:p>When it encounters a table element, it passes it to the paragraph and list processing submodule; when it encounters a table element... <w:tbl>When the condition is met, it is passed to the complex table parsing submodule.
[0074] This distribution mechanism ensures that different types of elements can be processed by the most suitable logical unit, achieving a high degree of modularity and scalability of the system.
[0075] S3: Use a specialized content parsing submodule for in-depth document parsing and structural reconstruction;
[0076] The specialized content parsing submodule is responsible for in-depth parsing and structural reconstruction of specific content, including processing using multiple highly specialized submodules:
[0077] S31: Directory parsing submodule: This module uses a flexible hybrid mode to identify and extract directories (TOC).
[0078] It first checks if the paragraph uses a special style that begins with the string "TOC," which is the most common way to implement a table of contents in modern Word documents. Additionally, to ensure compatibility with older or specially formatted documents, it also identifies the table of contents 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 initiates 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 precisely locate and extract hyperlinks that serve as table of contents titles. <w:hyperlink>This intelligently filters out non-content parts such as page numbers generated by the PAGEREF field and leading characters generated by tabs, as well as all text nodes inside the PAGEREF tag.
[0080] By analyzing the hierarchy of the TOC style (such as "TOC 1", "TOC 2"), the hierarchical structure of the directory entries is restored and reflected in the final output in an indented form.
[0081] S32: Paragraph and List Processing Submodule: This module is responsible for processing all regular paragraphs and multilevel lists that are not tables or directories.
[0082] Its core is to use a state machine to maintain a global list context. This list context is a data structure used to track the state of the list being processed in real time, including the list instance ID (numId) of the current list, the current level depth (ilvl), and a counter for each level.
[0083] When encountering a paragraph with a number attribute, the module queries the numbering model established during the pre-parsing phase to obtain its formatting rules and updates the list context accordingly (e.g., initializing the counter if it's a new list, increasing the level depth and resetting the lower-level counter if it's a next level, and incrementing the current counter if it's a sibling). It then generates the correct Markdown list prefix based on the updated context. When encountering a paragraph without a number attribute, the module resets the list context, marking the official end of the list.
[0084] This state machine-based context management mechanism enables the parser to correctly handle lists interrupted by ordinary paragraphs or tables. When a paragraph belonging to the same list is encountered again, its correct numbering sequence can be seamlessly restored, ensuring the logical continuity and accuracy of the list globally.
[0085] S33: Complex Table Parsing Submodule: This module introduces a method for constructing logical matrices and is responsible for parsing complex tables.
[0086] First, it calculates the exact total number of columns in the table by accumulating the gridSpan attribute value of each cell through a fast traversal. Then, it creates a two-dimensional logical matrix (cell_map) in memory that is completely consistent with the visual layout of the table.
[0087] This module populates the matrix using a two-pass algorithm: the first pass scans row-wise, handling horizontal merges. When a cell spanning multiple columns is encountered, the parser places the object reference of that cell at the beginning of the corresponding row in the matrix, leaving subsequent positions empty, accurately reflecting the structure of horizontal merges. The second pass scans column-wise, handling vertical merges (vMerge). The parser precisely reconstructs the vertical merge relationships of the table at the data structure level by overwriting the matrix entries of merged cells below with the object references of the starting merged cells directly above them.
[0088] During the content generation phase, this module accurately determines whether the current row is a continuation of vertically merged cells by comparing the cell object identifiers of key columns in the matrix. Because of the second scan, all cells belonging to the same vertically merged region point to the same object in the matrix. Therefore, this object reference-based comparison fundamentally avoids erroneous accumulation of list numbers within the merged region. Furthermore, when processing each cell, the module can check its content model to detect whether it contains nested tables, and recursively call itself to complete the full parsing of tables with arbitrary depths of nesting, achieving comprehensive support for complex form-style layouts.
[0089] S4: Embedded resource processing and post-processing;
[0090] Throughout the parsing process, the embedded resource processing module operates synchronously.
[0091] When in the XML structure of the paragraph ( <w:r>Graphical objects (such as elements) were detected in the elements. <w:drawing>When it retrieves the image file, it extracts its relation ID (r:embed). This ID is a key pointing to the document's relation file (.rels). The corresponding binary image file is then located in the document's media component using this ID. This file is decoupled, saved locally, and given a unique UUID filename. Finally, a standard image reference link pointing to this local file is inserted into the final Markdown text.
[0092] After all content conversion is complete, an optional post-processing and optimization module can be enabled. This module scans the generated Markdown text and identifies the table sections. By temporarily converting the Markdown tables back into a two-dimensional data structure, the module performs structural analysis and optimization operations. For example, it analyzes and removes redundant columns that are completely empty in all rows or columns that completely repeat content from other columns. Finally, based on the cleaned data structure, it regenerates a more optimized and compact Markdown table, significantly improving the standardization and readability of the final output.
[0093] Through the above steps, the method of the present invention 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 automation and intelligent applications.
[0094] In a second aspect, the present invention provides an embodiment of a computer device, including 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 described in the first aspect.
[0095] Thirdly, the present invention provides an embodiment of a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in the first aspect.
[0096] Fourthly, the present invention provides a computer program product embodiment, which, when executed by a processor, implements the steps of the method described in 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, Includes the following steps: S1: Perform pre-parse of numbering and style in the XML document to extract the document's global structure and formatting rules; S2: Processes the main document file of the XML document, performs serialization traversal on the content body, reads block-level elements one by one according to the natural order defined in the XML document, judges the type of the element by the XML tag, and then dispatches the element to the corresponding specialized parsing submodule. S3: Utilizing a specialized content parsing submodule, it performs in-depth parsing and structural reconstruction of the table of contents, paragraphs, lists, and tables in the XML document, generating a Markdown format document; among which... The processing of paragraphs and lists includes using a hierarchical counting state machine to maintain the global list context. The methods for processing tables include: constructing a two-dimensional logical matrix that is consistent with the table structure, and then filling it with table content; S4: Throughout the entire parsing process, embedded resource processing is performed on the XML document synchronously.
2. The method according to claim 1, characterized in that, It also includes step S5: post-processing and optimization; specifically including: The post-processing and optimization module scans the Markdown document and identifies the table portion. It temporarily converts the table back into a two-dimensional data structure, performs structural analysis and optimization, removes columns with empty or duplicate content, and regenerates a more compact Markdown table.
3. The method according to claim 1, characterized in that, The number pre-parse in step S1 specifically includes the following steps: By parsing the numbering definition file in the XML document, a mapping relationship is constructed between the ID of each list instance in the document and the ID of the abstract template it references; The abstract template includes formatting rules for all levels extracted from the abstract list template, specifically including numbering format, indentation, prefix, and suffix.
4. The method according to claim 1, characterized in that, The style pre-parsing in step S1 specifically includes the following steps: By parsing the style definition file in the XML document, all paragraph and character styles in the document are traversed. 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, characterized in that, In step S3, the steps for processing the document directory include: Directory identification is achieved by detecting directory-specific string styles or directory field codes; Extract directory content using an XPath-based content extractor; Analyze the directory hierarchy, reconstruct the hierarchical structure of the directory entries, and represent the hierarchical structure using indentation.
6. The method according to claim 5, characterized in that, The specific steps for extracting the directory content include: By using specific path expressions, the extractor can accurately locate and extract all text nodes inside the hyperlink tags that serve as table of contents titles, filtering out non-content parts including page numbers and leader characters.
7. The method according to claim 1, characterized in that, In step S3, the specific steps for processing paragraphs and lists include: For paragraphs with numbered attributes, their formatting rules are obtained from the pre-parsing results of step S1, and the state of the list context is updated accordingly, and a Markdown list prefix is generated. When a paragraph without a number attribute is encountered, the list context is reset and the current list count ends. When you encounter a paragraph belonging to the same list again, restore its correct numbering sequence.
8. The method according to claim 7, characterized in that, The list context is a data structure used to track the state of the list currently being processed 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 state of the update list context includes updates via the counter, specifically including: Initialize the counter for the new list; For the next level of list, increase the level depth and reset the sub-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 ways: By performing a quick traversal and accumulating the horizontal span attribute value of each cell, the exact total number of columns in the table can be calculated. Create a two-dimensional logical matrix in memory that is completely consistent with the visual layout of the table; The two-dimensional logical matrix is scanned twice, namely by row and by column, to handle the object reference relationships of horizontally merged and vertically merged cells; Fill the table content into the two-dimensional logical 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 scans include: In row-by-row scanning, the way to handle horizontally merged cells that span multiple columns is to place the object reference of the cell at the leftmost starting position of the cell, and leave the subsequent positions covered by the cell empty; In column scanning, the way to handle vertically merged cells that span multiple rows is to use the object reference of the topmost starting position of the cell to overwrite the merged positions below.
12. The method according to claim 1, characterized in that, In step S4, the specific steps for embedded resource processing include: When an embedded resource object is detected in the XML structure of a paragraph, its relation ID is extracted; This ID is used to locate the corresponding binary file in the media section of the XML document; Decouple the file, save it locally, generate a corresponding local file, and generate a unique UUID filename; Insert a resource object reference link pointing to the local file into the Markdown document; The resource objects include graphical objects.
13. A computer device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the steps of the method according to any one of claims 1-12.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the steps of the method described in any one of claims 1-12.
15. A computer program product, characterized in that, When executed by a processor, the computer program implements the steps of the method described in any one of claims 1-12.
Citation Information
Patent Citations
Method and system for converting Word file into EPUB file
CN110083805A
OOXML document entrainment detection method, storage medium and electronic equipment
CN116126349A