How yusukebe/gh-markdown-preview works
Project Type Analysis
This is a command-line tool that serves as an extension to GitHub CLI, providing a local web server functionality to preview Markdown files with GitHub-style rendering.
Main Components
A. Core Components:
• CLI Interface (cmd/cli.go)
• Web Server (cmd/server.go)
• WebSocket Handler (cmd/websocket.go)
• File Watcher (cmd/watcher.go)
• Browser Manager (cmd/browser.go)
B. External Services:
• GitHub Markdown API (for rendering)
• GitHub Web CSS (for styling)
[User Input] → [CLI Interface]
• ↓
[File System] ← [File Watcher] → [WebSocket Server]
• ↓ ↓
[GitHub API] ← [Web Server] → [Browser Client]
• ↑
[GitHub CSS] ─────────┘
Component Details
a) Input Layer:
• CLI command entry point
• File system watching capabilities
• Configuration options handling
b) Processing Layer:
• Web server component handling HTTP requests
• WebSocket server for live reload functionality
• File watcher for detecting markdown changes
• Browser automation for auto-opening feature
c) External Integration Layer:
• GitHub Markdown API connection
• GitHub CSS fetching mechanism
Data Flow Representation
• Command flow from user input to server initialization
• File change notifications from watcher to WebSocket
• Markdown content flow to GitHub API
• Rendered HTML delivery to browser
• Live reload notifications through WebSocket
Additional Elements
Notes about:
• Default port (3333) configuration
• Auto-detection of README files
• Dark/Light mode switching capability
• Browser compatibility (Chrome, Firefox, Safari)
Technical Details to Highlight
• Zero-dependency nature (except for gh CLI)
• Authentication handling with GitHub
• Port availability checking
• Live reload mechanism
• Browser auto-opening functionality