Skip to content

Commit

Permalink
add: string union for Block Type instead of string #83
Browse files Browse the repository at this point in the history
  • Loading branch information
souvikinator committed May 20, 2023
1 parent 06a9404 commit 2c9b9c0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/notion-to-md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Text,
ConfigurationOptions,
MdStringObject,
BlockType,
} from "./types";
import * as md from "./utils/md";
import { getBlockChildren } from "./utils/notion";
Expand All @@ -36,7 +37,7 @@ export class NotionToMarkdown {
}

setCustomTransformer(
type: string,
type: BlockType,
transformer: CustomTransformer
): NotionToMarkdown {
this.customTransformers[type] = transformer;
Expand Down
48 changes: 46 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Client } from "@notionhq/client";
import type { ListBlockChildrenResponse } from "@notionhq/client/build/src/api-endpoints";
import type {
ListBlockChildrenResponse,
GetBlockParameters,
} from "@notionhq/client/build/src/api-endpoints";

export type BlockAttributes = {
numbered_list_item?: {
number?: number;
};
};

export type ListBlockChildrenResponseResults =
ListBlockChildrenResponse["results"] & BlockAttributes;

Expand All @@ -14,6 +18,46 @@ export type ListBlockChildrenResponseResult =

export type TextRequest = string;

export type BlockType =
| "image"
| "video"
| "file"
| "pdf"
| "table"
| "bookmark"
| "embed"
| "equation"
| "divider"
| "toggle"
| "to_do"
| "bulleted_list_item"
| "numbered_list_item"
| "synced_block"
| "column_list"
| "column"
| "link_preview"
| "link_to_page"
| "paragraph"
| "heading_1"
| "heading_2"
| "heading_3"
| "bulleted_list_item"
| "numbered_list_item"
| "quote"
| "to_do"
| "template"
| "synced_block"
| "child_page"
| "child_database"
| "code"
| "callout"
| "breadcrumb"
| "table_of_contents"
| "link_to_page"
| "audio"
| "unsupported"
| string;

export type ConfigurationOptions = {
separateChildPage?: boolean;
convertImagesToBase64?: boolean;
Expand Down Expand Up @@ -98,4 +142,4 @@ export type CalloutIcon =

export type CustomTransformer = (
block: ListBlockChildrenResponseResult
) => string | Promise<string>;
) => BlockType | Promise<string>;

0 comments on commit 2c9b9c0

Please sign in to comment.