Markdown/HTML을 DOCX로 변환하는 문서 변환 라이브러리 (Mermaid/LaTeX 지원)
Project description
helper-md-doc
Markdown/HTML을 DOCX로 변환하는 Python 라이브러리 (Mermaid 다이어그램 및 LaTeX 수식 지원)
주요 기능
- Markdown → HTML 변환: Mermaid 다이어그램과 LaTeX 수식을 PNG 이미지로 렌더링
- HTML → DOCX 변환: 이미지와 수식을 임베딩하여 DOCX 생성
- Markdown → DOCX 직접 변환: 원스텝 변환 지원
- Mermaid 지원: 플로우차트, 시퀀스 다이어그램 등 자동 렌더링
- LaTeX 수식 지원: KaTeX 기반 수식 렌더링
- 이미지 임베딩: Base64 인코딩 또는 파일 경로 지원
설치
기본 설치
pip install helper-md-doc
# 테스트 서버
pip install --index-url https://test.pypi.org/simple/ helper-md-doc
Playwright 브라우저 설치 (필수)
playwright install chromium
Pandoc 설치 (필수)
- Windows: https://pandoc.org/installing.html
- Mac:
brew install pandoc - Linux:
sudo apt-get install pandoc
사용법
1. Markdown → HTML 변환
from helper_md_doc import md_to_html
md_text = """
# 제목
이것은 **Markdown** 문서입니다.
## Mermaid 다이어그램
```mermaid
graph LR
A[시작] --> B[처리]
B --> C[종료]
LaTeX 수식
인라인 수식: $E = mc^2$
블록 수식: $$ \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $$ """
html = md_to_html(md_text, title="문서 제목", use_base64=True) print(html)
### 2. HTML → DOCX 변환
```python
from helper_md_doc import html_to_doc
html_to_doc("input.html", "output.docx")
3. Markdown → DOCX 직접 변환
from helper_md_doc import md_to_doc
md_to_doc("input.md", "output.docx", title="문서 제목")
4. 역방향 변환
from helper_md_doc import doc_to_html, html_to_md, md_to_text
# DOCX → HTML (이미지 base64 임베딩)
doc_to_html("input.docx", "output.html")
# HTML → Markdown
html_to_md("input.html", "output.md")
# HTML → GitHub Flavored Markdown
html_to_md("input.html", "output.md", md_variant="gfm")
# Markdown → 순수 텍스트 (수식 제거)
md_to_text("input.md", "output.txt")
# Markdown → 순수 텍스트 (수식 원문 유지)
md_to_text("input.md", "output.txt", keep_math=True)
5. CLI 사용
# Markdown → HTML
md2html input.md -o output.html --base64
# HTML → DOCX
html2doc input.html -o output.docx
# Markdown → DOCX
md2doc input.md -o output.docx --title "문서 제목"
# Markdown → PDF
md2pdf input.md -o output.pdf
# HTML → PDF
html2pdf input.html -o output.pdf
# DOCX → HTML (역변환)
doc2html input.docx -o output.html
# DOCX → HTML (이미지 별도 파일)
doc2html input.docx --no-embed
# HTML → Markdown (역변환)
html2md input.html -o output.md
# HTML → GitHub Flavored Markdown
html2md input.html --variant gfm
# Markdown → 순수 텍스트 (역변환)
md2text input.md -o output.txt
# Markdown → 순수 텍스트 (수식 원문 유지)
md2text input.md --keep-math
또는 모듈로 실행:
# Markdown → HTML
python -m helper_md_doc.helper_md_html input.md -o output.html --base64
# HTML → DOCX
python -m helper_md_doc.helper_html_doc input.html -o output.docx
# Markdown → DOCX
python -m helper_md_doc.helper_md_doc input.md -o output.docx --title "문서 제목"
# DOCX → HTML (역변환)
python -m helper_md_doc.helper_doc_html input.docx -o output.html
# HTML → Markdown (역변환)
python -m helper_md_doc.helper_html_md input.html -o output.md
# Markdown → 순수 텍스트 (역변환)
python -m helper_md_doc.helper_md_text input.md -o output.txt
의존성
- markdown (>=3.7.0): Markdown 파싱
- playwright (>=1.40.0): Mermaid/LaTeX 렌더링
- pypandoc (>=1.13): DOCX 변환
개발
# 저장소 클론
git clone https://github.com/c0z0c-helper/helper_md_doc.git
cd helper_md_doc
# 편집 모드 설치
pip install -e .
# 개발 의존성 설치
pip install -r requirements-dev.txt
# 테스트 실행
pytest
라이센스
MIT License
본 패키지는 다음 서드파티 라이브러리를 포함합니다:
- KaTeX (MIT License) - LaTeX 수식 렌더링
- KaTeX Fonts (SIL Open Font License 1.1) - 수식용 폰트
- Mermaid (MIT License) - 다이어그램 렌더링
자세한 내용은 THIRD_PARTY_LICENSES.md를 참조하세요.
기여
버그 리포트나 기능 제안은 GitHub Issues에 등록해주세요.
변경 이력
v0.5.1(2025-12-09)
- 최초 릴리스
v0.5.2(2025-12-09)
- BOM 처리
- ** 속성 적용
v0.5.5(2025-12-11)
- 종속 라이브러리 설치
v0.5.6(2026-03-19)
- 랜더링 최적화
v0.5.8(2026-03-21)
- doc 변환시 기본 폰트 D2Coding 적용
- D2Coding 폰트 자동 설치
v0.5.9(2026-04-18)
- HTML → PDF 변환 기능 추가
- Markdown → PDF 변환 기능 추가
html2pdf,md2pdfCLI 추가
v0.5.11(2026-05-01)
math_mode기본값 변경:omml→mathml(세부 튜닝 가능, 품질 향상)- 역방향 변환 기능 추가
- DOCX → HTML 변환 (
doc_to_html,doc2htmlCLI) - HTML → Markdown 변환 (
html_to_md,html2mdCLI) - Markdown → 순수 텍스트 변환 (
md_to_text,md2textCLI)
- DOCX → HTML 변환 (
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file helper_md_doc-0.5.11.tar.gz.
File metadata
- Download URL: helper_md_doc-0.5.11.tar.gz
- Upload date:
- Size: 7.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c455888440206c72fa549cde0ea5a73648e6ded0c4d222945cffc68931098da5
|
|
| MD5 |
229ca958895730fee7069ef51ff16c45
|
|
| BLAKE2b-256 |
f32bf046df43f58f8c0d4a7b7463e5555a9d936eb72e7275456151a164e2b854
|
File details
Details for the file helper_md_doc-0.5.11-py3-none-any.whl.
File metadata
- Download URL: helper_md_doc-0.5.11-py3-none-any.whl
- Upload date:
- Size: 7.5 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b16dbc44e56f3fbda683ff4a8cef20da6cb42503254f145057848b09def69f5
|
|
| MD5 |
1975a08453db5624c83d60f790d3fea1
|
|
| BLAKE2b-256 |
adbad2c3d01ca3a7458f752385e9c46c60c4319ba3e4f24a4346174046c050d5
|