Skip to content

Commit

Permalink
feat: add support for thematic breaks/dividers in markdown parsing
Browse files Browse the repository at this point in the history
This commit adds support for thematic breaks/dividers in the markdown parsing functionality. It introduces a new function `divider()` in the `blocks.ts` file, which creates a divider block. Additionally, the `parseNode()` function in the `internal.ts` file has been updated to handle the `thematicBreak` node type and convert it into a divider block.
  • Loading branch information
sengmitnick committed Jun 24, 2024
1 parent 8cfccaa commit 9561de9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/notion/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export type RichText = (Block & {
type: 'paragraph';
})['paragraph']['rich_text'][number];

export function divider(): Block {
return {
object: 'block',
type: 'divider',
divider: {},
};
}

export function paragraph(text: RichText[]): Block {
return {
object: 'block',
Expand Down
3 changes: 3 additions & 0 deletions src/parser/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ function parseNode(
case 'math':
return [parseMath(node)];

case 'thematicBreak':
return [notion.divider()];

default:
return [];
}
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/divider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Thematic Break

***

Divider

---

END
15 changes: 15 additions & 0 deletions test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ const hello = "hello";

expect(actual).toStrictEqual(expected);
});

it('should deal with divider', () => {
const text = fs.readFileSync('test/fixtures/divider.md').toString();
const actual = markdownToBlocks(text);

const expected = [
notion.paragraph([notion.richText('Thematic Break')]),
notion.divider(),
notion.paragraph([notion.richText('Divider')]),
notion.divider(),
notion.paragraph([notion.richText('END')]),
];

expect(actual).toStrictEqual(expected);
});

it('should break up large elements', () => {
const text = fs.readFileSync('test/fixtures/large-item.md').toString();
Expand Down

0 comments on commit 9561de9

Please sign in to comment.