epub-lsp

module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2026 License: MIT

README

EPUB LSP

A Language Server Protocol implementation for EPUB source files. Validates XHTML content documents, OPF package files, navigation documents, and CSS with rules based on epubcheck and ace. Pure Go, no Java or Node.js dependencies.

Installation

Download Binary

Download prebuilt binaries from GitHub Releases.

Available for Linux, macOS, and Windows (amd64/arm64).

Install from Source
go install github.com/toba/epub-lsp/cmd/epub-lsp@latest
Build from Source
git clone https://github.com/toba/epub-lsp.git
cd epub-lsp
go build -o epub-lsp ./cmd/epub-lsp
go test ./...

Editor Integration

epub-lsp communicates over stdin/stdout using JSON-RPC per the LSP specification. Point your editor's LSP client at the epub-lsp binary for .opf, .xhtml, .html, and .css files.

A Zed extension is available at gubby.

Supported File Types

Extension Type Detection
.opf OPF package document Extension
.xhtml XHTML content document Extension
.html HTML content document Extension
.css CSS stylesheet Extension
.ncx NCX navigation (EPUB 2) Extension

Navigation documents (.xhtml/.html containing epub:type="toc") are detected via content sniffing and receive additional nav-specific validation.

Validators

OPF Package Document
  • Required metadata: dc:identifier, dc:title, dc:language
  • unique-identifier must reference a valid dc:identifier/@id
  • Manifest integrity: unique IDs, valid media-types, no duplicate hrefs
  • Spine itemrefs must reference existing manifest items
XHTML Content Document
  • XHTML namespace (xmlns="http://www.w3.org/1999/xhtml") required
  • xml:lang and lang consistency
  • <img> elements must have alt attribute
Navigation Document
  • <nav epub:type="toc"> required with <ol> child
  • No remote links allowed in navigation
  • Optional page-list and landmarks detection
  • TOC link order vs spine order consistency
CSS Stylesheet
  • Forbidden properties: direction, unicode-bidi
  • Position warnings: fixed, absolute
  • @font-face format validation (woff, woff2, opentype, truetype)
  • UTF-8 encoding check
  • Unclosed brace detection
Cross-File Resource Validation
  • Manifest items reference files that exist in the workspace
  • Resources referenced in content (<img>, <link>, <audio>, <video>, <source>) exist in the OPF manifest
Accessibility (based on DAISY Ace rules)
  • Metadata: schema:accessMode, schema:accessibilityFeature, schema:accessibilityHazard, schema:accessibilitySummary, schema:accessModeSufficient with value validation and contradictory hazard detection
  • OPF: dc:title and dc:language presence
  • Page navigation: printPageNumbers requires page-list nav and pagebreak markers; page-list requires dc:source; page-list references validated against content IDs
  • Structure: epub:type to ARIA role mapping, pagebreak labels, heading level ordering, table captions, form input labels

Architecture

cmd/epub-lsp/           LSP server (stdin/stdout JSON-RPC)
  lsp/                  Protocol types, message framing, handlers
internal/epub/          Core types (Diagnostic, FileType, Position)
  parser/               XML and CSS parsers with offset tracking
  testutil/             Shared test helpers
  validator/            Registry and Validator interface
    opf/                OPF package validation + OPF parsing
    xhtml/              XHTML namespace and structure checks
    nav/                Navigation document validation
    css/                CSS property and syntax checks
    resource/           Cross-file manifest and content reference checks
    accessibility/      Accessibility metadata, structure, and page checks

Validators register with a central Registry and are dispatched by file type. Files within a workspace are validated concurrently. Cross-file context (manifest items, spine order, file contents) is passed via WorkspaceContext.

License

MIT License - see LICENSE for details.

Directories

Path Synopsis
cmd
epub-lsp command
Command epub-lsp provides a Language Server Protocol server for EPUB validation.
Command epub-lsp provides a Language Server Protocol server for EPUB validation.
epub-lsp/lsp
Package lsp implements LSP message types and handlers for EPUB validation.
Package lsp implements LSP message types and handlers for EPUB validation.
internal
epub
Package epub provides core types for EPUB validation.
Package epub provides core types for EPUB validation.
epub/formatter
Package formatter provides XML and CSS formatting for EPUB documents.
Package formatter provides XML and CSS formatting for EPUB documents.
epub/parser
Package parser provides XML and CSS parsing helpers for EPUB validation.
Package parser provides XML and CSS parsing helpers for EPUB validation.
epub/testutil
Package testutil provides shared test helpers for EPUB validator tests.
Package testutil provides shared test helpers for EPUB validator tests.
epub/validator
Package validator provides the EPUB validation framework.
Package validator provides the EPUB validation framework.
epub/validator/accessibility
Package accessibility validates EPUB accessibility metadata and structure per the Ace (daisy/ace) rule set.
Package accessibility validates EPUB accessibility metadata and structure per the Ace (daisy/ace) rule set.
epub/validator/css
Package css validates CSS stylesheets for EPUB compliance.
Package css validates CSS stylesheets for EPUB compliance.
epub/validator/nav
Package nav validates EPUB navigation documents.
Package nav validates EPUB navigation documents.
epub/validator/opf
Package opf validates OPF package documents.
Package opf validates OPF package documents.
epub/validator/resource
Package resource validates cross-file resource references in EPUB.
Package resource validates cross-file resource references in EPUB.
epub/validator/xhtml
Package xhtml validates XHTML content documents.
Package xhtml validates XHTML content documents.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL