Skip to content
servitantgitPublic

About

GitHub-native editor for Markdown, HTML and text files. OAuth, live preview, tabs, search, Commit/History, drafts, PDF. No local clone, no build step.DF export. No local clone, no build step.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

381 Commits

Folders and files

Repository files navigation

GitHub MD Editor

Tests Deployed on Cloudflare Pages Vite Vanilla JS Last commit Code size Open issues License

A lightweight browser editor for Markdown and related text files in a GitHub repository. Sign in with "Sign in with GitHub" (OAuth) — the access token is issued by GitHub and lives only in sessionStorage; our server only ever sees the one-time code-for-token exchange (setup: README-CLOUDFLARE.md).

Plain ES modules bundled with Vite for production (dist/). End users still open the site with zero install. Edit Markdown, HTML, JS/CSS and other text files with three layouts (Source / Live / Preview), multi-tab editing, full-text search, local drafts (IndexedDB) + explicit Save/Commit to GitHub, Commit / History drawers, find/replace, outline, minimap, and PDF export. Core editor libraries ship from npm via js/vendor.js (not from a CDN).

Screenshots

landpage
Sign in with GitHub — OAuth login, no manual token to create or paste.

hero
File tree, tabs, live preview and toolbar side by side while editing a note.

Architecture

Plain JavaScript (ES modules), no TypeScript, no bundler — opens directly in the browser. Code is split by responsibility:

index.html              HTML shell; loads js/vendor.js (npm libs → window) then js/app.js
vite.config.js          Vite: dev server :8080, build → dist/
js/vendor.js             only module that imports EasyMDE/marked/DOMPurify/… from npm
css/app.css              all styles
functions/auth/
  login.js                Cloudflare Pages Function: GET /auth/login — starts OAuth
  callback.js              Cloudflare Pages Function: GET /auth/callback — exchanges
                            code -> access_token, hands the token to the client
js/
  paths.js                pure path-handling functions (no DOM/network)
  markdown-tokens.js       detects images/links in markdown, builds a
                            "canonical" preview HTML (no DOM/network)
  reference-rewriter.js    logic for rewriting links when files move
                            (pure functions, no network)
  github-client.js         thin GitHub REST API client (auth, contents, trees,
                            Git Data API)
  demo-client.js           in-memory GitHubClient stand-in for "Try demo" (local sandbox)

  github-repo-url.js       parses a pasted GitHub repo URL into owner/repo
  file-kind.js             file extension -> kind mapping (md/html/js/css/…)
  image-resolver.js        markdown path -> data: URL via the GitHub API, cached
  file-mover.js            orchestrates moving a file (reads/writes through
                            github-client, uses reference-rewriter)
  folder-manager.js        create/rename/delete folders (one atomic commit)
  image-preview.js         DOM side of the preview: src substitution, resize handle
  editor.js                wrapper around EasyMDE (setup, preview rendering,
                            correct CodeMirror.refresh(), tab-aware Preview)
  file-tree.js             file tree + drag & drop for files and folders (context menu)
  upload.js                image uploads (OS drag & drop + toolbar button)
  folder-upload.js         folder upload via drag & drop (webkitGetAsEntry)
  print-export.js          Print… / Save as PDF via the browser print dialog
  working-tree.js          tracks dirty state across files/tabs for Commit panel
  commit-ui.js             Commit + History panel DOM helpers
  diff-util.js             unified diff helpers for the History panel
  tabs.js                  tab model: ordered paths + active + persistence
  tabs-ui.js               tab strip rendering and click handling
  tabs-session.js          tab session state: tab docs, open/close/switch (extracted from app.js)
  autosave.js              hybrid autosave: local draft on idle; GitHub on Save/Commit
  draft-store.js           per-repo/branch IndexedDB store for local drafts
  idb-backend.js           generic IndexedDB wrapper (open/degrade/quota/sweep)
  search-index.js           MiniSearch index over repo markdown
  search-store.js          IndexedDB persistence for search index
  search-sync.js           background sync: diff tree, fetch bodies, update index
  search-ui.js             search box + results list DOM helpers
  file-kind.js             extension → language / preview strategy
  file-ops.js              file/folder CRUD orchestration (create/rename/move/delete/copy link, extracted from app.js)
  html-preview.js          HTML iframe srcdoc + relative assets + link bridge
  login-ui.js              Sign-in + OAuth flow (consumeOAuthRedirect, readSession, finishLogin; extracted from app.js)
  minimap.js               canvas document minimap
  commit-ui.js             Commit + History drawers
  commit-history-ui.js     Commit panel / History drawer orchestration (extracted from app.js)
  working-tree.js          multi-file dirty set for Commit
  diff-util.js             unified diff helpers
  app.js                   assembly point: state, wiring up the modules (login flow now in login-ui.js)
test/                      unit tests (node:test) for the pure logic
e2e_smoke_test.py          end-to-end browser test (Playwright)
serve.mjs                  bare static server (no npm resolve — not for full app after Vite)

Why it's structured this way: paths.js, markdown-tokens.js and reference-rewriter.js have ZERO dependency on the DOM or the network — this is all the "dangerous" logic (link parsing, relative-path rewriting), which can and should be tested in isolation. That's exactly where real bugs hid in earlier versions.

Running it

Browsers won't load <script type="module"> from file://, and after the Vite migration the app also needs either the Vite dev server or a production build so js/vendor.js can resolve npm packages.

  • Cloudflare Pages — production (md-edit.pages.dev). Git integration, auto-deploy on push to main. Build command: npm run build. Output directory: dist. OAuth is implemented as Pages Functions (functions/auth/*). Setup: README-CLOUDFLARE.md.
  • Local development (UI):
    npm ci
    npx vite          # http://localhost:8080 — required for EasyMDE and friends
    Do not use node serve.mjs for the full editor: it serves files as-is and cannot resolve import … from 'easymde', so the UI shows “Editor failed to load”. serve.mjs remains only as a minimal static helper.
  • Local OAuth: npx wrangler pages dev . (or test against production). Plain Vite does not run /functions.
  • Serving a pre-built dist/ with any static host works for the UI without OAuth; GitHub login still needs Pages Functions.

Testing

Status

Check Status What it covers
Unit tests 🧪 npm test paths, markdown-tokens, reference-rewriter, file-mover, autosave state machine, draft/search stores, search sync, tabs (model + strip), editor teardown, git client CORS
Browser smoke test 🧪 CI real Chromium: editing, autosave + 409, tabs, create/delete, search, PDF, images, History toggle, HTML Live preview, Space near inline image
GitHub Actions 🔄 automatic runs both checks on push and pull_request

Current CI status is shown by the Tests badge at the top of this README. A red badge means at least one workflow check failed.

Running unit tests locally:

npm ci
npm test

End-to-end browser test (real Chromium, GitHub API replaced with mocked responses). Runs automatically in CI:

pip install playwright && playwright install chromium
npm ci
npx vite --port 8080 --strictPort &   # must be Vite, not serve.mjs
python3 e2e_smoke_test.py             # editing, hybrid autosave + 409, tabs, create/delete, search, Print, images, History/HTML, PDF/DOCX view + Download

Features

  • Sign in with GitHub (OAuth) — no manual Personal Access Token; the authorization and any 2FA/mobile confirmation happen on GitHub's side, and the app receives a ready-made access token that it keeps only in sessionStorage.
  • Layout modes — Source / Live (side-by-side source + preview) / Preview (preview only), toggled in the header. Preference is stored in localStorage.
  • Tabs — open as many files as you like and switch between them without losing your place: each tab keeps its text, undo history, cursor and scroll position. The active tab's preview re-renders automatically in Live/Preview mode. A dot on a tab means not on GitHub yet; closing a tab never loses work. Tabs are restored after a reload, and only the active one is fetched at startup.
  • Hybrid autosave + local drafts — typing is persisted to IndexedDB within ~400 ms (and again after ~10 s idle) so a crash or reload does not lose work. GitHub is updated only on Save (current file) or Commit (all dirty files). Status next to Save: ● Unsaved / ○ Local only — Save or Commit to push / ⟳ Saving to GitHub… / ✓ Saved to GitHub / ⚠ Save failed. Unsaved edits stay a local draft until Save, Commit or Discard.
  • 409 conflicts handled gracefully — the first sha conflict is retried silently with a freshly read sha; a second one in a row raises a banner offering Reload from GitHub / Overwrite.
  • Commit panel — multi-file commits with a message via the Git Data API (blobs → tree → commit → update ref). Dirty files show M/A badges in the file tree; the header Commit button shows the number of changes.
  • History panel — recent commits on the current branch; click a commit to see a per-file unified diff.
  • Full-text search — a search box in the sidebar header (Ctrl/Cmd+K focuses it from anywhere). Results replace the file tree as you type, each row showing the file path plus a one-line snippet with the matched term highlighted. Clicking a result highlights located matched words in the current text and jumps to the first occurrence of the longest word. Find provides next/previous and a current/total counter; Map shows match positions. Preview switches to Source. Search uses actual prefix/fuzzy tokens; editing Find switches to literal phrase search and enables Replace. Path-only matches or text that cannot be mapped to source may have no document highlight. The index persists in IndexedDB for 30 days; clearing the sidebar input restores the tree exactly as it was.
  • Backlinks — the Backlinks panel lists the notes that link to the open one: markdown links and [[wiki links]]; links inside code are ignored.
  • Link suggestions — typing [[ opens a list of notes that filters as you type; Enter inserts a root-absolute link [name](/path).
  • Image previews — resolved through the GitHub API (works with private repos too), not as direct links. This is the editor's own preview, not a separate static GitHub Preview.
  • Image resizing — drag the handle in the bottom-right corner of an image in the preview; the width is written straight into the markdown (<img ... width="...">).
  • Paste images from the clipboard — a copied image/screenshot from the clipboard is uploaded to the repo as a file and immediately inserted into the markdown.
  • Drag & drop images — drop a file into the editor window, or use the toolbar upload button. Automatically detects a shared images folder (looks for something like Asset//Images/, or the folder with the most existing images) and inserts a relative link, matching the style the rest of the notes already use.
  • Drag & drop folders — drop a folder from your file system onto the "Drop a folder here to upload" zone in the sidebar. Recursively uploads all files, preserving the folder structure.
  • Drag & drop files between folders — drag any file onto another folder in the tree on the left. Automatically rewrites the moved file's own links and fixes links in every other note in the repo that points to it (relative links, root-relative /path links, images, and plain [text](path) links alike).
  • Folder management — the "+ folder" button creates a new folder (via a .gitkeep file); right-click a folder in the tree → "Rename" / "Delete". Renaming updates references in .md files.
  • File and folder context menus — right-click any file or folder in the tree. For files the menu is unified across markdown, code, PDF and office: Open (or Open preview for images), Download, New file here, Copy as link (text / view-only), Rename, Delete. The menu closes on Escape and survives edge clicks.
  • Copy as link — right-click a file → “🔗 Copy as link” copies a repo-root absolute markdown link (/path/to/file.md) that stays valid when pasted into a note in another folder.
  • PDF & office view-only — click a .pdf / .docx / .xlsx (and related office extensions) in the tree to open it as a tab. Source shows a stub that editing is not supported; Live / Preview render the file (native PDF iframe, DOCX via Mammoth, XLSX via SheetJS). The toolbar Download button (and the tree menu item) save the original bytes to disk. Save / Discard / PDF-export stay disabled for these tabs.
  • Print… / Save as PDF — the Print… button builds a clean paper layout of the active markdown or HTML page (images resolved like in Preview) and opens the system print dialog. Choose Save as PDF / Microsoft Print to PDF there. This replaces the old html2canvas-based one-click export (which rasterized text and was fragile). Opening an existing .pdf from the repo is a separate view-only flow.

Known limitations

  • No refresh-token for the OAuth session — if "Expire user access tokens" is enabled on the GitHub OAuth App, the token dies after roughly 8 hours and the user is simply logged out (they need to click "Sign in with GitHub" again). This option is kept off by default — see README-CLOUDFLARE.md.
  • Toolbar icons (Font Awesome) ship with the Vite bundle via js/vendor.js. If an older note said CDN — if the network is unavailable, only the icon glyphs disappear; functionality is unaffected.
  • Reference rewriting handles markdown images, markdown links, [[wiki links]] and raw <img> tags; links like onenote:... and other external schemes are deliberately left untouched. A bare [[Name]] follows a rename only when no other note in the repository has the same name.
  • Print uses the browser’s own paginator; layout can differ slightly between Chrome, Firefox and Safari. Very tall images may still span pages — that is controlled by the browser, not by a custom page-break plugin.
  • Opening repo .pdf / office files is view-only (no in-browser editing). DOCX/XLSX preview loads Mammoth / SheetJS from a CDN on first use; offline or blocked CDNs fall back to the Download-only message. PPTX and legacy binary formats (.doc, .ppt, …) have no client-side renderer yet.
  • Full-text search degrades to session-only when IndexedDB is unavailable (private window, Safari ITP, storage disabled) or the origin quota is exceeded; search still works, but results are not persisted.

About

GitHub-native editor for Markdown, HTML and text files. OAuth, live preview, tabs, search, Commit/History, drafts, PDF. No local clone, no build step.DF export. No local clone, no build step.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages