Spaces:
Sleeping
Sleeping
| const { convertHtmlToMarkdown } = htmlToSMD; | |
| document | |
| .getElementById("converter-form") | |
| .addEventListener("submit", async function (e) { | |
| e.preventDefault(); | |
| const urlInput = document.getElementById("url-input").value; | |
| const markdownOutput = document.getElementById("markdown-output"); | |
| const extractMainContent = document.getElementById( | |
| "extract-main-content" | |
| ).checked; | |
| const refifyUrls = document.getElementById("refify-urls").checked; | |
| const enableTableColumnTracking = document.getElementById( | |
| "enable-table-column-tracking" | |
| ).checked; | |
| const websiteDomain = document.getElementById("website-domain").value; | |
| const options = { | |
| extractMainContent, | |
| refifyUrls, | |
| enableTableColumnTracking, | |
| websiteDomain: websiteDomain || undefined, | |
| }; | |
| try { | |
| // Fetch HTML content from the server | |
| const response = await fetch( | |
| `/fetch-html?url=${encodeURIComponent(urlInput)}` | |
| ); | |
| if (!response.ok) { | |
| throw new Error("Failed to fetch HTML content"); | |
| } | |
| const htmlContent = await response.text(); | |
| // Convert HTML to Markdown | |
| const markdown = await convertHtmlToMarkdown(htmlContent, options); | |
| markdownOutput.textContent = markdown; | |
| } catch (error) { | |
| markdownOutput.textContent = "Error: " + error.message; | |
| } | |
| }); | |