Skip to content

Commit 727bbfa

Browse files
authored
1 parent 206d998 commit 727bbfa

File tree

1 file changed

+56
-24
lines changed

1 file changed

+56
-24
lines changed

jina-reader.html

+56-24
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,22 @@
1717
font-size: 24px;
1818
margin-bottom: 20px;
1919
}
20-
#url-input, #submit-btn, #markdown-raw, #copy-btn {
20+
#url-input, #format-select, #submit-btn, #markdown-raw, #copy-btn {
2121
font-size: 16px;
22-
padding: 10px;
22+
padding: 5px;
2323
margin-bottom: 10px;
2424
box-sizing: border-box;
2525
}
2626
#url-input {
27-
width: 70%;
27+
width: 50%;
28+
}
29+
#format-select {
30+
width: 20%;
2831
}
2932
#submit-btn, #copy-btn {
3033
background-color: #4CAF50;
3134
color: white;
32-
border: none;
35+
border: 2px solid #4CAF50;
3336
cursor: pointer;
3437
}
3538
#submit-btn:hover, #copy-btn:hover {
@@ -62,8 +65,13 @@
6265
}
6366
@media (min-width: 768px) {
6467
#url-input {
65-
width: 70%;
68+
width: 50%;
69+
display: inline-block;
70+
}
71+
#format-select {
72+
width: 20%;
6673
display: inline-block;
74+
margin-left: 2%;
6775
}
6876
#submit-btn {
6977
display: inline-block;
@@ -80,6 +88,12 @@ <h1>Jina Reader</h1>
8088
<p>An interface for the <a href="https://jina.ai/reader/">Jina Reader API</a>.</p>
8189
<form id="url-form">
8290
<input type="text" id="url-input" placeholder="Enter URL" required>
91+
<select id="format-select">
92+
<option value="markdown">Markdown</option>
93+
<option value="html">HTML</option>
94+
<option value="text">Text</option>
95+
<option value="llm_markdown">LLM Markdown</option>
96+
</select>
8397
<button type="submit" id="submit-btn">Submit</button>
8498
</form>
8599
<div id="loading">Loading...</div>
@@ -92,6 +106,7 @@ <h1>Jina Reader</h1>
92106
<script>
93107
const urlForm = document.getElementById('url-form');
94108
const urlInput = document.getElementById('url-input');
109+
const formatSelect = document.getElementById('format-select');
95110
const loading = document.getElementById('loading');
96111
const result = document.getElementById('result');
97112
const markdownRaw = document.getElementById('markdown-raw');
@@ -101,34 +116,51 @@ <h1>Jina Reader</h1>
101116
urlForm.addEventListener('submit', async (e) => {
102117
e.preventDefault();
103118
const url = urlInput.value;
119+
const format = formatSelect.value;
104120
if (!url) return;
105121

106122
loading.style.display = 'block';
107123
result.style.display = 'none';
108124

109125
try {
110-
const response = await fetch(`https://r.jina.ai/${url}`);
111-
const markdown = await response.text();
112-
markdownRaw.value = markdown;
113-
const htmlContent = `
114-
<html>
115-
<head>
116-
<style>
117-
body { font-family: Helvetica, sans-serif; line-height: 1.6; color: #333; }
118-
img { max-width: 100%; height: auto; }
119-
</style>
120-
</head>
121-
<body>
122-
${marked.parse(markdown)}
123-
</body>
124-
</html>
125-
`;
126+
let fetchOptions = {
127+
method: 'GET'
128+
};
129+
130+
if (format !== 'llm_markdown') {
131+
fetchOptions.headers = {
132+
"X-Return-Format": format
133+
};
134+
}
135+
136+
const response = await fetch(`https://r.jina.ai/${url}`, fetchOptions);
137+
const content = await response.text();
138+
markdownRaw.value = content;
139+
140+
let htmlContent;
141+
if (format === 'html') {
142+
htmlContent = content;
143+
} else {
144+
htmlContent = `
145+
<html>
146+
<head>
147+
<style>
148+
body { font-family: Helvetica, sans-serif; line-height: 1.6; color: #333; }
149+
img { max-width: 100%; height: auto; }
150+
</style>
151+
</head>
152+
<body>
153+
${format === 'text' ? `<pre>${content}</pre>` : marked.parse(content)}
154+
</body>
155+
</html>
156+
`;
157+
}
126158
markdownRendered.srcdoc = htmlContent;
127159
result.style.display = 'block';
128160
} catch (error) {
129-
console.error('Error fetching markdown:', error);
130-
markdownRaw.value = 'Error fetching markdown. Please try again.';
131-
markdownRendered.srcdoc = '<p>Error fetching markdown. Please try again.</p>';
161+
console.error('Error fetching content:', error);
162+
markdownRaw.value = 'Error fetching content. Please try again.';
163+
markdownRendered.srcdoc = '<p>Error fetching content. Please try again.</p>';
132164
result.style.display = 'block';
133165
} finally {
134166
loading.style.display = 'none';

0 commit comments

Comments
 (0)