Documents
Home>Documents>AI>Agent>Contextifier

Contextifier RTF/DOCX Handler: Streaming Table Processing

5 min readJan 29, 2026Feb 22, 2026

Background: Adding RTF Support

The QA validation system needed to process RTF-format certificate files. RTF is a legacy format, but some systems still use it.

RTF Parsing Implementation

RTF uses its own markup language. I implemented the parser from scratch:

flowchart LR
    A[RTF 파일] --> B[RTF 파서]
    B --> C[제어 코드 해석]
    C --> D[그룹/토큰 분리]
    D --> E[텍스트 추출]
    E --> F[인코딩 변환]
    F --> G[ChunkResult]

Streaming Table Processing for DOCX

Large tables in DOCX files can cause memory issues. In v0.2.0, I refactored the table extraction to use a streaming approach.

# 기존: 전체 로드
def extract_tables_all(docx):
    all_tables = []
    for table in docx.tables:
        all_tables.append(parse_table(table))  # 메모리에 전부 적재
    return all_tables

# 개선: 스트리밍
def extract_tables_streaming(docx):
    for table in docx.tables:
        yield parse_table(table)  # 하나씩 처리

Splitting the Extractor/Processor Interface

DOCX table processing is now split into two distinct layers:

graph TD
    A[DOCX 파일] --> B[TableExtractor]
    B -->|원시 데이터| C[TableProcessor]
    C -->|포맷팅| D[Markdown 테이블]

    B -.->|인터페이스| E["extract(doc) -> RawTable"]
    C -.->|인터페이스| F["process(raw) -> str"]
  • TableExtractor: Extracts raw table data from the document
  • TableProcessor: Converts raw data into a target format such as Markdown

Unified format_table Function

In v0.2.0, the table formatting logic that had been scattered across individual handlers was consolidated into a single format_table function.

This refactor cut roughly 200 lines of code and ensured consistent output formatting across all handlers.

Tags
ContextifierRTFDOCXtable processingstreaming