How 00dhkim/notion-marp-extension works
Project type and purpose
• This is a Chrome extension (“notion-marp-extension”) that runs entirely client-side in the browser.
• Its job is to take a Notion page, call the Notion API to fetch its contents, send that to an LLM (Gemini) to insert slide separators, render the result with the Marp library into a PDF, and download that PDF—all without a server component.
File structure
• Top level:
• manifest.json – Chrome Extension Manifest V3 definition
• background.js – Service Worker / background script handling messaging and API calls
• contentScript.js – Injected into Notion pages, adds the “Export → Marp” button
• options.html + options.js – Extension options UI where the user supplies Notion API and Gemini keys
• utils/marp.esm.js – The Marp rendering library, packaged for client-side PDF generation
• rollup.config.js, package.json – Build configuration and dependencies
• Build artifacts:
• After npm run build, a dist/ folder holds the bundle for deployment.
README for additional insights
• All calls to external services (Notion API, Gemini) happen in background.js via Fetch.
• contentScript sends a Chrome runtime message to background.js when the user clicks the export button.
• The Marp library is used entirely client-side to convert Markdown to PDF.
Main components and interactions
a. Browser & Extension Shell
• Chrome Extension container, handling manifest, security, permissions.
b. contentScript
• Injected into Notion pages, UI component to render Export button.
• Listens for button clicks, sends messages to background.
c. background.js (Service Worker)
• Receives messages from contentScript.
• Holds user API tokens (from options page) via chrome.storage.
• Orchestrates:
1. Fetch Notion page data from Notion API.
2. Send content to Gemini LLM API to insert slide separators.
3. Receive processed Markdown.
4. Pass Markdown to Marp library for PDF generation.
• Uses utils/marp.esm.js in the bundle.
• Triggers a download of the resulting PDF in the user’s browser.
d. options UI
• options.html + options.js
• Allows user to configure and save API keys via chrome.storage.
e. External Services
• Notion REST API
• Gemini (LLM) API
f. Marp Renderer
• utils/marp.esm.js (bundled by Rollup)
Architectural patterns and design principles
• Chrome Extension MV* pattern
• contentScript (View/UI) ←→ background.js (Controller/Orchestrator)
• Message-passing
• Use chrome.runtime.sendMessage and onMessage to decouple UI injection from API logic.
• Client-side only
• No server deployment; all APIs are called from the browser background script.
• Modular bundling with Rollup
• Separate code into modules (utils, contentScript, background) and bundle for V3.
Detailed component breakdown to capture
• User’s Browser (Chrome)
• Chrome Extension Host
• manifest.json (permissions)
• contentScript.js
• background.js (Service Worker)
• options.html + options.js
• utils/marp.esm.js
• Storage
• chrome.storage (holds API keys)
• External:
• Notion REST API
• Gemini LLM API