notion2hast 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  ## Installtion
8
8
 
9
9
  ```console
10
- $ npm install --save notion2hast
10
+ npm install --save notion2hast
11
11
  ```
12
12
 
13
13
  ## Security
@@ -235,6 +235,7 @@ const client = new FromNotion({
235
235
  - [x] heading_1
236
236
  - [x] heading_2
237
237
  - [x] heading_3
238
+ - [x] heading_4
238
239
  - [x] bulleted_list_item
239
240
  - [x] numbered_list_item
240
241
  - [x] quote
@@ -311,6 +312,7 @@ const client = new FromNotion({
311
312
  - `heading-1`
312
313
  - `heading-2`
313
314
  - `heading-3`
315
+ - `heading-4`
314
316
  - `code`
315
317
  - `code-pre`
316
318
  - `code-code`
package/dist/cli.js CHANGED
@@ -3,6 +3,7 @@ import { Client as NotionClient } from '@notionhq/client';
3
3
  import { Client } from './lib/client.js';
4
4
  import { blockToHast } from './lib/notion2hast.js';
5
5
  class CliClient extends Client {
6
+ client;
6
7
  constructor(options) {
7
8
  super();
8
9
  this.client = new NotionClient(options);
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { blockToHast } from './lib/notion2hast.js';
2
- export { Client } from './lib/client.js';
1
+ export { blockToHast } from './lib/notion2hast.ts';
2
+ export { Client } from './lib/client.ts';
@@ -1,8 +1,8 @@
1
1
  import type { Child, Properties } from 'hastscript';
2
- import { Block, BlockToHastBuilderOpts, BlockToHastBuilderPropertiesKey, BlockToHastBuilderPropertiesMap, BlockToHastOpts, ToHastOpts } from './types.js';
3
- import { RichTextToHast } from './richtext.js';
4
- import { Client } from './client.js';
5
- import { ColorProps } from './color.js';
2
+ import type { Block, BlockToHastBuilderOpts, BlockToHastBuilderPropertiesKey, BlockToHastBuilderPropertiesMap, BlockToHastOpts, ToHastOpts } from './types.ts';
3
+ import { RichTextToHast } from './richtext.ts';
4
+ import { Client } from './client.ts';
5
+ import { ColorProps } from './color.ts';
6
6
  export declare function isBlock(o: any): o is Block;
7
7
  export declare class BlockItem {
8
8
  private client;
@@ -72,6 +72,15 @@ export declare class BlockHeading3ToHast extends BlockToHastBuilder<'heading_3'>
72
72
  build({ block, nest, richTextToHast, colorProps }: BlockToHastBuilderBuildOpts): Promise<Child[]>;
73
73
  isBreak(_prevType: PrevType): boolean;
74
74
  }
75
+ export declare class BlockHeading4ToHast extends BlockToHastBuilder<'heading_4'> {
76
+ constructor(opts?: BlockToHastBuilderOpts);
77
+ outerTag(): {
78
+ name: string | null;
79
+ properties?: Properties;
80
+ };
81
+ build({ block, nest, richTextToHast, colorProps }: BlockToHastBuilderBuildOpts): Promise<Child[]>;
82
+ isBreak(_prevType: PrevType): boolean;
83
+ }
75
84
  export declare class BlockCodeToHast extends BlockToHastBuilder<'code'> {
76
85
  constructor(opts?: BlockToHastBuilderOpts);
77
86
  outerTag(): {
package/dist/lib/block.js CHANGED
@@ -8,6 +8,12 @@ export function isBlock(o) {
8
8
  return false;
9
9
  }
10
10
  export class BlockItem {
11
+ client;
12
+ opts;
13
+ blocks;
14
+ next_cursor;
15
+ blocksLen;
16
+ idx;
11
17
  constructor(client, opts) {
12
18
  this.client = client;
13
19
  this.opts = opts;
@@ -53,8 +59,10 @@ export class BlockItem {
53
59
  }
54
60
  }
55
61
  export class BlockToHastBuilder {
62
+ blockType;
63
+ defaultClassname;
64
+ propertiesMap = {};
56
65
  constructor(blockType, opts) {
57
- this.propertiesMap = {};
58
66
  this.blockType = blockType;
59
67
  this.defaultClassname = opts.defaultClassname || false;
60
68
  this.propertiesMap = { ...(opts.propertiesMap || {}) };
@@ -145,6 +153,25 @@ export class BlockHeading3ToHast extends BlockToHastBuilder {
145
153
  return true;
146
154
  }
147
155
  }
156
+ export class BlockHeading4ToHast extends BlockToHastBuilder {
157
+ constructor(opts = {}) {
158
+ super('heading_4', opts);
159
+ }
160
+ outerTag() {
161
+ return { name: null };
162
+ }
163
+ async build({ block, nest, richTextToHast, colorProps }) {
164
+ if (this.blockType === block.type) {
165
+ return [
166
+ h('h4', mergeProps(this.props('heading-4'), colorProps.props(block[block.type].color)), ...(await richTextToHast.build(block[block.type].rich_text)), ...nest)
167
+ ];
168
+ }
169
+ return [];
170
+ }
171
+ isBreak(_prevType) {
172
+ return true;
173
+ }
174
+ }
148
175
  export class BlockCodeToHast extends BlockToHastBuilder {
149
176
  constructor(opts = {}) {
150
177
  super('code', opts);
@@ -471,12 +498,15 @@ export class BlockImageToHast extends BlockToHastBuilder {
471
498
  }
472
499
  }
473
500
  export class SurroundElement {
501
+ prevType = '';
502
+ children = [];
474
503
  defaultBlockToHastBuilders(opts) {
475
504
  return {
476
505
  paragraph: new BlockParagraphToHast(opts),
477
506
  heading_1: new BlockHeading1ToHast(opts),
478
507
  heading_2: new BlockHeading2ToHast(opts),
479
508
  heading_3: new BlockHeading3ToHast(opts),
509
+ heading_4: new BlockHeading4ToHast(opts),
480
510
  code: new BlockCodeToHast(opts),
481
511
  callout: new BlockCalloutToHast(opts),
482
512
  divider: new BlockDividerToHast(opts),
@@ -493,10 +523,8 @@ export class SurroundElement {
493
523
  image: new BlockImageToHast(opts)
494
524
  };
495
525
  }
526
+ blockToHastBuilders = {};
496
527
  constructor(initType, opts = {}) {
497
- this.prevType = '';
498
- this.children = [];
499
- this.blockToHastBuilders = {};
500
528
  this.prevType = initType;
501
529
  const buildersOpts = opts.blockToHastBuilderOpts || {};
502
530
  if (typeof buildersOpts.defaultClassname === 'undefined') {
@@ -1,5 +1,5 @@
1
1
  import type { Properties } from 'hastscript';
2
- import { ColorPropsOpts } from './types';
2
+ import type { ColorPropsOpts } from './types.ts';
3
3
  export declare class ColorProps {
4
4
  private defaultColorPropertiesMap;
5
5
  private colorPropertiesMap;
package/dist/lib/color.js CHANGED
@@ -23,8 +23,8 @@ export class ColorProps {
23
23
  defaultColorPropertiesMap() {
24
24
  return colorPropertiesMap;
25
25
  }
26
+ colorPropertiesMap = {};
26
27
  constructor(opts) {
27
- this.colorPropertiesMap = {};
28
28
  Object.assign(this.colorPropertiesMap, this.defaultColorPropertiesMap(), opts.colorPropertiesMap || {});
29
29
  }
30
30
  props(color) {
@@ -1,4 +1,4 @@
1
1
  import type { Child } from 'hastscript';
2
- import { ToHastOpts } from './types.js';
3
- import { Client } from './client.js';
2
+ import type { ToHastOpts } from './types.ts';
3
+ import { Client } from './client.ts';
4
4
  export declare function blockToHast(client: Client, opts: ToHastOpts, depth?: number): Promise<Child>;
@@ -1,6 +1,6 @@
1
1
  import type { Child, Properties } from 'hastscript';
2
- import { ColorProps } from './color.js';
3
- import { RichTextItem, RichTexttoHastOpts } from './types.js';
2
+ import { ColorProps } from './color.ts';
3
+ import type { RichTextItem, RichTexttoHastOpts } from './types.ts';
4
4
  export type RichTextTextItem = Extract<RichTextItem, {
5
5
  type?: 'text';
6
6
  }>;
@@ -9,8 +9,10 @@ export function colorText(richTextColor) {
9
9
  return [richTextColor, ''];
10
10
  }
11
11
  export class RichTextToHast {
12
+ colorProps;
13
+ defaultClassName;
14
+ propertiesMap = {};
12
15
  constructor(opts = {}, colorProps) {
13
- this.propertiesMap = {};
14
16
  this.colorProps = colorProps || new ColorProps({});
15
17
  this.defaultClassName = opts.defaultClassName || false;
16
18
  Object.assign(this.propertiesMap, opts.richTexttoHastBuilderOpts?.richTexttoHastBuildePropertiesMap || {});
@@ -1,6 +1,6 @@
1
1
  import { Client } from '@notionhq/client';
2
2
  import type { Properties } from 'hastscript';
3
- import { BlockToHastBuilder } from './block';
3
+ import { BlockToHastBuilder } from './block.ts';
4
4
  export type ToHastOpts = {
5
5
  block_id: string;
6
6
  parent?: Block;
@@ -11,7 +11,7 @@ export type ToHastOpts = {
11
11
  export type Block = Extract<Awaited<ReturnType<InstanceType<typeof Client>['blocks']['retrieve']>>, {
12
12
  type: string;
13
13
  }>;
14
- export type BlockToHastBuilderPropertiesKey = `paragraph` | `heading-1` | `heading-2` | `heading-3` | `code` | `code-pre` | `code-code` | `code-caption` | `callout` | `callout-icon-emoji` | `callout-icon-image` | `callout-paragraph` | `divider` | `column-list` | `column` | `bulleted-list` | `bulleted-list-item` | `numbered-list` | `numbered-list-item` | `quote` | `todo` | `todo-checked` | `todo-not-checked` | `todo-text` | `toggle` | `toggle-summary` | `table` | `table-row` | `table-row-cell` | `table-row-header` | `table-row-header-top-left` | `table-row-header-top` | `table-row-header-left` | `bookmark` | `bookmark-link` | `bookmark-caption` | `image` | `image-img` | `image-caption` | `text-link` | `text-bold` | `text-code` | `text-italic` | `text-strikethrough` | `text-underline`;
14
+ export type BlockToHastBuilderPropertiesKey = `paragraph` | `heading-1` | `heading-2` | `heading-3` | `heading-4` | `code` | `code-pre` | `code-code` | `code-caption` | `callout` | `callout-icon-emoji` | `callout-icon-image` | `callout-paragraph` | `divider` | `column-list` | `column` | `bulleted-list` | `bulleted-list-item` | `numbered-list` | `numbered-list-item` | `quote` | `todo` | `todo-checked` | `todo-not-checked` | `todo-text` | `toggle` | `toggle-summary` | `table` | `table-row` | `table-row-cell` | `table-row-header` | `table-row-header-top-left` | `table-row-header-top` | `table-row-header-left` | `bookmark` | `bookmark-link` | `bookmark-caption` | `image` | `image-img` | `image-caption` | `text-link` | `text-bold` | `text-code` | `text-italic` | `text-strikethrough` | `text-underline`;
15
15
  export type BlockToHastBuilderPropertiesMap = {
16
16
  [key in BlockToHastBuilderPropertiesKey]?: Properties;
17
17
  };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "notion2hast",
3
- "version": "0.1.4",
3
+ "version": "0.2.0",
4
4
  "description": "Notion blocks to hast",
5
5
  "license": "MIT",
6
6
  "author": "hankei6km <hankei6km@gmail.com> (https://github.com/hankei6km)",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git@github.com:hankei6km/notion2hast.git"
9
+ "url": "git+https://github.com/hankei6km/notion2hast.git"
10
10
  },
11
11
  "bugs": {
12
12
  "url": "https://github.com/hankei6km/notion2hast/issues"
@@ -30,14 +30,16 @@
30
30
  },
31
31
  "scripts": {
32
32
  "start": "npm run build && node dist/main.js",
33
- "build": "npm run clean && tsc && rimraf dist/test && mv dist/src/* dist/ && rimraf dist/src",
34
- "test": "node --experimental-vm-modules node_modules/.bin/jest",
35
- "clean": "rimraf dist/",
36
- "upgrade-interactive": "npm-check --update",
37
- "csb:test": "npm test -- --runInBand --watchAll"
33
+ "start:ts": "node --experimental-strip-types src/main.ts",
34
+ "prebuild": "npm run clean",
35
+ "build": "tsc -p tsconfig.build.json",
36
+ "test": "node --experimental-test-module-mocks --experimental-test-module-mocks --experimental-strip-types --test",
37
+ "test:coverage": "npm run test -- --experimental-test-coverage",
38
+ "lint:types": "tsc --noEmit -p tsconfig.json",
39
+ "clean": "rm -rf dist/*"
38
40
  },
39
41
  "dependencies": {
40
- "@notionhq/client": "^4.0.0",
42
+ "@notionhq/client": "^5.0.0",
41
43
  "hash.js": "^1.1.7",
42
44
  "hast-util-classnames": "^3.0.0",
43
45
  "hast-util-to-html": "^9.0.0",
@@ -46,14 +48,9 @@
46
48
  "yargs": "^18.0.0"
47
49
  },
48
50
  "devDependencies": {
49
- "@types/jest": "^30.0.0",
50
- "@types/node": "^20.12.8",
51
+ "@types/node": "^26.1.1",
51
52
  "@types/sha.js": "^2.4.0",
52
53
  "@types/yargs": "^17.0.12",
53
- "jest": "^30.0.0",
54
- "rimraf": "^6.0.1",
55
- "ts-jest": "^29.1.2",
56
- "ts-node": "^10.9.1",
57
- "typescript": "^5.0.2"
54
+ "typescript": "^7.0.2"
58
55
  }
59
56
  }