JSPM

  • Created
  • Published
  • Downloads 15
  • Score
    100M100P100Q51060F
  • License ISC

A modular, open source library for converting HTML content into professional document formats. Initially focused on HTML-to-DOCX conversion, with planned support for PDF and XLSX. Built with TypeScript, it features a core HTML parsing engine and separate format-specific modules, offering a unified API for seamless integration.

Package Exports

  • html-to-document
  • html-to-document/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (html-to-document) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npm version Build Status License: ISC

html‑to‑document

Convert any HTML into production‑ready documents — DOCX today, PDF/XLSX.

html‑to‑document parses HTML into an intermediate, format‑agnostic tree and then feeds that tree to adapters (e.g. DOCX, PDF).
Write HTML → get Word, PDFs, spreadsheets, and more — all with one unified TypeScript API.


✨ Key Features

Feature Description
Format‑agnostic core Converts HTML into a reusable DocumentElement[] structure
DOCX adapter (built‑in) Powered by docx with rich style support
Pluggable adapters Add your own adapter for PDF, XLSX, Markdown, etc.
Style mapping engine Map CSS → document styles and set per‑format defaults
Custom tag handlers Override or extend how any HTML tag is parsed
Middleware pipeline Transform or sanitise HTML before parsing

📦 Installation

npm install html-to-document

🚀 Quick Start

import { init } from 'html-to-document';
import fs from 'fs';

const converter = init();                // default DOCX adapter & middleware
const html = '<h1>Hello World</h1>';

const buffer = await converter.convert(html, 'docx');   // ↩️ Buffer in Node / Blob in browser
fs.writeFileSync('output.docx', buffer);

Need just the parsed structure?

const elements = await converter.parse('<p>Some HTML</p>');
console.log(elements); // => DocumentElement[]

📚 Documentation & Demo

Resource Link
Full Docs https://html-to-document.vercel.app/

🛠 Extending

  • Style mappings: fine‑tune CSS → DOCX/PDF with StyleMapper
  • Tag handlers: intercept <custom-tag> → your own DocumentElement
  • Custom adapters: implement IDocumentConverter to target new formats

See the Extensibility Guide.


🧑‍💻 Contributing

Contributions are welcome!
Please read CONTRIBUTING.md and follow the Code of Conduct.


📝 Changelog

All notable changes are documented in CHANGELOG.md.


📄 License

ISC — a permissive, MIT‑style license that allows free use, modification, and distribution without requiring permission.