29 lines
664 B
Python
29 lines
664 B
Python
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class ConvertRequest(BaseModel):
|
|
markdown: str
|
|
width: int = 80
|
|
|
|
|
|
class ConvertResponse(BaseModel):
|
|
micron: str
|
|
|
|
|
|
@router.post("/convert", response_model=ConvertResponse)
|
|
async def convert(req: ConvertRequest):
|
|
try:
|
|
from md2txt import convert_markdown
|
|
|
|
result = convert_markdown(
|
|
req.markdown,
|
|
width=req.width,
|
|
renderer_name="micron",
|
|
)
|
|
return ConvertResponse(micron=result)
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f"Conversion failed: {e}")
|