@wipcomputer/markdown-viewer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CLAUDE.md ADDED
@@ -0,0 +1,138 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ Two versions of a feature-rich markdown viewer with syntax highlighting, diagrams, math equations, and more:
8
+
9
+ 1. **Web Browser Version** (`markdown-viewer.html`) - Standalone single-file HTML application
10
+ 2. **BBEdit Preview Template** (`bbedit-preview-template.html`) - Integration for BBEdit's preview system
11
+
12
+ Both share the same rendering features but differ in file loading and refresh mechanisms.
13
+
14
+ ## Architecture
15
+
16
+ ### Web Browser Version (`markdown-viewer.html` - 1,052 lines)
17
+
18
+ **Single-file architecture** with embedded CSS and JavaScript:
19
+
20
+ - **CDN Dependencies**: marked.js (markdown parsing), highlight.js (syntax highlighting), Mermaid (diagrams), KaTeX (math)
21
+ - **CSS Variables**: Theme system for light/dark mode (`:root` and `[data-theme="dark"]`)
22
+ - **Key Components**:
23
+ - Drop zone UI with "Load File" button (supports drag-and-drop and File System Access API)
24
+ - Viewer container with header controls (TOC, Theme, Load, Refresh, Export, Print)
25
+ - TOC sidebar (collapsible, auto-generated from headings)
26
+ - Markdown content area (styled with GitHub-inspired typography)
27
+
28
+ **File Loading Flow**:
29
+ 1. Drag-and-drop OR "Load File" button → `handleDrop()` or `loadNewFile()`
30
+ 2. `loadFile()` → FileReader reads text → `displayMarkdown()`
31
+ 3. `displayMarkdown()` → marked.js renders → sanitize HTML → highlight code → render Mermaid/KaTeX → generate TOC
32
+
33
+ **Auto-Refresh** (Chrome/Edge only):
34
+ - Uses File System Access API (`showOpenFilePicker`) to get `fileHandle`
35
+ - `checkForChanges()` polls every 2 seconds via `fileHandle.getFile()`
36
+ - Compares `lastModified` timestamp and reloads if changed
37
+ - Safari/Firefox: No File System Access API, must manually refresh
38
+
39
+ ### BBEdit Preview Template (`bbedit-preview-template.html` - 558 lines)
40
+
41
+ **Simplified version designed for BBEdit's preview system**:
42
+
43
+ - **No file loading logic**: BBEdit handles markdown parsing and injects HTML at `#DOCUMENT_CONTENT#` marker
44
+ - **Removed**: Drop zone, file buttons, marked.js, File System Access API, file watching
45
+ - **Kept**: All rendering (highlight.js, Mermaid, KaTeX), TOC generation, dark mode, export
46
+ - **Auto-refresh**: Native BBEdit behavior (updates on save) - no polling needed
47
+
48
+ **Template Integration**:
49
+ 1. BBEdit parses markdown → HTML
50
+ 2. Injects at `#DOCUMENT_CONTENT#` marker in template
51
+ 3. Template JavaScript runs: syntax highlight → render diagrams/math → generate TOC
52
+ 4. Updates automatically when file is saved in BBEdit
53
+
54
+ **Installation**: Copy to `~/Library/Application Support/BBEdit/Preview Templates/`
55
+
56
+ ## Key Features (Both Versions)
57
+
58
+ - **Syntax highlighting**: highlight.js with auto-detection (180+ languages)
59
+ - **Mermaid diagrams**: Renders flowcharts, sequence diagrams, etc. from code blocks
60
+ - **Math equations**: KaTeX renders inline `$...$` and display `$$...$$` LaTeX
61
+ - **Table of Contents**: Auto-generated from h1-h4, smooth scroll navigation
62
+ - **Dark mode**: Toggleable with localStorage persistence, updates highlight.js/Mermaid themes
63
+ - **GitHub Flavored Markdown**: Tables, task lists, strikethrough via marked.js GFM mode
64
+ - **XSS Protection**: Basic sanitization (removes `<script>`, validates `<iframe>` src)
65
+
66
+ ## Development
67
+
68
+ ### Testing Web Version
69
+ ```bash
70
+ open markdown-viewer.html # macOS
71
+ # or open in any browser
72
+ ```
73
+
74
+ Test with `demo/demo.md` which includes examples of all features.
75
+
76
+ ### Testing BBEdit Template
77
+ ```bash
78
+ # Copy template to BBEdit folder
79
+ cp bbedit-preview-template.html ~/Library/Application\ Support/BBEdit/Preview\ Templates/
80
+
81
+ # Open demo in BBEdit
82
+ open -a BBEdit demo/demo.md
83
+
84
+ # Press ⌃⌘P to preview, select template from menu
85
+ ```
86
+
87
+ ### Making Changes
88
+
89
+ **When modifying features:**
90
+ - Update BOTH files if feature is shared (syntax highlighting, dark mode, TOC, etc.)
91
+ - Update only web version for file loading/refresh logic
92
+ - Update only BBEdit version for template-specific behavior
93
+
94
+ **Key areas that differ between versions:**
95
+ - Web: Lines 484-520 (drop zone), 579-891 (file loading/watching)
96
+ - BBEdit: No file loading, uses `#DOCUMENT_CONTENT#` marker at line 401
97
+
98
+ **CSS theming:**
99
+ - Both use CSS variables (`:root` for light, `[data-theme="dark"]` for dark)
100
+ - Changing colors: Update CSS variables at top of `<style>` section
101
+ - Highlight.js theme switches via DOM: `document.getElementById('highlight-theme').href = ...`
102
+
103
+ ## Common Tasks
104
+
105
+ ### Adding a new CDN library
106
+ Add `<script>` or `<link>` in `<head>` section of both files (after existing CDN includes).
107
+
108
+ ### Updating markdown renderer options
109
+ Web version only: Modify `marked.setOptions()` around line 496-509.
110
+ BBEdit version: BBEdit handles markdown parsing (cmark/GFM/MultiMarkdown configurable in BBEdit preferences).
111
+
112
+ ### Changing dark mode colors
113
+ Update CSS variables in `[data-theme="dark"]` block (lines 34-47 in web version, similar in BBEdit).
114
+
115
+ ### Modifying TOC generation
116
+ Both files: `generateTOC()` function queries `h1-h4` and builds sidebar list with smooth scroll.
117
+
118
+ ## Repository Structure
119
+
120
+ ```
121
+ .
122
+ ├── markdown-viewer.html # Web browser version
123
+ ├── bbedit-preview-template.html # BBEdit preview template
124
+ ├── demo/
125
+ │ ├── demo.md # Feature demonstration file
126
+ │ └── demo-image.png # Test image (referenced in demo.md)
127
+ ├── images/ # Screenshots for README
128
+ ├── README.md # User documentation (installation, usage)
129
+ ├── LICENSE # MIT License
130
+ └── CLAUDE.md # This file
131
+ ```
132
+
133
+ ## Important Notes
134
+
135
+ - **No build process**: Files are standalone HTML, edit and refresh
136
+ - **Image paths in markdown**: Relative to markdown file location (BBEdit resolves correctly)
137
+ - **Browser compatibility**: Auto-refresh requires File System Access API (Chrome/Edge/Opera only)
138
+ - **BBEdit markdown parsers**: Users can choose cmark, GFM, MultiMarkdown, or Pandoc in BBEdit preferences
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Parker Todd Brooks
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,136 @@
1
+ ###### WIP Computer
2
+ # Live .md Viewer
3
+
4
+ See your documents update in real time as you and your AI edit them together.
5
+
6
+ ## How It Works
7
+
8
+ 1. Tell your AI coding tool to install `@wipcomputer/markdown-viewer` globally
9
+ 2. Tell your AI to open the demo.md (or any .md) in md view
10
+ 3. AI will open the file in your default browser
11
+ 4. Every save re-renders the page instantly. No refresh needed.
12
+
13
+ Open multiple tabs to work on multiple documents at once.
14
+
15
+ ## Install
16
+
17
+ ### For AI Agents
18
+
19
+ Open your AI coding tool and say:
20
+
21
+ ```
22
+ Install @wipcomputer/markdown-viewer globally,
23
+ start mdview, and add live viewer support to this project.
24
+ ```
25
+
26
+ Your AI will install the package, start the server, and add the right instructions to your project so it knows to open the viewer whenever you edit markdown together. That's it.
27
+
28
+ ### npm
29
+
30
+ ```bash
31
+ npm install -g @wipcomputer/markdown-viewer
32
+ mdview
33
+ ```
34
+
35
+ That's it. Global install gives you the `mdview` command anywhere.
36
+
37
+ ### From source
38
+
39
+ ```bash
40
+ git clone https://github.com/wipcomputer/wip-markdown-viewer.git
41
+ cd wip-markdown-viewer
42
+ npm install
43
+ node server.js
44
+ ```
45
+
46
+ Server starts at `http://127.0.0.1:3000`. Open any markdown file:
47
+
48
+ ```
49
+ http://127.0.0.1:3000/view?path=/absolute/path/to/your/file.md
50
+ ```
51
+
52
+
53
+ ## Supported Tools
54
+
55
+ This works with any AI agent that can run shell commands and edit files.
56
+
57
+ | Tool | Instruction file | How to add support |
58
+ |------|-----------------|-------------------|
59
+ | Claude Code | `CLAUDE.md` | Add the snippet below to your project's `CLAUDE.md` |
60
+ | OpenAI Codex CLI | `AGENTS.md` | Add the snippet below to your project's `AGENTS.md` |
61
+ | Cursor | `.cursorrules` | Add the snippet below to `.cursorrules` |
62
+ | Windsurf | `.windsurfrules` | Add the snippet below to `.windsurfrules` |
63
+ | OpenClaw | `SKILL.md` | Install the `live-viewer` skill |
64
+ | Any other agent | Whatever config it reads | Add the snippet below |
65
+
66
+ If your tool reads a project-level instruction file... it works. The snippet is the same for all of them.
67
+
68
+ ## Features
69
+
70
+ - **Live reload:** SSE-powered, works in all browsers including Safari
71
+ - **Multi-file:** each tab watches its own file independently
72
+ - **GitHub Flavored Markdown:** tables, task lists, strikethrough
73
+ - **Syntax highlighting:** 180+ languages via highlight.js
74
+ - **Dark mode:** light and dark themes
75
+ - **Table of contents:** auto-generated from headings
76
+ - **Mermaid diagrams:** flowcharts, sequence diagrams, and more
77
+ - **Math equations:** KaTeX rendering for LaTeX
78
+
79
+ ## For AI Agents
80
+
81
+ Everything below is for you, the AI agent. The human doesn't need to read this. When the user asks you to set up the live markdown viewer, follow these steps.
82
+
83
+ ### Step 1. Start the Server
84
+
85
+ If installed globally via npm (`npm install -g @wipcomputer/markdown-viewer`):
86
+
87
+ ```bash
88
+ curl -s http://127.0.0.1:3000/ > /dev/null 2>&1 || mdview &
89
+ ```
90
+
91
+ Or if cloned from source, resolve the full path and start the server:
92
+
93
+ ```bash
94
+ curl -s http://127.0.0.1:3000/ > /dev/null 2>&1 || node {absolute path to wip-markdown-viewer}/server.js &
95
+ ```
96
+
97
+ The server runs at `http://127.0.0.1:3000` and stays running in the background. Note: the server doesn't survive reboots or long idle periods. The check above starts it only if it's not already running.
98
+
99
+ ### Step 2. Add the Snippet to Your Project
100
+
101
+ Add the following to whatever instruction file your tool uses (`CLAUDE.md`, `AGENTS.md`, `.cursorrules`, `.windsurfrules`, or equivalent). The content is the same regardless of the file:
102
+
103
+ ```markdown
104
+ ## Live Markdown Viewer
105
+
106
+ When editing a .md file, check the server is running and open it in the viewer:
107
+
108
+ curl -s http://127.0.0.1:3000/ > /dev/null 2>&1 || node {path to server.js} &
109
+ open "http://127.0.0.1:3000/view?path={absolute path to the file}"
110
+
111
+ Then make your edits. The user sees every change as you write. No refresh needed.
112
+ Do this every time you edit a markdown file.
113
+ ```
114
+
115
+ ### Step 3. Every Time You Edit Markdown
116
+
117
+ 1. Run: `open "http://127.0.0.1:3000/view?path={absolute path to the file}"`
118
+ 2. Edit the file
119
+ 3. The user sees it update live in their browser
120
+
121
+ That's it. The server watches the file and pushes updates via SSE. You don't need to do anything else.
122
+
123
+ ### Notes
124
+
125
+ - The `open` command works on macOS. On Linux use `xdg-open`. On Windows use `start`.
126
+ - Each file gets its own URL. Multiple files can be viewed in separate tabs.
127
+ - The server reads the file fresh on every change. No caching.
128
+ - If the server isn't running, start it. It doesn't need any arguments.
129
+
130
+ ---
131
+
132
+ ## License
133
+
134
+ MIT
135
+
136
+ Built by Parker Todd Brooks, with Claude Code and Lēsa (OpenClaw).