feat: add omml api
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
"""Markdown to DOCX conversion endpoint."""
|
||||
"""Format conversion endpoints."""
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from fastapi.responses import Response
|
||||
|
||||
from app.core.dependencies import get_converter
|
||||
from app.schemas.convert import MarkdownToDocxRequest
|
||||
from app.schemas.convert import MarkdownToDocxRequest, LatexToOmmlRequest, LatexToOmmlResponse
|
||||
from app.services.converter import Converter
|
||||
|
||||
router = APIRouter()
|
||||
@@ -28,3 +28,39 @@ async def convert_markdown_to_docx(
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Conversion failed: {e}")
|
||||
|
||||
|
||||
@router.post("/latex-to-omml", response_model=LatexToOmmlResponse)
|
||||
async def convert_latex_to_omml(
|
||||
request: LatexToOmmlRequest,
|
||||
converter: Converter = Depends(get_converter),
|
||||
) -> LatexToOmmlResponse:
|
||||
"""Convert LaTeX formula to OMML (Office Math Markup Language).
|
||||
|
||||
OMML is the math format used by Microsoft Word and other Office applications.
|
||||
This endpoint is separate from the main OCR endpoint due to the performance
|
||||
overhead of OMML conversion (requires creating a temporary DOCX file).
|
||||
|
||||
Args:
|
||||
request: Contains the LaTeX formula to convert (without $ or $$ delimiters).
|
||||
|
||||
Returns:
|
||||
OMML representation of the formula.
|
||||
|
||||
Example:
|
||||
```bash
|
||||
curl -X POST "http://localhost:8000/api/v1/convert/latex-to-omml" \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-d '{"latex": "\\\\frac{a}{b} + \\\\sqrt{c}"}'
|
||||
```
|
||||
"""
|
||||
if not request.latex or not request.latex.strip():
|
||||
raise HTTPException(status_code=400, detail="LaTeX formula cannot be empty")
|
||||
|
||||
try:
|
||||
omml = converter.convert_to_omml(request.latex)
|
||||
return LatexToOmmlResponse(omml=omml)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
except RuntimeError as e:
|
||||
raise HTTPException(status_code=503, detail=str(e))
|
||||
|
||||
Reference in New Issue
Block a user