Architecture Overview
Noeqtion is built as a Manifest V3 browser extension with a minimal architecture:- Content Script (
content.js): Handles equation detection and conversion logic - Popup Interface (
popup.html,popup.js): Provides manual trigger UI - Manifest Configuration (
manifest.json): Defines permissions and script injection
The extension uses Manifest V3, the latest Chrome extension platform standard that emphasizes security, privacy, and performance.
Conversion Architecture
Sequential Processing Model
Noeqtion uses a sequential, single-equation processing model:- DOM stability: Notion dynamically updates the DOM after each conversion
- Error isolation: Failures in one equation don’t block others
- Rescan capability: Fresh DOM scan after each conversion handles dynamically inserted content
Equation Detection
The extension uses a regex pattern to identify LaTeX equations:Pattern Breakdown
Pattern Breakdown
\$\$[\s\S]*?\$\$: Matches block equations (non-greedy, including newlines)\$[^\$\n]*?\$: Matches inline equations (excluding newlines to prevent false positives)
Conversion Mechanisms
Display Equations ($$...$$)
Display equations use Notion’s /math command:
- Selection: Text node containing
$$...$$is selected usingRangeAPI - Deletion:
selection.deleteFromDocument()removes the LaTeX text - Command insertion:
document.execCommand('insertText', false, '/math')triggers Notion’s command palette - Enter dispatch: Synthetic
Enterkeypress event selects the math block option - LaTeX insertion: Content (without
$$delimiters) inserted into the math input field - Validation: KaTeX error detection via
div[role="alert"]selector - Finalization: “Done” button clicked or
Escapepressed if error detected
The extension waits 100ms for the math dialog to appear and another 100ms for the math block to initialize. These timing constants are critical for reliability.
Inline Equations ($...$)
Inline equations use a simpler conversion:
- Selection: Text node containing
$...$is selected - Direct replacement:
document.execCommand('insertText', false,$$$$$) - Notion auto-detection: Notion recognizes the
$$...$$pattern and automatically converts to inline math
Timing System
The extension uses carefully calibrated delays defined incontent.js:4-15:
| Timing Constant | Duration | Purpose |
|---|---|---|
FOCUS | 50ms | Wait after focusing editable block for Notion to register |
QUICK | 20ms | Short pause for UI updates between operations |
DIALOG | 100ms | Wait for dialogs/inputs to appear (display equations) |
MATH_BLOCK | 100ms | Extra time for math block initialization |
POST_CONVERT | 300ms | Wait for Notion DOM updates before rescanning |
These timing values were empirically determined to balance speed and reliability across different system performance levels.
DOM Interaction Details
Finding Editable Parents
Notion’s editable content uses the attributedata-content-editable-leaf="true":
Text Selection
Precise text selection uses the DOM Range API:Keyboard Event Simulation
Synthetic keyboard events are dispatched to trigger Notion’s native behavior:Enter (selecting math block) and Escape (closing dialogs).
Visual Distraction Mitigation
During conversion, the extension injects CSS to hide UI elements:content.js:66-70).
Browser API Compatibility Layer
The extension supports both Firefox and Chrome APIs:- Firefox: Uses
browser.*namespace (Promise-based) - Chrome/Chromium: Uses
chrome.*namespace (callback-based)
Activation Methods
Keyboard Shortcut
Registered viakeydown event listener (content.js:27-36):
Ctrl+Alt+M (case-insensitive)
Extension Popup
The popup sends a message to the active tab:Error Handling
KaTeX Validation
For display equations, the extension checks for KaTeX errors:Conversion Failures
Each conversion is wrapped in try-catch:Permissions and Scope
Frommanifest.json:
Permission Details
Permission Details
- activeTab: Allows popup to send messages to the current tab
- scripting: Required for Manifest V3 script injection
- host_permissions: Restricts extension to
notion.sodomain only - content_scripts: Auto-injects
content.json all Notion pages
Performance Characteristics
Conversion speed depends on:- Equation count: Sequential processing means O(n) time complexity
- Timing delays: ~520ms per display equation, ~320ms per inline equation
- DOM complexity: TreeWalker traversal scales with page size
- Notion responsiveness: Delays ensure Notion’s async updates complete
For a page with 10 display equations, expect ~5-6 seconds total conversion time. This is intentionally conservative to ensure reliability.