Office 문서를 Markdown으로 변환하기
Office Oxide의 모든 핸들에는 to_markdown() 메서드가 있습니다. 지원하는 여섯 가지 형식 중 어느 것에서든 GitHub Flavored Markdown — 제목, 표, 목록, 코드 블록 — 을 생성합니다. 대부분의 LLM 및 RAG 파이프라인이 사용해야 할 진입점입니다.
단일 호출
Rust
use office_oxide::to_markdown;
let md = to_markdown("report.docx")?;
std::fs::write("report.md", md)?;
Python
import office_oxide
md = office_oxide.to_markdown("report.docx")
open("report.md", "w").write(md)
JavaScript
import { toMarkdown } from 'office-oxide';
import { writeFileSync } from 'node:fs';
writeFileSync('report.md', toMarkdown('report.docx'));
Go
md, err := officeoxide.ToMarkdown("report.docx")
os.WriteFile("report.md", []byte(md), 0o644)
C#
File.WriteAllText("report.md", OfficeOxide.ToMarkdown("report.docx"));
C
int err = 0;
char *md = office_to_markdown("report.docx", &err); /* open + render in one call */
if (md) {
FILE *f = fopen("report.md", "w");
fputs(md, f);
fclose(f);
office_oxide_free_string(md);
}
재사용 가능한 핸들
Rust
let doc = office_oxide::Document::open("deck.pptx")?;
let md = doc.to_markdown();
Python
from office_oxide import Document
with Document.open("deck.pptx") as doc:
md = doc.to_markdown()
JavaScript
using doc = Document.open('deck.pptx');
const md = doc.toMarkdown();
C
int err = 0;
OfficeDocumentHandle *doc = office_document_open("deck.pptx", &err);
if (doc) {
char *md = office_document_to_markdown(doc, &err);
if (md) { /* use md */ office_oxide_free_string(md); }
office_document_free(doc);
}
WASM
import { WasmDocument } from 'office-oxide-wasm';
// WASM has no file I/O — read the bytes yourself, then open from bytes
const data = new Uint8Array(await (await fetch('/deck.pptx')).arrayBuffer());
using doc = new WasmDocument(data, 'pptx');
const md = doc.toMarkdown();
출력되는 내용
| 소스 요소 | Markdown |
|---|---|
DOCX 제목 (<w:pStyle w:val="Heading1"/> …) |
# Heading (스타일에 맞는 레벨) |
| DOCX 단락 | 단락 하나, 소프트 하이픈 제거 |
| DOCX 목록 항목 | - item 또는 1. item (번호 보존) |
| DOCX 표 | GFM 파이프 표 |
| XLSX 시트 | ## Sheet name + 범위마다 파이프 표 |
| XLSX 병합 셀 | 첫 번째 셀 내용, span 폐기 |
| PPTX 슬라이드 | ## Slide N + 본문, 노트는 인용 블록으로 추가 |
| PPTX 표 | 슬라이드 안에 인라인으로 들어가는 GFM 파이프 표 |
| 하이퍼링크 | [text](url) |
| 이미지 |  자리표시자 — 아래 “이미지” 참고 |
이미지
to_markdown()은 이미지를 파일명 자리표시자(예: )로 출력하지만 이미지 바이트는 추출하지 않습니다. Markdown은 텍스트 형식이기 때문입니다. 이미지를 꺼내려면 IR이나 형식별 접근 방법을 사용하세요:
from office_oxide import Document
with Document.open("report.docx") as doc:
ir = doc.to_ir()
for section in ir["sections"]:
for el in section["elements"]:
if el["kind"] == "Image":
print(el["filename"], len(el["data"]))
전체 스키마는 IR 추출을 참조하세요.
활용 사례
- RAG 인제스트 — Markdown은 LLM에 가장 친화적인 입력 형식입니다. 문서당 1회 패스, 결정론적 구조, HTML 노이즈 없음.
- 문서 인덱싱 — 제목이 자연스러운 청크 경계가 되고, 표는 그대로 쿼리할 수 있습니다.
- 마이그레이션 — 정적 사이트 생성기(Hugo, Astro, MkDocs)를 위한 DOCX → Markdown 변환.
- 콘텐츠 diff — Markdown diff는
.docx바이너리 diff보다 훨씬 검토하기 쉽습니다.
성능
to_markdown()은 plain_text()와 같은 수준의 속도로 동작합니다. 중간 크기 문서에서 보통 1~2배의 비용입니다. 전체 수치는 성능을 참고하세요.
관련 문서
- HTML 추출 — 스타일이 있는 출력이 필요할 때
- IR 추출 — 풍부한 파이프라인을 위한 구조화 JSON
- PDF for RAG — PDF용 동반 라이브러리
pdf_oxide