Skip to content

Instantly share code, notes, and snippets.

@iceener
Created July 14, 2023 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iceener/41ad0650d728b2e4389930d3187eaf49 to your computer and use it in GitHub Desktop.
Save iceener/41ad0650d728b2e4389930d3187eaf49 to your computer and use it in GitHub Desktop.
import { markdownToBlocks } from '@tryfabric/martian';
import { NotionToMarkdown } from 'notion-to-md';
@Controller('/api/tools')
export class ToolsController {
@Post('/markdown-notion')
async convert(@Body() body) {
return markdownToBlocks(body.markdown);
}
@Post('/notion-markdown')
async convertBlocksToMarkdown(
@Req() request,
@Body() body,
) {
const auth = request.headers.authorization;
const notionClient = new Client({auth});
const n2m = new NotionToMarkdown({notionClient});
const mdblocks = await n2m.pageToMarkdown(body.pageId);
const mdString = n2m.toMarkdownString(mdblocks);
return {
markdown: mdString,
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment