@openthesis/docx-renderer
v0.1.0
Published
Template-driven DOCX renderer — converts structured JSON content into submission-ready .docx using a parsed style template
Maintainers
Readme
@openthesis/docx-renderer
Template-Driven DOCX Renderer — convert structured JSON content into submission-ready
.docxfiles.
What it does
template.json + content.json
│ │
└───────┬───────┘
▼
docx-renderer
(dolanmiu/docx)
│
▼
output.docxKey Features
- Template-driven — all formatting (fonts, sizes, margins, spacing) from parsed template
- Block dispatcher pattern — extensible content block → DOCX element routing
- Complete table formatting — gridlines, header shading, column widths
- Headers/footers/page numbers — configurable
- Three document types — thesis (学位论文), journal (期刊), official document (公文)
- Backward compatible — supports legacy
{cover_blocks, body_blocks}JSON format
Install
npm install @openthesis/docx-rendererUsage
import { renderDocument, createUSTBTemplate } from '@openthesis/docx-renderer';
import type { ThesisDocument } from '@openthesis/document-schema';
const template = createUSTBTemplate(); // or load from parsed template.json
const doc: ThesisDocument = {
type: 'thesis',
meta: { title: 'My Thesis' },
cover: [
{ type: 'centered_text', text: 'XX大学', font_size_pt: 26, bold: true },
{ type: 'page_break' },
],
sections: [
{
id: 'intro',
type: 'chapter',
title: 'Introduction',
content: [
{ type: 'paragraph', text: 'This is the introduction...' },
],
},
],
};
const buffer = await renderDocument({
outputPath: 'output.docx',
template,
document: doc,
});Supported Content Blocks
| Block Type | Description |
|-----------|-------------|
| heading1–heading4 | Section headings |
| paragraph / paragraph_no_indent | Body text |
| centered_text | Cover page titles |
| equation / equation_numbered | LaTeX equations |
| figure | Image with caption |
| table | Data table with caption |
| red_header | 公文红色发文机关标志 |
| document_number | 发文字号 |
| recipient_line | 主送/抄送机关 |
| signature_block | 发文机关署名+日期 |
| attachment_note | 附件说明 |
| spacer / page_break / horizontal_rule | Layout |
Related
- OpenThesis — Full document template engine
- @openthesis/template-parser — Parse DOCX → JSON
- @openthesis/equation-engine — LaTeX → OMML
License
MIT
