No description
Find a file
neil 12990a9c5d Markdown: highlight nested blocks on their own
Every block now maps to its own source lines at any depth: quotes inside
quotes, paragraphs, code, quotes and lists inside list items, and each
table row. A list item's highlight covers only its own text, not its
nested items, and a parent quote is not highlighted with its children.
A Parser subclass marks each block in the rendered HTML; the output is
otherwise identical to render().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 03:01:21 -08:00
app Markdown: highlight nested blocks on their own 2026-11-17 03:01:21 -08:00
tests Syntax Highlighting tool, Markdown guide, unread share badge, Open in menu 2026-11-02 00:30:13 -08:00
.gitignore Keep server details out of the repo; deploy target comes from HOST or .deploy.env 2026-11-02 01:19:28 -08:00
CLAUDE.md Keep server details out of the repo; deploy target comes from HOST or .deploy.env 2026-11-02 01:19:28 -08:00
compose.yml Keep server details out of the repo; deploy target comes from HOST or .deploy.env 2026-11-02 01:19:28 -08:00
deploy.sh Configurable trusted proxy (FORWARDED_ALLOW_IPS); named deploy targets 2026-11-02 01:35:23 -08:00
README.md Configurable trusted proxy (FORWARDED_ALLOW_IPS); named deploy targets 2026-11-02 01:35:23 -08:00

tools

Small browser tools at https://tools.neilbantoc.dev:

Tool Path Runs
Markdown: edit, side by side, or full-page preview; syntax guide /markdown in the browser
Syntax Highlighting: VS Code / Android Studio themes, Format, copy as rich text, RTF /syntax in the browser
JSON editor: validate, format, compact, sort keys, editable live tree /json in the browser
Pastebin with 24-hour expiry /paste, /paste/<id>, /raw/<id> server (SQLite)

Drafts are saved in the browser's localStorage. Any tool marked opensPaste in the registry opens <path>?paste=<id> without overwriting the local draft, and appears in a paste's Open in menu. Share buttons (Markdown, Syntax Highlighting) create such a link; the paste counts as unread on the Pastebin nav badge until it's opened.

Syntax Highlighting

highlight.js tokenizes; the theme colors (js/tools/highlight-themes.js) are applied as inline styles in the same HTML shape VS Code puts on the clipboard, so pasting into Docs, Word, Slides, Outlook, Slack or Notion keeps them. RTF comes from the same tokens.

Format depends on the language:

Languages Engine
JS, TS, CSS/SCSS/Less, HTML, YAML, Markdown, GraphQL Prettier 3.9.10 (loaded on first use)
SQL sql-formatter 15.9.0 (on first use)
JSON the JSON tool's lossless printer
Kotlin, Java, C/C++/C#/Obj-C, Go, Rust, Swift, Dart, PHP, Scala, Groovy, Protobuf built-in brace formatter: re-indent, operator/comma/keyword spacing, K&R braces (Allman for C#), case bodies, continuation lines
Python built-in: block re-indent to 4, PEP 8 spacing (kwargs, slices, inline comments)
XML (non-HTML) built-in: one attribute per line for Android-style XML or long tags
anything else trailing whitespace and blank lines only

The built-in formatters only ever change whitespace: strings and comments are masked out first, and the tests assert that stripping all whitespace from input and output gives the same text, and that formatting twice changes nothing. They don't wrap long lines or reorder anything.

Layout

app/
  main.py            FastAPI: mounts every tools/*.py router, serves the single-page app
  tools/paste.py     pastebin API (+ startup/shutdown hooks for its expiry sweep)
  static/
    index.html       app shell
    js/registry.js   the tool list (sidebar, home page and routing all read it)
    js/app.js        router, nav, theme
    js/ui.js         shared helpers (el, toast, copy/download, store, segmented, …)
    js/tools/*.js    one module per tool
    vendor/          marked 18.1.2, DOMPurify 3.4.17, highlight.js 11.12.0, Prettier 3.9.10,
                     sql-formatter 15.9.0 + nearley 2.20.1 (vendored, no CDN)
compose.yml          production container (host network, 127.0.0.1:8090)
deploy.sh            tests, copies to /opt/tools on the server, rebuilds, waits for healthy
tests/               node --test tests/   (JSON parser/printer, formatters, highlighter)

No build step: the browser loads the ES modules directly.

Run locally

docker build -t tools:dev app
docker run --rm --network host -e PORT=18090 -v "$PWD/data:/data" tools:dev
# http://127.0.0.1:18090

data/ must be writable by uid 10001 (sudo chown 10001 data or chmod 777 data locally).

Deploy

HOST=root@<server> ./deploy.sh    # or put HOST=… in .deploy.env (gitignored)

On the server: /opt/tools/{compose.yml,app/,data/}, container tools, listening on 127.0.0.1:8090 only, so put a reverse proxy or tunnel connector on the same host in front of it. It trusts X-Forwarded-For only from FORWARDED_ALLOW_IPS (default loopback), which is what makes the per-IP paste limit work.

For a proxy that runs in Docker instead (reaching the app over a Docker network), add a compose.override.yml next to compose.yml on the server; deploy.sh leaves it alone:

services:
  tools:
    network_mode: !reset null
    networks: [proxy]
    environment:
      HOST: 0.0.0.0                       # inside the container's own network namespace
      FORWARDED_ALLOW_IPS: 172.16.0.0/12  # the proxy's Docker network
networks:
  proxy:
    external: true
    name: <the proxy's network>

Each server keeps its own pastes; instances don't share data.

Pastebin limits

5 MB per paste, 10 new pastes per IP and 1000 for the whole site per rolling 24 hours (logged in the DB with the IP as a keyed hash, so limits survive restarts and deleting a paste doesn't refund it). Expired pastes stop being served immediately and are deleted every 5 minutes. /raw/<id> is served as text/plain with a sandboxing CSP, so a paste can never run as a page on this origin. Each paste gets a delete token, kept in the creating browser's localStorage.