Skip to content

Commit 9de184f

Browse files
committed
Simplify labeling of plugins
1 parent 0a549ae commit 9de184f

File tree

7 files changed

+11
-28
lines changed

7 files changed

+11
-28
lines changed

src/config/configuration.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// an extension manager that uses cosmicconfig to get a list of plugin functions
22
// and then runs them in sequence
33

4-
import {
5-
ListBlockChildrenResponseResult,
6-
ListBlockChildrenResponseResults,
7-
} from "notion-to-md/build/types";
4+
import { ListBlockChildrenResponseResult } from "notion-to-md/build/types";
85
import * as Cosmic from "cosmiconfig";
96
import { CosmiconfigResult } from "cosmiconfig/dist/types";
107
import { NotionPage } from "../NotionPage";
@@ -27,7 +24,6 @@ export type IPlugin = {
2724
name: string;
2825
// operations on notion blocks before they are converted to markdown
2926
notionBlockModifications?: {
30-
label: string;
3127
modify: (block: NotionBlock) => void;
3228
}[];
3329
// overrides for the default notion-to-markdown conversions
@@ -41,7 +37,6 @@ export type IPlugin = {
4137

4238
// corrections to links after they are converted to markdown
4339
linkModifier?: {
44-
label: string;
4540
match: RegExp; // does this plugin apply to this link?
4641
convert: linkConversionFunction;
4742
};
@@ -51,7 +46,6 @@ export type IPlugin = {
5146
};
5247

5348
export type IRegexMarkdownModification = {
54-
label: string;
5549
regex: RegExp;
5650
output: string;
5751
imports?: string[];
@@ -82,22 +76,12 @@ export type IDocuNotionContext = {
8276
relativeFilePathToFolderContainingPage: string;
8377
pages: NotionPage[];
8478
counts: ICounts;
85-
// log: {
86-
// error(s: string): void;
87-
// warning(s: string): void;
88-
// info(s: string): void;
89-
// verbose(s: string): void;
90-
// debug(s: string): void;
91-
// };
9279
};
9380

94-
//let config: IDocuNotionConfig | undefined;
95-
9681
// read the plugins from the config file
9782
// and add them to the map
9883
export function loadConfig(): IDocuNotionConfig {
9984
// return Cosmic.cosmiconfigSync("docunotion").search()
100-
// ?.config as IDocuNotionConfig;
10185

10286
return defaultConfig;
10387
}

src/plugins/EscapeHtmlBlockModifier.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export const standardEscapeHtmlBlockModifier: IPlugin = {
55

66
notionBlockModifications: [
77
{
8-
label: "standardEscapeHtmlBlockModifier",
98
modify: (block: NotionBlock) => {
109
escapeHtml(block);
1110
},

src/plugins/HeadingTransformer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export const standardHeadingTransformer: IPlugin = {
3535
// result, to which we will append the block ID to enable heading links.
3636
notionBlockModifications: [
3737
{
38-
label: "headingTransformer",
3938
modify: (block: NotionBlock) => {
4039
// "as any" needed because we're putting a value in that is not allowed by the real type
4140
(block as any).type = block.type.replace("heading", "DN_heading");

src/plugins/embedTweaks.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export const gifEmbed: IPlugin = {
44
name: "gif",
55
regexMarkdownModifications: [
66
{
7-
label: "gif",
87
// I once saw a gif coming from Notion that wasn't a full
98
// url, which wouldn't work, hence the "http" requirement
109
regex: /\[.*\]\((http.*(\.(gif|GIF)))\)/gm,
@@ -17,7 +16,6 @@ export const imgurGifEmbed: IPlugin = {
1716
name: "imgur",
1817
regexMarkdownModifications: [
1918
{
20-
label: "imgur",
2119
regex: /\[.*\]\((.*imgur\.com\/.*)\)/gm, // imgur.com
2220
// imgur links to gifs need a .gif at the end, but the url they give you doesn't have one.
2321
output: `![]($1.gif)`,
@@ -28,7 +26,6 @@ export const youtubeEmbed: IPlugin = {
2826
name: "youtube",
2927
regexMarkdownModifications: [
3028
{
31-
label: "youtube",
3229
regex: /\[.*\]\((.*youtube\.com\/watch.*)\)/gm, //youtube.com/watch
3330
imports: [`import ReactPlayer from "react-player";`],
3431
output: `<ReactPlayer controls url="$1" />`,
@@ -39,7 +36,6 @@ export const vimeoEmbed: IPlugin = {
3936
name: "vimeo",
4037
regexMarkdownModifications: [
4138
{
42-
label: "vimeo",
4339
regex: /\[.*\]\((https:\/\/.*vimeo.*)\)/gm,
4440
// we use to have the following, but the above should handle both the player an not-player urls.
4541
//regex: /\[.*\]\((.*player\.vimeo.*)\)/gm, // player.vimeo

src/plugins/externalLinks.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { error, warning } from "../log";
44
export const standardExternalLinkConversion: IPlugin = {
55
name: "standard external link conversion",
66
linkModifier: {
7-
label: "standard external link conversion",
87
match: /\[.*\]\(http.*\)/,
98
convert: (context: IDocuNotionContext, markdownLink: string) => {
109
const linkRegExp = /\[([^\]]+)?\]\((http.*)\)/;

src/plugins/internalLinks.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ export function parseLinkId(fullLinkId: string): {
8787
export const standardInternalLinkConversion: IPlugin = {
8888
name: "standard internal link conversion",
8989
linkModifier: {
90-
label: "standard internal link conversion",
9190
// from notion (or notion-md?) we get slightly different hrefs depending on whether the links is "inline"
9291
// (has some other text that's been turned into a link) or "raw".
9392
// Raw links come in without a leading slash, e.g. [link_to_page](4a6de8c0-b90b-444b-8a7b-d534d6ec71a4)

src/transform.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ function doNotionBlockTransforms(
8484
function doTransformsOnMarkdown(config: IDocuNotionConfig, input: string) {
8585
const regexMods: IRegexMarkdownModification[] = config.plugins
8686
.filter(plugin => !!plugin.regexMarkdownModifications)
87-
.map(plugin => plugin.regexMarkdownModifications!)
87+
.map(plugin => {
88+
const mods = plugin.regexMarkdownModifications!;
89+
// stick the name of the plugin into each mode for logging
90+
const modsWithNames = mods.map(m => ({ name: plugin.name, ...m }));
91+
return modsWithNames;
92+
})
8893
.flat();
8994

9095
let body = input;
@@ -94,11 +99,13 @@ function doTransformsOnMarkdown(config: IDocuNotionConfig, input: string) {
9499

95100
// eslint-disable-next-line @typescript-eslint/no-unused-vars
96101
regexMods.forEach(mod => {
97-
//verbose(`Trying [${mod.label}]`);
102+
//verbose(`Trying [${mod.name}]`);
98103
while ((match = mod.regex.exec(input)) !== null) {
99104
const string = match[0];
100105
const url = match[1];
101-
verbose(`[${mod.label}] ${string} --> ${mod.output.replace("$1", url)}`);
106+
verbose(
107+
`[${(mod as any).name}] ${string} --> ${mod.output.replace("$1", url)}`
108+
);
102109
body = body.replace(string, mod.output.replace("$1", url));
103110
// add any library imports
104111
mod.imports?.forEach(imp => imports.add(imp));

0 commit comments

Comments
 (0)