# SmartCane Documentation Viewer A lightweight, browser-based markdown documentation viewer for SmartCane architecture guides and system documentation. ## Features ✨ **Simple Single-Page App** - No backend required - Static HTML/JS/CSS - Works on any static hosting (Netlify, GitHub Pages, etc.) - Perfect for local development or production πŸ“š **Dynamic Document Loading** - Sidebar auto-populates from markdown files in `../docs/` - Click to view any documentation file - Search/filter documents by name 🎨 **Beautiful Rendering** - Inherited SmartCane branding (teal/blue theme from `../theme.css`) - Responsive design (desktop, tablet, mobile) - Properly styled markdown elements: - Headings with hierarchy - Code blocks with background highlighting - Tables with alternating rows - Blockquotes and lists - Links with hover effects πŸ”’ **Security** - All HTML output is sanitized with DOMPurify - Prevents XSS injection from markdown content - Safe for user-uploaded or external documentation πŸ”— **Bookmarkable & Shareable** - URL hash tracks current document (e.g., `#ARCHITECTURE_DATA_FLOW`) - Reload page or share link with hash to jump directly to document - Browser back/forward work as expected ## File Structure ``` webapps/markdown_docs_viewer/ β”œβ”€β”€ index.html # Main page (layout + header) β”œβ”€β”€ script.js # Markdown loading logic β”œβ”€β”€ style.css # Custom styles + layout β”œβ”€β”€ lib/ # (Optional local library storage) └── README.md # This file ``` ## Setup ### Prerequisites - No installation requiredβ€”pure HTML/CSS/JavaScript - External libraries loaded via CDN: - `marked.js` (v11.1.0) β€” Markdown parser - `DOMPurify.js` (v3.0.0) β€” HTML sanitizer ### Local Development 1. Place markdown files in `../docs/` folder (same level as `../webapps/`) ``` SmartCane_code/ β”œβ”€β”€ webapps/ β”‚ β”œβ”€β”€ markdown_docs_viewer/ β”‚ β”‚ β”œβ”€β”€ index.html β”‚ β”‚ β”œβ”€β”€ script.js β”‚ β”‚ └── style.css β”‚ └── docs/ ← Markdown files go here β”‚ β”œβ”€β”€ system_architecture.md β”‚ β”œβ”€β”€ ARCHITECTURE_DATA_FLOW.md β”‚ └── ... ``` 2. Open `index.html` in a browser (or use a local HTTP server): ```bash # Python 3 python -m http.server 8000 # Then visit: http://localhost:8000/webapps/markdown_docs_viewer/ ``` 3. Click documents in the sidebar to view them ### Deployment to Netlify 1. Ensure `system_architecture/` folder is moved to `webapps/docs/`: ``` webapps/ β”œβ”€β”€ markdown_docs_viewer/ ← The viewer app └── docs/ ← All .md files here ``` 2. Push to GitHub (the `code-improvements` branch) 3. Netlify will auto-deploy the entire `webapps/` folder 4. Access at: `https://your-site.netlify.app/markdown_docs_viewer/` ## How It Works ### Page Load Flow ``` 1. User opens index.html ↓ 2. JavaScript executes `populateDocumentList()` β”œβ”€ Fetches list of .md files from ../docs/ β”œβ”€ Sorts alphabetically (system_architecture.md first) └─ Creates clickable links in sidebar ↓ 3. Check URL hash: β”œβ”€ If hash exists (e.g., #ARCHITECTURE_DATA_FLOW) β”‚ └─ Load that document automatically └─ If no hash, show welcome message ↓ 4. Setup completeβ€”user can click docs to load ``` ### Document Loading ``` 1. User clicks a document link ↓ 2. `loadDocument(docId)` is called β”œβ”€ Fetches markdown file: fetch('../docs/{docId}.md') β”œβ”€ Parses with marked.js: marked.parse(markdown) β”œβ”€ Sanitizes with DOMPurify.sanitize(html) β”œβ”€ Insert into #content div └─ Update URL hash for bookmarking ↓ 3. Markdown is rendered with custom CSS styling ``` ## Customization ### Adding New Documents Simply add `.md` files to `webapps/docs/` folder. They'll automatically appear in the sidebar on next page load. ### Changing Document Order Edit the `docFiles` array in `script.js` `populateDocumentList()` function: ```javascript const docFiles = [ 'system_architecture.md', // Always first 'ARCHITECTURE_DATA_FLOW.md', // ... add more ]; ``` ### Changing Display Names Update the `nameMap` in `formatDocName()` function in `script.js`: ```javascript const nameMap = { 'system_architecture.md': 'πŸ—οΈ System Architecture', // Change the emoji or text 'YOUR_FILE.md': '🎯 Your Custom Name', // ... }; ``` ### Styling Adjustments - **Colors**: Modify CSS variables at top of `style.css` (`:root` section) - `--smartcane-teal`: Main color - `--smartcane-dark`: Darker accent - `--accent-color`: Link color - **Layout**: Change sidebar width (default 280px) or adjust breakpoints in media queries - **Fonts**: Update `font-family` in `body` rule ## Browser Support - βœ… Chrome 90+ - βœ… Firefox 88+ - βœ… Safari 14+ - βœ… Edge 90+ - ⚠️ IE 11: Not supported (uses modern ES6+ features) ## Troubleshooting ### Documents not loading? 1. **Check folder path**: Ensure `../docs/` folder exists relative to `index.html` 2. **Check filenames**: File names are case-sensitive (e.g., `ARCHITECTURE_DATA_FLOW.md` β‰  `architecture_data_flow.md`) 3. **CORS error**: If running locally via `file://` protocol, use a local HTTP server instead 4. **Browser console**: Open DevTools (F12) and check Console tab for error messages ### Styling looks different? - Ensure `../theme.css` exists (inherited for SmartCane branding) - Check that `style.css` is loaded (should see in Network tab) - Clear browser cache (Ctrl+Shift+Delete) and reload ### Search not working? - Search filters sidebar document list (case-insensitive) - Only shows documents matching the search term - Clear search input to see all documents again ## Technical Notes ### Performance - **Fast rendering**: marked.js renders ~1MB markdown in <100ms - **Minimal dependencies**: Only 2 external libraries (58KB total gzipped) - **No build step needed**: Pure HTML/CSS/JS, no transpilation required - **Caching**: Browser caches .md files and libraries automatically ### Security - **DOMPurify sanitization**: Removes any `