-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml-to-markdown
More file actions
150 lines (132 loc) · 3.56 KB
/
html-to-markdown
File metadata and controls
150 lines (132 loc) · 3.56 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML to Markdown Converter</title>
<link rel="stylesheet" href="styles.css">
<style>body {
font-family: 'Arial', sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container {
background-color: white;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 800px;
padding: 30px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.converter-box {
display: flex;
flex-direction: column;
}
.input-section, .output-section {
margin-bottom: 20px;
}
textarea {
width: 100%;
min-height: 200px;
resize: vertical;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-family: monospace;
}
.button-section {
display: flex;
justify-content: center;
gap: 10px;
margin-bottom: 20px;
}
button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #45a049;
}
#copyBtn {
background-color: #2196F3;
margin-top: 10px;
}
#copyBtn:hover {
background-color: #1E88E5;
}
@media (max-width: 600px) {
.container {
width: 95%;
padding: 15px;
}
}
</style>
</head>
<body>
<div class="container">
<h1>HTML to Markdown Converter</h1>
<div class="converter-box">
<div class="input-section">
<h2>Input HTML</h2>
<textarea id="htmlInput" placeholder="Paste your HTML here..."></textarea>
</div>
<div class="button-section">
<button id="convertBtn">Convert →</button>
<button id="clearBtn">Clear</button>
</div>
<div class="output-section">
<h2>Markdown Output</h2>
<textarea id="markdownOutput" readonly placeholder="Markdown will appear here..."></textarea>
<button id="copyBtn">Copy Markdown</button>
</div>
</div>
</div>
<script src="https://unpkg.com/turndown/dist/turndown.js"></script>
<script src="script.js">document.addEventListener('DOMContentLoaded', () => {
const htmlInput = document.getElementById('htmlInput');
const markdownOutput = document.getElementById('markdownOutput');
const convertBtn = document.getElementById('convertBtn');
const clearBtn = document.getElementById('clearBtn');
const copyBtn = document.getElementById('copyBtn');
// Initialize Turndown converter
const turndownService = new TurndownService();
// Convert HTML to Markdown
convertBtn.addEventListener('click', () => {
try {
const html = htmlInput.value;
const markdown = turndownService.turndown(html);
markdownOutput.value = markdown;
} catch (error) {
alert('Error converting HTML to Markdown: ' + error.message);
}
});
// Clear inputs
clearBtn.addEventListener('click', () => {
htmlInput.value = '';
markdownOutput.value = '';
});
// Copy Markdown to clipboard
copyBtn.addEventListener('click', () => {
markdownOutput.select();
document.execCommand('copy');
alert('Markdown copied to clipboard!');
});
});
</script>
</body>
</html>