Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Julia Rosenson <[email protected]>
  • Loading branch information
cliftonc and Julia Rosenson authored Nov 4, 2021
1 parent 3e9a8f8 commit 1c09299
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Martian is a Markdown parser to convert any Markdown content to Notion API block
uses [unified](https://github.com/unifiedjs/unified) to create a Markdown AST, then converts the AST into Notion
objects.

Designed to make using the Notion SDK and API easier. Notion API version 0.4.4.
Designed to make using the Notion SDK and API easier. Notion API version 0.4.5.

### Supported Markdown Elements

Expand All @@ -22,20 +22,20 @@ Designed to make using the Notion SDK and API easier. Notion API version 0.4.4.

## Unsupported Markdown Elements

*tables*: Tables can be imported in an 'unsupported mode' if you add a flag to the parser.
*tables*: Tables can be imported in an [unsupported mode](https://developers.notion.com/reference/block) if you add a flag to the parser.

First, the default mode - it ignores the tables:

```ts
const unsupported = false;
const allowUnsupportedObjectType = false;
const blocks: Block[] = markdownToBlocks(`
# Table
| First Header | Second Header |
| ------------- | ------------- |
| Content Cell | Content Cell |
| Content Cell | Content Cell |
`, unsupported);
`, allowUnsupportedObjectType);

// [
// {
Expand Down Expand Up @@ -63,19 +63,19 @@ const blocks: Block[] = markdownToBlocks(`
// ]
```

Next, with unsupported flag = true (note I have removed the `annotations` from the returned object to make it easier to see what is going on):
Next, with unsupported flag = true (note the `annotations` have been removed from the returned object to make it easier to see what is going on):


```ts
const unsupported = true;
const allowUnsupportedObjectType = true;
const blocks: Block[] = markdownToBlocks(`
# Table
| First Header | Second Header |
| ------------- | ------------- |
| Content Cell | Content Cell |
| Content Cell | Content Cell |
`, unsupported)
`, allowUnsupportedObjectType)

[
// {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"author": "Richard Robinson",
"license": "ISC",
"dependencies": {
"@notionhq/client": "^0.4.4",
"@notionhq/client": "^0.4.5",
"remark-gfm": "^1.0.0",
"remark-parse": "^9.0.0",
"unified": "^9.2.1"
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import gfm from 'remark-gfm';
*/
export function markdownToBlocks(
body: string,
unsupported = false
allowUnsupportedObjectType = false
): notion.Block[] {
const root = unified().use(markdown).use(gfm).parse(body);
return parseBlocks(root as unknown as md.Root, unsupported);
return parseBlocks(root as unknown as md.Root, allowUnsupportedObjectType);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const hello = "hello";
expect(expected).toStrictEqual(actual);
});

it('should convert markdown to blocks - skip tables if unsupported = true', () => {
it('should convert markdown to blocks - include tables if unsupported = true', () => {
const text = fs.readFileSync('test/fixtures/table.md').toString();
const actual = markdownToBlocks(text, true);
const expected = [
Expand Down

0 comments on commit 1c09299

Please sign in to comment.