Methods, devices, and media for converting markdown to notion api applicable structs
By parsing Markdown text to generate a list of markup objects and using a converter factory to dynamically allocate processors, the Markdown text is converted into a block structure applicable to the Notion API. This solves the problem that the Notion API cannot parse Markdown, and achieves efficient and accurate content migration and format preservation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 深圳市和讯华谷信息技术有限公司
- Filing Date
- 2026-03-04
- Publication Date
- 2026-06-12
Smart Images

Figure CN122195440A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data conversion technology, and in particular to a method, apparatus and medium for converting Markdown into a Notion API-compatible structure. Background Technology
[0002] Markdown is a lightweight markup language widely used for document writing due to its concise syntax. Notion, as a collaboration platform, provides an application programming interface (API) for creating pages within a Notion workspace.
[0003] In practical applications, users often need to import Markdown formatted documents into Notion for management. However, the inventors of this application discovered that the Notion API accepts its custom structured block data and cannot directly parse Markdown syntax. If Markdown text is passed in as a plain string, the Notion page will only display the raw string, along with formatting tags, failing to display headings, bolding, and other effects, resulting in the loss of document layout information and affecting readability. Summary of the Invention
[0004] This invention provides a method, device, and medium for converting Markdown into a Notion API-compatible structure. The technical problem it aims to solve is: how to provide an effective solution for converting Markdown text into a Notion API-compatible structure.
[0005] In a first aspect, embodiments of the present invention provide a method for converting Markdown into a Notion API-compatible struct, comprising: Obtain the Markdown text string, call the parser to parse the Markdown text string, and generate a list of markup objects. Each markup object in the list of markup objects has a corresponding type identifier. Initialize the converter factory, which maintains multiple conversion processors; The marked objects in the marked object list are sequentially input into the converter factory. The converter factory then matches the corresponding target converter from the plurality of converters based on the type identifier of the currently input marked object. The currently input token object is passed to the target transformation processor, which parses the currently input token object to generate at least one block structure that conforms to the Notion API specification. Store at least one block structure generated by the target conversion processor into a block structure set; After processing all the marked objects in the marked object list, the block structure set is output as a list of Notion API applicable structures.
[0006] Optionally, the parser is invoked to parse the Markdown text string and generate a list of markup objects, including: Call the parsing interface of the mistune library and pass the Markdown text string as an input parameter to the mistune library; Receive the parsing result returned by the mistune library. The parsing result is a tree-structured list of marked objects. Each marked object in the list contains a type field and a content field.
[0007] Optionally, the initialization converter factory includes: Create a converter factory instance; Register multiple conversion processors in the converter factory instance; Establish a mapping relationship between type identifiers and conversion processors, and store the mapping relationship in the converter factory instance.
[0008] Optionally, the step of matching the corresponding target conversion processor from the plurality of conversion processors based on the type identifier of the currently input marked object through the converter factory includes: The converter factory reads the type field of the currently input marked object to obtain the type identifier; The converter factory queries the mapping relationship based on the type identifier to find the conversion processor corresponding to the type identifier; If a corresponding conversion processor is found, the found conversion processor will be designated as the target conversion processor.
[0009] Optionally, the step of parsing the currently input tokenized object through the target transformation processor to generate at least one block structure conforming to the Notion API specification includes: The target conversion processor reads the content field of the marked object and extracts the text content and attribute information. The target transformation processor constructs at least one block structure object according to the type identifier of the marked object, the text content, and the attribute information, in accordance with the field specification of the Notion API block structure.
[0010] Optionally, storing at least one block structure generated by the target conversion processor into a block structure set includes: Create an empty list of block structures as the block structure set; For each tagged object, at least one block structure object generated by the target transformation processor is sequentially appended to the block structure list according to the order in which the tagged objects are in the tagged object list.
[0011] Optionally, after outputting the block structure set as a list of Notion API-applicable structures, the method further includes: The Notion API uses the list of applicable structures as the request body to call the Notion API's page creation or page update interface, and sends the list of block structures to the Notion server.
[0012] Optionally, the tag objects in the tag object list include at least one of paragraph type tag objects, heading type tag objects, list type tag objects, and code block type tag objects; The plurality of conversion processors includes at least one of paragraph conversion processor, heading conversion processor, list conversion processor, and code block conversion processor; The paragraph conversion processor is used to process the paragraph type tag object, the heading conversion processor is used to process the heading type tag object, the list conversion processor is used to process the list type tag object, and the code block conversion processor is used to process the code block type tag object.
[0013] Secondly, embodiments of the present invention also provide a computer device, which includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the above-described method.
[0014] Thirdly, embodiments of the present invention also provide a computer-readable storage medium storing a computer program that, when executed by a processor, can implement the above-described method.
[0015] This invention provides a method, device, and medium for converting Markdown to Notion API-compatible structures. Specifically, this invention generates a list of markup objects by parsing Markdown text and dynamically allocates appropriate conversion processors based on the type of the markup objects using a converter factory, achieving automated conversion from Markdown to Notion block structures. Furthermore, because the conversion processors handle different types of markup objects specifically, the accuracy and precision of the conversion logic are ensured, avoiding formatting errors that might result from uniform processing. The final generated block structure list is strictly compatible with the Notion API and can be directly used for Notion page creation or updates, effectively solving the problem that Markdown text cannot be directly formatted and displayed in Notion. This method provides developers with an efficient and reliable solution for importing Markdown content into Notion, significantly improving the efficiency and accuracy of content migration while reducing the labor costs of manual reformatting. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart illustrating a method for converting Markdown into a Notion API-compatible structure, as provided in an embodiment of the present invention. Figure 2 This is a schematic block diagram of a computer device provided in an embodiment of the present invention. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0020] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0021] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0022] As used in this specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if [described condition or event] is detected" may be interpreted, depending on the context, as "once determined," "in response to determination," "once [described condition or event] is detected," or "in response to detection of [described condition or event]."
[0023] Please see Figure 1 This invention provides a method for converting Markdown into a Notion API-compatible struct, the method comprising the following steps: S1. Obtain the Markdown text string, call the parser to parse the Markdown text string, and generate a list of markup objects. Each markup object in the list of markup objects has a corresponding type identifier.
[0024] In practice, the first step is to obtain the Markdown text string to be converted. This Markdown string can come from various sources, such as direct input by the user through the application interface, reading Markdown format documents from the local file system, or receiving Markdown content sent by other systems through a network interface. This invention does not specifically limit the source. The obtained string serves as the raw input data for subsequent processing.
[0025] Further, the parser is invoked to parse the Markdown text string. The parser employs a parsing algorithm based on Markdown syntax rules, capable of recognizing markers in the text and breaking it down into multiple semantically meaningful units. The parser scans the text character by character, generating a series of marker objects according to the marker rules. Each marker object corresponds to an element in Markdown, such as a paragraph, a first-level heading, or a list item. After parsing, the parser outputs a list of marker objects. This list is organized using a specific data structure, with each marker object containing a type identifier to distinguish the specific type of the element. The list of marker objects may be arranged in linear order or in a tree structure reflecting the nested relationships between elements, such as list items containing sublists.
[0026] In some preferred embodiments, the process of calling the parser to parse the Markdown text string and generate a list of markup objects includes: calling the parsing interface of the Mistune library, passing the Markdown text string as an input parameter to the Mistune library; and receiving the parsing result returned by the Mistune library, wherein the parsing result is a tree-structured list of markup objects, and each markup object in the list contains a type field and a content field.
[0027] In practice, the first step is to call the parsing interface of the Mistune library. Mistune is a mature Markdown parsing library that provides efficient parsing capabilities. The obtained Markdown text string is passed as an input parameter to the Mistune library's parsing interface. This interface is typically a function or method that accepts a string and returns the parsed result.
[0028] Furthermore, the parsing results are received from the mistune library. Internally, the mistune library performs lexical and syntactic analysis, breaking down the text into a series of syntactic units according to the Markdown specification and organizing these units in a tree structure. The returned parsing result is a tree-structured list of markup objects. This tree structure reflects the hierarchical relationships between Markdown elements; for example, a list item may contain nested sublists, and a quotation block may contain multiple paragraphs. Each markup object in the list contains a type field and a content field. The type field identifies the type of markup object, such as heading, paragraph, list_item, etc. The content field stores the specific text content, attribute information, and a list of possible sub-markup objects for that markup object. Through the parsing by the mistune library, the original Markdown text is accurately converted into a structured intermediate representation, providing an accurate data foundation for subsequent conversions.
[0029] This invention, through its implementation, utilizes the mature and stable parsing capabilities of the Mistune library's parsing interface to ensure the accuracy and standardization of the conversion from Markdown text to a list of markup objects. Furthermore, the tree-structured list of markup objects fully preserves the hierarchical relationships of the original Markdown, such as nested lists and multiple sections within quoted blocks, providing necessary information for the subsequent conversion processor to correctly restore the document structure. Moreover, each markup object contains clearly defined type and content fields, enabling the conversion processor to accurately extract the required data, thereby improving the overall reliability and fidelity of the conversion.
[0030] S2, Initialize the converter factory, which maintains multiple conversion processors.
[0031] In practice, a converter factory is initialized. The converter factory is a centralized management component that internally maintains multiple conversion processors. Furthermore, each conversion processor is an independent processing unit, specifically responsible for converting one or more specific types of tokenized objects into the block structure required by the Notion API. During initialization, the converter factory pre-creates these processor instances and records their correspondence with tokenized types. The converter factory itself does not execute the specific conversion logic; instead, it acts as a scheduler, allocating appropriate conversion processors based on the type of the tokenized object.
[0032] In some preferred embodiments, initializing the converter factory includes: creating a converter factory instance; registering multiple conversion processors in the converter factory instance; and establishing a mapping relationship between type identifiers and conversion processors, wherein the mapping relationship is stored in the converter factory instance.
[0033] In practice, the first step is to create a converter factory instance. This instance is an object or class instance that is instantiated at runtime and used for subsequent management of conversion processors and scheduling of conversion tasks.
[0034] Furthermore, multiple conversion processors are registered in the converter factory instance. The registration process can involve instantiating a predefined processor class and adding it to a container within the factory, or dynamically loading processor modules via a configuration file. Furthermore, each conversion processor corresponds to processing logic for one or more specific types of tag objects; for example, a paragraph processor specifically handles paragraph type tag objects, and a heading processor specifically handles heading type tag objects.
[0035] Furthermore, a mapping relationship is established between type identifiers and conversion processors. This mapping relationship is stored in the converter factory instance, typically in the form of key-value pairs, where the key is the type identifier of the tag object (such as the string "paragraph" or "heading"), and the value is a reference to the corresponding conversion processor instance or the processor identifier. The mapping relationship can be automatically established during processor registration or manually configured after registration. After the mapping is established, the converter factory can quickly locate the corresponding conversion processor based on the type identifier of the input tag object, achieving efficient distribution and scheduling. Furthermore, this mapping relationship supports dynamic expansion; when new tag types need to be supported, simply register the new processor and update the mapping.
[0036] This embodiment constructs a flexible and scalable scheduling architecture by creating converter factory instances, registering multiple conversion processors, and establishing a mapping relationship between type identifiers and processors. This architecture decouples the identification of markup types from the processing logic, allowing the converter factory to distribute data only based on the mapping relationship without needing to concern itself with the specific processing details. Furthermore, when support for new Markdown elements needs to be added, only the new processor needs to be added and the mapping updated; there is no need to modify the core logic of existing processors or factories, thereby reducing system maintenance costs and improving code scalability and reusability. Furthermore, the existence of the mapping relationship ensures rapid matching of types to processors, improving the execution efficiency of the conversion process.
[0037] In some preferred embodiments, the tag objects in the tag object list include at least one of paragraph type tag objects, heading type tag objects, list type tag objects, and code block type tag objects; the plurality of conversion processors include at least one of paragraph conversion processor, heading conversion processor, list conversion processor, and code block conversion processor; wherein, the paragraph conversion processor is used to process the paragraph type tag objects, the heading conversion processor is used to process the heading type tag objects, the list conversion processor is used to process the list type tag objects, and the code block conversion processor is used to process the code block type tag objects.
[0038] In specific implementation, the tag objects in the tag object list include at least one of the following: paragraph type tag objects, heading type tag objects, list type tag objects, and code block type tag objects. Correspondingly, the converter factory maintains multiple conversion processors, including at least one of the following: paragraph conversion processor, heading conversion processor, list conversion processor, and code block conversion processor.
[0039] Furthermore, the paragraph conversion processor is specifically designed to handle paragraph type tag objects. When a tag object is identified as "paragraph", the converter factory dispatches the object to the paragraph conversion processor, which is responsible for converting it into a Notion paragraph block.
[0040] Furthermore, the heading transformation processor is specifically designed to process heading type tag objects. Heading type tag objects may contain subtypes at different levels, such as Heading 1, Heading 2, etc. The heading transformation processor converts these tags into corresponding Heading 1, Heading 2, etc., within the Notion based on the level information within the tag object.
[0041] Furthermore, the list conversion processor is specifically designed to handle list-type token objects. List types include ordered and unordered lists, and may contain nested sublists. The list conversion processor parses the list token object and its sub-token objects, generating Notion list item blocks and correctly setting the nesting relationships and ordinal types.
[0042] Furthermore, the code block transformation processor is specifically designed to process code block type token objects. A code block token object contains code content and its language identifier. The code block transformation processor converts it into Notion code blocks and populates the code content and language attributes.
[0043] Furthermore, each of the aforementioned processors generates a corresponding Notion block structure upon receiving a tag object of the corresponding type.
[0044] This embodiment covers the main formatting elements in Markdown documents by explicitly defining various common markup object types and their corresponding dedicated conversion processors. Paragraphs, headings, lists, and code blocks are the most commonly used and fundamental components of Markdown. This embodiment provides a dedicated processor for each element, ensuring that these core formatting elements can be accurately converted into Notion block structures. The dedicated processor design allows each processor to be optimized for specific types of complex characteristics; for example, the list processor handles nesting, and the code block processor handles language highlighting, thereby improving the quality and robustness of the conversion. This embodiment provides comprehensive basic support for practical applications and can meet the conversion needs of the vast majority of Markdown documents.
[0045] S3, the marked objects in the marked object list are sequentially input into the converter factory, and the converter factory matches the corresponding target converter from the multiple converter processors according to the type identifier of the currently input marked object.
[0046] In practice, the marked objects from the previously generated list are sequentially input into the converter factory. The input process is typically implemented by iterating through the list, processing one marked object at a time. For the currently input marked object, the converter factory first reads its type identifier, and then searches for a matching conversion processor based on its internally maintained mapping. If a match is found, that processor is designated as the target conversion processor.
[0047] In some preferred embodiments, the step of matching the corresponding target conversion processor from the plurality of conversion processors based on the type identifier of the currently input marked object by the converter factory includes: reading the type field of the currently input marked object by the converter factory to obtain the type identifier; querying the mapping relationship by the converter factory based on the type identifier to find the conversion processor corresponding to the type identifier; and if a corresponding conversion processor is found, determining the found conversion processor as the target conversion processor.
[0048] In practice, the converter factory first reads the type field of the currently input marker object to obtain the type identifier. The type field is an attribute of the marker object that records the object's type information, such as strings like "heading" or "paragraph". The converter factory extracts the type identifier by accessing this field.
[0049] Furthermore, the converter factory queries the internally stored mapping relationship based on the acquired type identifier. This mapping relationship is a correspondence table between type identifiers and conversion processors established in the above embodiments. The query process can involve looking up the corresponding processor reference in the mapping dictionary based on the type identifier.
[0050] Furthermore, if a corresponding transformation processor is found, the converter factory designates it as the target transformation processor. This means that this processor will be used to process the current tagged object. If no corresponding processor is found, the converter factory can execute pre-defined exception handling logic, such as ignoring the tagged object, using the default processor, or throwing an error. After determining the target transformation processor, subsequent steps pass the current tagged object to that processor for processing.
[0051] This invention achieves precise distribution of tagged objects by reading type identifiers, querying mapping relationships, and determining target conversion processors through a converter factory. This process ensures that each tagged object can be processed by a processor specifically designed for its type, avoiding conversion errors caused by type mismatches. Furthermore, the mechanism for querying mapping relationships is based on a pre-established correspondence table, which is efficient and deterministic, maintaining stable performance when processing a large number of tagged objects. Furthermore, this step provides an accurate entry point for subsequent calls to conversion processors, ensuring the continuity of data flow and the correctness of conversion logic.
[0052] S4, the currently input token object is passed to the target transformation processor, and the target transformation processor parses the currently input token object to generate at least one block structure that conforms to the Notion API specification.
[0053] In practice, after determining the target conversion processor, the converter factory passes the currently input tag object to that target conversion processor. This passing can be done by directly calling a method of the processor and passing the tag object as a parameter.
[0054] After receiving a tagged object, the target transformation processor begins parsing it. Parsing involves reading the text content, attribute information, and any sub-tagged objects carried within the tagged object. For example, for a heading-type tagged object, the processor extracts the heading level (e.g., Heading 1) and the heading text content; for a bold text tagged object, the processor extracts the bolded text content. Further, after parsing, the processor constructs one or more block structure objects according to the Notion API's definition of block structures. The Notion API's block structure is a standardized data format, with each block structure containing type fields (e.g., paragraph, Heading 1, Heading 2, list item, etc.) and content fields (e.g., rich text arrays, color, indentation level, etc.). The processor then fills the parsed text content and attribute information into the corresponding fields, generating a block structure object conforming to the Notion specification. Some tagged objects may correspond to multiple block structures; for example, a complex list may generate multiple list item blocks.
[0055] In some preferred embodiments, the step of parsing the currently input tokenized object through the target transformation processor to generate at least one block structure conforming to the Notion API specification includes: reading the content fields of the tokenized object through the target transformation processor to extract text content and attribute information; and constructing at least one block structure object according to the field specification of the Notion API block structure based on the type identifier of the tokenized object, combined with the text content and the attribute information.
[0056] In practice, the target transformation processor first reads the content field of the marked object. The content field contains specific information about the element, such as text content, attribute parameters, and possibly nested child elements. Further, the target transformation processor parses the content field, extracting the text content and attribute information. The text content refers to the text actually written by the user, such as heading text or paragraph text. Attribute information includes additional formatting data, such as heading level, list number type, and code block language.
[0057] Furthermore, the target transformation processor constructs at least one block structure object based on the type identifier of the tag object, combined with the extracted text content and attribute information, and in accordance with the Notion API block structure field specifications. The Notion API defines a series of block types, such as paragraph blocks, heading 1 blocks, heading 2 blocks, list item blocks, code blocks, etc., each with specific field requirements. The target transformation processor determines the block type to be generated based on the type identifier and then fills the corresponding fields with the extracted text content and attribute information. For example, for a tag object with the type identifier "heading" and a level of 1, the processor constructs a block of type heading_1 and fills the heading text into the rich text field. For complex tag objects, such as quoting blocks containing multiple paragraphs, the target transformation processor may need to construct multiple block structure objects and combine them together through nesting. After construction, the target transformation processor outputs one or more block structure objects that fully conform to the Notion API data format requirements.
[0058] This embodiment uses a target conversion processor to read content fields, extract text content and attribute information, and construct block structure objects according to the Notion API specification, achieving a precise conversion from markup objects to block structures. This process fully preserves the text content and formatting attributes of the original Markdown, ensuring that the converted block structure is visually consistent with the original text. Furthermore, due to strict adherence to the Notion API field specifications, the generated block structure can be correctly parsed and rendered by the Notion server, avoiding API call failures or abnormal page display caused by format inconsistencies. Moreover, the target conversion processor employs specific construction logic for different types of markup objects, ensuring the accuracy and fine-grained control of the conversion.
[0059] S5, store at least one block structure generated by the target conversion processor into a block structure set.
[0060] In practice, at least one block structure generated by the target transformation processor is stored in a block structure collection. This collection can be a list or an array, used to temporarily store all generated block structure objects. Initially, the block structure collection is empty; after processing each marked object, the resulting block structure is appended to the end of the collection.
[0061] In some preferred embodiments, storing at least one block structure generated by the target conversion processor into a block structure set includes: creating an empty block structure list as the block structure set; and for each marked object, sequentially appending at least one block structure object generated by the target conversion processor to the block structure list according to the order of the marked objects in the marked object list.
[0062] In practice, firstly, an empty list of block structures is created, which serves as the collection of block structures. This list is used to sequentially store the block structure objects obtained after the transformation of all marked objects.
[0063] Furthermore, for each markup object, at least one block structure object generated by the target transformation processor is appended to the block structure list in the order it appeared in the original markup object list. Specifically, when processing the markup object list, a loop is used to iterate through it. For each markup object processed, one or more corresponding block structure objects are obtained, and these block structure objects are then added to the end of the block structure list in the order they were generated. This ensures that the order of elements in the block structure list strictly matches the order of the original markup object list, thus maintaining the original order of the Markdown document content. If a markup object generates multiple block structures, these block structures are also consecutively listed to reflect the logical order within the markup object.
[0064] This embodiment ensures that the final output list of block structures perfectly matches the content order of the original Markdown document by creating an empty list and appending the block structures sequentially according to the original order of the marked objects. Maintaining this order is crucial for the document's readability and structural integrity; for example, the order of paragraphs after headings and list items must be identical to the original text to ensure correct formatting in the Notion page. Accurate restoration of the order avoids content errors caused by disordered ordering, guaranteeing a superior user reading experience. Furthermore, this step aggregates the scattered block structures into an ordered list, providing formatted data input for subsequent Notion API calls and simplifying the preparation work for API calls.
[0065] S6. After processing all the marked objects in the marked object list, output the block structure set as a list of Notion API applicable structures.
[0066] In practice, the above process is repeated, processing each tag object in the tag object list sequentially until all tag objects have been processed. At this point, the block structure set contains a complete sequence of block structures corresponding to all elements of the original Markdown text.
[0067] Furthermore, the collection of block structures is output as a list of structures applicable to the Notion API. This list is the final result and can be directly used as the payload for Notion API requests to create new Notion pages or update the content of existing pages. By calling the Notion API and sending the list to the Notion server, formatted document pages are generated in the Notion workspace, where all content is presented in the original Markdown style.
[0068] In this embodiment, the data flow of the entire method is clear: the input is a Markdown text string, which is parsed to obtain a list of marked objects; the marked objects are input into the converter factory, and after being dispatched by the factory, they are converted into block structures by the target conversion processor; the block structures are stored in a set, and the final output is a list of block structures. The data transfer between each step has a clear input-output relationship, ensuring the integrity and traceability of the conversion process.
[0069] This invention generates a list of markup objects by parsing Markdown text and dynamically allocates appropriate conversion processors based on the type of the markup objects using a converter factory, thus achieving automated conversion from Markdown to Notion block structures. Furthermore, because the conversion processors handle different types of markup objects specifically, the accuracy and precision of the conversion logic are ensured, avoiding formatting errors that might result from uniform processing. The final generated block structure list is strictly compatible with the Notion API and can be directly used for Notion page creation or updates, effectively solving the problem that Markdown text cannot be directly formatted and displayed in Notion. This method provides developers with an efficient and reliable solution for importing Markdown content into Notion, significantly improving the efficiency and accuracy of content migration while reducing the labor costs of manual reformatting.
[0070] In some preferred embodiments, after outputting the block structure set as a Notion API applicable structure list, the method further includes: using the Notion API applicable structure list as a request body, calling the Notion API's page creation interface or page update interface, and sending the block structure list to the Notion server.
[0071] In practice, the first step is to use the list of Notion API-compatible structs obtained from the request as the request body. This list is JSON data conforming to the Notion API specification and contains all content blocks of the page.
[0072] Furthermore, call the Notion API's page creation or page update interfaces. The page creation interface is used to create a new page in the Notion workspace, while the page update interface is used to modify the content of an existing page. Choose the appropriate interface based on the application scenario. When calling, embed the aforementioned block structure list as part of the request body into the HTTP request and send it to the Notion server. The request must also include necessary authentication information, such as the Notion API key, to authorize access to the user's Notion workspace.
[0073] Furthermore, upon receiving the request, the Notion server parses the list of block structures in the request body and creates or updates the corresponding page in the workspace. The page content is then displayed in a formatted manner according to the block structure definition. At this point, the Markdown text has been successfully converted into a Notion page and stored in the Notion platform.
[0074] This invention, through a further invocation of the Notion API after generating the block structure list, directly sends the conversion result to the Notion server, achieving a completely automated process from Markdown text to Notion page storage. Furthermore, this step streamlines the conversion and platform integration, allowing developers to import Markdown content into Notion with a single click, without manually copying and pasting or writing additional API call code. Moreover, the flexibility of calling the page creation or update API meets the different needs of adding new documents and modifying existing ones. The entire process is seamlessly integrated, greatly improving the efficiency of content management and migration.
[0075] Please see Figure 2 , Figure 2 This is a schematic block diagram of a computer device provided in an embodiment of this application. The computer device 500 can be a terminal or a server, wherein the server can be a standalone server or a server cluster composed of multiple servers.
[0076] The computer device 500 includes a processor 502, a memory, and a network interface 505 connected via a system bus 501. The memory may include a non-volatile storage medium 503 and internal memory 504.
[0077] The non-volatile storage medium 503 may store an operating system 5031 and a computer program 5032. When the computer program 5032 is executed, it causes the processor 502 to perform a method for converting Markdown into a Notion API-compatible structure.
[0078] The processor 502 provides computing and control capabilities to support the operation of the entire computer device 500.
[0079] The internal memory 504 provides an environment for the execution of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can perform a method to convert Markdown into a NotionAPI applicable structure.
[0080] The network interface 505 is used for network communication with other devices. Those skilled in the art will understand that the above structure is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device 500 to which the present application is applied. A specific computer device 500 may include more or fewer components than shown in the figures, or combine certain components, or have different component arrangements.
[0081] The processor 502 is used to run a computer program 5032 stored in the memory to perform the following steps: Obtain the Markdown text string, call the parser to parse the Markdown text string, and generate a list of markup objects. Each markup object in the list of markup objects has a corresponding type identifier. Initialize the converter factory, which maintains multiple conversion processors; The marked objects in the marked object list are sequentially input into the converter factory. The converter factory then matches the corresponding target converter from the plurality of converters based on the type identifier of the currently input marked object. The currently input token object is passed to the target transformation processor, which parses the currently input token object to generate at least one block structure that conforms to the Notion API specification. Store at least one block structure generated by the target conversion processor into a block structure set; After processing all the marked objects in the marked object list, the block structure set is output as a list of Notion API applicable structures.
[0082] Optionally, the parser is invoked to parse the Markdown text string and generate a list of markup objects, including: Call the parsing interface of the mistune library and pass the Markdown text string as an input parameter to the mistune library; Receive the parsing result returned by the mistune library. The parsing result is a tree-structured list of marked objects. Each marked object in the list contains a type field and a content field.
[0083] Optionally, the initialization converter factory includes: Create a converter factory instance; Register multiple conversion processors in the converter factory instance; Establish a mapping relationship between type identifiers and conversion processors, and store the mapping relationship in the converter factory instance.
[0084] Optionally, the step of matching the corresponding target conversion processor from the plurality of conversion processors based on the type identifier of the currently input marked object through the converter factory includes: The converter factory reads the type field of the currently input marked object to obtain the type identifier; The converter factory queries the mapping relationship based on the type identifier to find the conversion processor corresponding to the type identifier; If a corresponding conversion processor is found, the found conversion processor will be designated as the target conversion processor.
[0085] Optionally, the step of parsing the currently input tokenized object through the target transformation processor to generate at least one block structure conforming to the Notion API specification includes: The target conversion processor reads the content field of the marked object and extracts the text content and attribute information. The target transformation processor constructs at least one block structure object according to the type identifier of the marked object, the text content, and the attribute information, in accordance with the field specification of the Notion API block structure.
[0086] Optionally, storing at least one block structure generated by the target conversion processor into a block structure set includes: Create an empty list of block structures as the block structure set; For each tagged object, at least one block structure object generated by the target transformation processor is sequentially appended to the block structure list according to the order in which the tagged objects are in the tagged object list.
[0087] Optionally, after outputting the block structure set as a list of Notion API-applicable structures, the method further includes: The Notion API uses the list of applicable structures as the request body to call the Notion API's page creation or page update interface, and sends the list of block structures to the Notion server.
[0088] Optionally, the tag objects in the tag object list include at least one of paragraph type tag objects, heading type tag objects, list type tag objects, and code block type tag objects; The plurality of conversion processors includes at least one of paragraph conversion processor, heading conversion processor, list conversion processor, and code block conversion processor; The paragraph conversion processor is used to process the paragraph type tag object, the heading conversion processor is used to process the heading type tag object, the list conversion processor is used to process the list type tag object, and the code block conversion processor is used to process the code block type tag object.
[0089] It should be understood that in the embodiments of this application, the processor 502 may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0090] It will be understood by those skilled in the art that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program may be stored in a storage medium, which is a computer-readable storage medium. The computer program is executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.
[0091] Therefore, the present invention also provides a storage medium. This storage medium can be a computer-readable storage medium. The storage medium stores a computer program. When executed by a processor, the computer program causes the processor to perform the following steps: Obtain the Markdown text string, call the parser to parse the Markdown text string, and generate a list of markup objects. Each markup object in the list of markup objects has a corresponding type identifier. Initialize the converter factory, which maintains multiple conversion processors; The marked objects in the marked object list are sequentially input into the converter factory. The converter factory then matches the corresponding target converter from the plurality of converters based on the type identifier of the currently input marked object. The currently input token object is passed to the target transformation processor, which parses the currently input token object to generate at least one block structure that conforms to the Notion API specification. Store at least one block structure generated by the target conversion processor into a block structure set; After processing all the marked objects in the marked object list, the block structure set is output as a list of Notion API applicable structures.
[0092] Optionally, the parser is invoked to parse the Markdown text string and generate a list of markup objects, including: Call the parsing interface of the mistune library and pass the Markdown text string as an input parameter to the mistune library; Receive the parsing result returned by the mistune library. The parsing result is a tree-structured list of marked objects. Each marked object in the list contains a type field and a content field.
[0093] Optionally, the initialization converter factory includes: Create a converter factory instance; Register multiple conversion processors in the converter factory instance; Establish a mapping relationship between type identifiers and conversion processors, and store the mapping relationship in the converter factory instance.
[0094] Optionally, the step of matching the corresponding target conversion processor from the plurality of conversion processors based on the type identifier of the currently input marked object through the converter factory includes: The converter factory reads the type field of the currently input marked object to obtain the type identifier; The converter factory queries the mapping relationship based on the type identifier to find the conversion processor corresponding to the type identifier; If a corresponding conversion processor is found, the found conversion processor will be designated as the target conversion processor.
[0095] Optionally, the step of parsing the currently input tokenized object through the target transformation processor to generate at least one block structure conforming to the Notion API specification includes: The target conversion processor reads the content field of the marked object and extracts the text content and attribute information. The target transformation processor constructs at least one block structure object according to the type identifier of the marked object, the text content, and the attribute information, in accordance with the field specification of the Notion API block structure.
[0096] Optionally, storing at least one block structure generated by the target conversion processor into a block structure set includes: Create an empty list of block structures as the block structure set; For each tagged object, at least one block structure object generated by the target transformation processor is sequentially appended to the block structure list according to the order in which the tagged objects are in the tagged object list.
[0097] Optionally, after outputting the block structure set as a list of Notion API-applicable structures, the method further includes: The Notion API uses the list of applicable structures as the request body to call the Notion API's page creation or page update interface, and sends the list of block structures to the Notion server.
[0098] Optionally, the tag objects in the tag object list include at least one of paragraph type tag objects, heading type tag objects, list type tag objects, and code block type tag objects; The plurality of conversion processors includes at least one of paragraph conversion processor, heading conversion processor, list conversion processor, and code block conversion processor; The paragraph conversion processor is used to process the paragraph type tag object, the heading conversion processor is used to process the heading type tag object, the list conversion processor is used to process the list type tag object, and the code block conversion processor is used to process the code block type tag object.
[0099] The storage medium is a physical, non-transient storage medium, such as a USB flash drive, external hard drive, read-only memory (ROM), magnetic disk, or optical disk, or any other physical storage medium capable of storing program code. The computer-readable storage medium can be non-volatile or volatile.
[0100] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0101] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of each unit is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
[0102] The steps in the method of this invention can be adjusted, merged, or reduced in order according to actual needs. The units in the device of this invention can be merged, divided, or reduced according to actual needs. Furthermore, the functional units in the various embodiments of this invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0103] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.
[0104] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0105] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Since these modifications and variations fall within the scope of the claims and their equivalents, this invention also intends to include these modifications and variations.
[0106] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for converting Markdown into a Notion API-compatible struct, characterized in that, include: Obtain the Markdown text string, call the parser to parse the Markdown text string, and generate a list of markup objects. Each markup object in the list of markup objects has a corresponding type identifier. Initialize the converter factory, which maintains multiple conversion processors; The marked objects in the marked object list are sequentially input into the converter factory. The converter factory then matches the corresponding target converter from the plurality of converters based on the type identifier of the currently input marked object. The currently input token object is passed to the target transformation processor, which parses the currently input token object to generate at least one block structure that conforms to the Notion API specification. Store at least one block structure generated by the target conversion processor into a block structure set; After processing all the marked objects in the marked object list, the block structure set is output as a list of Notion API applicable structures.
2. The method for converting Markdown into a Notion API-compatible struct according to claim 1, characterized in that, The parser is invoked to parse the Markdown text string and generate a list of markup objects, including: Call the parsing interface of the mistune library and pass the Markdown text string as an input parameter to the mistune library; Receive the parsing result returned by the mistune library. The parsing result is a tree-structured list of marked objects. Each marked object in the list contains a type field and a content field.
3. The method for converting Markdown into a Notion API-compatible struct according to claim 1, characterized in that, The initialization converter factory includes: Create a converter factory instance; Register multiple conversion processors in the converter factory instance; Establish a mapping relationship between type identifiers and conversion processors, and store the mapping relationship in the converter factory instance.
4. The method for converting Markdown into a Notion API-compatible struct according to claim 3, characterized in that, The step of matching the corresponding target conversion processor from the plurality of conversion processors based on the type identifier of the currently input marked object through the converter factory includes: The converter factory reads the type field of the currently input marked object to obtain the type identifier; The converter factory queries the mapping relationship based on the type identifier to find the conversion processor corresponding to the type identifier; If a corresponding conversion processor is found, the found conversion processor will be designated as the target conversion processor.
5. The method for converting Markdown into a Notion API-compatible struct according to claim 1, characterized in that, The step of parsing the currently input tokenized object through the target transformation processor to generate at least one block structure conforming to the Notion API specification includes: The target conversion processor reads the content field of the marked object and extracts the text content and attribute information. The target transformation processor constructs at least one block structure object according to the type identifier of the marked object, the text content, and the attribute information, in accordance with the field specification of the Notion API block structure.
6. The method for converting Markdown into a Notion API-compatible struct according to claim 1, characterized in that, The step of storing at least one block structure generated by the target conversion processor into a block structure set includes: Create an empty list of block structures as the block structure set; For each tagged object, at least one block structure object generated by the target transformation processor is sequentially appended to the block structure list according to the order in which the tagged objects are in the tagged object list.
7. The method for converting Markdown into a Notion API-compatible struct according to claim 1, characterized in that, After outputting the block structure set as a list of Notion API-applicable structures, the process also includes: The Notion API uses the list of applicable structures as the request body to call the Notion API's page creation or page update interface, and sends the list of block structures to the Notion server.
8. The method for converting Markdown into a Notion API-compatible struct according to claim 1, characterized in that, The tag objects in the tag object list include at least one of the following: paragraph type tag objects, heading type tag objects, list type tag objects, and code block type tag objects; The plurality of conversion processors includes at least one of paragraph conversion processor, heading conversion processor, list conversion processor, and code block conversion processor; The paragraph conversion processor is used to process the paragraph type tag object, the heading conversion processor is used to process the heading type tag object, the list conversion processor is used to process the list type tag object, and the code block conversion processor is used to process the code block type tag object.
9. A computer device, characterized in that, The computer device includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the method as described in any one of claims 1-8.
10. A computer-readable storage medium, characterized in that, The storage medium stores a computer program that, when executed by a processor, can implement the method as described in any one of claims 1-8.