SuperAPI AI Directory

document-assembler

Office & productivity

View repository

Updated 10-16 00:04

About this skill

Document Assembly and Rendering

Assemble the content of each SAP chapter into a properly formatted Word document + manual review checklist.

Rendering Strategy (Three-Tier Approach)

  1. Pandoc (Primary Approach): Industrial-grade Markdown -> Word conversion, with styles controlled via the sap_reference.docx template
  2. python-docx assembly: Falls back to pure Python construction via assemble_docx.py when Pandoc is unavailable
  3. python-docx direct writing: The Agent directly uses the python-docx API to create Word (see the code template below)

python-docx Direct Writing Code Template (Key)

When you directly use the nodes tool to create a Word document,you must use the following native APIs, and embedding Markdown syntax in the text is prohibited.

from docx import Document
from docx.shared import Pt, Cm, RGBColor
from docx.enum.table import WD_TABLE_ALIGNMENT

doc = Document() doc.styles["Normal"].font.name = "Times New Roman" doc.styles["Normal"].font.size = Pt(11)

Headings (using # Markdown headings is prohibited)

doc.add_heading("1. Objectives, Endpoints, and Estimands", level=1) doc.add_heading("1.1 Primary Estimands", level=2)

Bold text (using bold)

para = doc.add_paragraph() run = para.add_run("Primary Estimand 1: ") run.bold = True para.add_run("Annualized rate of severe exacerbation events")

Lists

doc.add_paragraph("ITT population", style="List Bullet") doc.add_paragraph("Safety population", style="List Bullet")

Tables (using Markdown | col1 | col2 | syntax is prohibited)

table = doc.add_table(rows=3, cols=3) table.style = "Table Grid" table.alignment = WD_TABLE_ALIGNMENT.CENTER

Header row

for j, text in enumerate(["Attribute", "Description", "Source"]): cell = table.rows[0].cells[j] cell.text = text for run in cell.paragraphs[0].runs: run.bold = True run.font.size = Pt(9)

Data rows

table.rows[1].cells[0].text = "Population" table.rows[1].cells[1].text = "ITT population (all randomized patients)"

Page break

doc.add_page_break()

AI marker highlighting

from docx.oxml.ns import qn para = doc.add_paragraph() run = para.add_run("[AI-INFERRED] ") rpr = run._element.get_or_add_rPr() hl = rpr.makeelement(qn("w:highlight"), {qn("w:val"): "yellow"}) rpr.append(hl) para.add_run("DSMB will review safety data periodically")

doc.save(output_path)


## 禁止事项

- 禁止在 Word 段落文本中使用 `**bold**` Markdown 语法 -> 用 `run.bold = True`
- 禁止在 Word 段落文本中使用 `# Title` -> 用 `doc.add_heading()`
- 禁止在 Word 段落文本中使用 `| col |` 表格 -> 用 `doc.add_table()`
- 禁止在 Word 段落文本中使用 `---` 分隔线 -> 用 `doc.add_page_break()`
- 禁止在 Word 段落文本中使用 `- item` 列表 -> 用 `style="List Bullet"`

## Scripts

- [scripts/assemble_docx.py](scripts/assemble_docx.py) — 主组装脚本(Pandoc 优先 + python-docx 降级 + bold/标记后处理)
- [scripts/create_reference_docx.py](scripts/create_reference_docx.py) — 生成 Pandoc reference.docx 模板
- [scripts/generate_checklist.py](scripts/generate_checklist.py) — 审核清单生成

## Styles

- [styles/sap_reference.docx](styles/sap_reference.docx) — Pandoc 参考模板(ICH E9 / EU-PEARL 规范)
- [styles/formatting_rules.md](styles/formatting_rules.md) — 样式规格说明

## 标记处理

- `[AI-INFERRED]` -> 黄色高亮(AI 推断内容,需人工确认)
- `[PLACEHOLDER]` -> 红色高亮(占位符,需人工填写)