generated from ryansonshine/typescript-npm-package-template
-
Notifications
You must be signed in to change notification settings - Fork 31
/
pluginTypes.ts
89 lines (77 loc) · 3.23 KB
/
pluginTypes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { ListBlockChildrenResponseResult } from "notion-to-md/build/types";
import { NotionPage } from "../NotionPage";
import { NotionToMarkdown } from "notion-to-md";
import { DocuNotionOptions } from "../pull";
import { LayoutStrategy } from "../LayoutStrategy";
import { ICounts, NotionBlock } from "../index";
type linkConversionFunction = (
context: IDocuNotionContext,
markdownLink: string
) => string;
export type IPlugin = {
// this is just for display when debugging
name: string;
// operations on notion blocks before they are converted to markdown
notionBlockModifications?: {
modify: (block: NotionBlock) => void;
}[];
// overrides for the default notion-to-markdown conversions
notionToMarkdownTransforms?: {
type: string;
getStringFromBlock: (
context: IDocuNotionContext,
block: NotionBlock
) => string | Promise<string>;
}[];
// corrections to links after they are converted to markdown
linkModifier?: {
match: RegExp; // does this plugin apply to this link?
convert: linkConversionFunction;
};
// simple regex replacements on the markdown output
regexMarkdownModifications?: IRegexMarkdownModification[];
// Allow a plugin to perform an async operation at the start of docu-notion.
// Notice that the plugin itself is given, so you can add things to it.
init?(plugin: IPlugin): Promise<void>;
};
export type IRegexMarkdownModification = {
// Should match on markdown that you want to replace
regex: RegExp;
// Based on that regex, the outputPattern will be used to replace the matched text
replacementPattern?: string;
// Instead of a pattern, you can use this if you have to ask a server somewhere for help in getting the new markdown
getReplacement?(
context: IDocuNotionContext,
match: RegExpExecArray
): Promise<string>;
// normally, anything in code blocks is will be ignored. If you want to make changes inside of code blocks, set this to true.
includeCodeBlocks?: boolean;
// If the output is creating things like react elements, you can append their import definitions
// to this array so they get added to the page.
// e.g. mod.imports.push(`import ReactPlayer from "react-player";`);
imports?: string[];
};
export type ICustomNotionToMarkdownConversion = (
block: ListBlockChildrenResponseResult,
context: IDocuNotionContext
) => () => Promise<string>;
export type IGetBlockChildrenFn = (id: string) => Promise<NotionBlock[]>;
export type IDocuNotionContext = {
layoutStrategy: LayoutStrategy;
options: DocuNotionOptions;
getBlockChildren: IGetBlockChildrenFn;
notionToMarkdown: NotionToMarkdown;
pageInfo: IDocuNotionContextPageInfo;
convertNotionLinkToLocalDocusaurusLink: (url: string) => string | undefined;
pages: NotionPage[];
counts: ICounts;
// If the output is creating things like react elements, you can append their import definitions
// to this array so they get added to the page.
// e.g. context.imports.push(`import ReactPlayer from "react-player";`);
imports: string[];
};
export type IDocuNotionContextPageInfo = {
directoryContainingMarkdown: string;
relativeFilePathToFolderContainingPage: string;
slug: string;
};