-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown_to_html.py
More file actions
62 lines (45 loc) · 1.28 KB
/
markdown_to_html.py
File metadata and controls
62 lines (45 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
Convert Markdown to HTML using DocForge API.
Usage: python markdown_to_html.py
"""
import requests
API_URL = "https://docforge-api.vercel.app/api/md-to-html"
markdown = """
# Getting Started with DocForge
DocForge is a **free API** for converting between common document formats.
## Supported Conversions
- Markdown to HTML
- CSV to JSON
- JSON to CSV
- YAML to JSON
- JSON to YAML
## Quick Example
```python
import requests
response = requests.post(
'https://docforge-api.vercel.app/api/md-to-html',
json={'markdown': '# Hello World'}
)
print(response.json()['html'])
```
> Free tier: 500 requests per day, no signup required.
"""
def convert():
response = requests.post(API_URL, json={"markdown": markdown})
if response.status_code != 200:
print(f"Error: {response.status_code}")
print(response.text)
return
result = response.json()
print("=== Metadata ===")
print(f"Word count: {result['meta']['wordCount']}")
print(f"Headings: {', '.join(result['meta']['headings'])}")
print()
print("=== HTML Output ===")
print(result["html"])
# Save to file
with open("output.html", "w", encoding="utf-8") as f:
f.write(result["html"])
print("\nSaved to output.html")
if __name__ == "__main__":
convert()