About this tool
This tool cleans HTML, which is the code behind a web page. It removes scripts and other unsafe or unwanted parts, strips styles and empty pieces, and keeps a safe set of tags. It can also give you only the main article, plain text or Markdown (text with simple marks). It tells you how much it removed.
For example, you paste text copied from Word and clean it before putting it on your website.
How to use it
- Choose this tool.
- Add your HTML file, or paste the code into the box.
- Choose the form you want: tidy HTML, main article only, plain text or Markdown.
- Choose what to do with links, pictures and styles, if you like.
- Press Generate, then copy or download the result.
What you get back
You get the cleaned result, which you can copy or download, along with counts of what was removed.
GOOD TO KNOW
The HTML is parsed, never run, and nothing is fetched. mode=article needs real article text (400 when none is found). Counts as one document.
TEST IT LIVE
Try Clean HTML in the Studio
One click opens the Studio with this tool already selected. Add your file and see the result in seconds.
Family
Documents
Plan
Free
Method
POST
Endpoint
/v1/documents/clean-html
Tool ID
documents.clean-html
Authentication
API key
Accepts
Text and settings
Background jobs
Yes
Usage group
Documents
For developers
Use it from your code
cURL
curl -X POST "https://app.h2i.davixlabs.io/v1/documents/clean-html" \
-H "X-Api-Key: $DAVIX_H2I_API_KEY" \
-F 'html=<div onclick="x()"><h1>Title</h1><script>alert(1)</script></div>' \
-F 'mode=sanitize' \
-F 'allow_tags=["p","a","strong"]'Node.js
const { DavixH2I } = require('@davixlabs/h2i-sdk');
const h2i = new DavixH2I({ apiKey: process.env.DAVIX_H2I_API_KEY, baseUrl: process.env.DAVIX_H2I_URL });
const result = await h2i.documents.cleanHtml({
"html": "<div onclick=\"x()\"><h1>Title</h1><script>alert(1)</script></div>",
"mode": "sanitize",
"allow_tags": "[\"p\",\"a\",\"strong\"]"
});
console.log(result.data, result.requestId);PHP
<?php
require 'vendor/autoload.php';
$h2i = new \Davix\H2I\Client(['apiKey' => getenv('DAVIX_H2I_API_KEY'), 'baseUrl' => getenv('DAVIX_H2I_URL')]);
$result = $h2i->documents()->cleanHtml([
'html' => '<div onclick="x()"><h1>Title</h1><script>alert(1)</script></div>',
'mode' => 'sanitize',
'allow_tags' => '["p","a","strong"]',
]);
echo $result->requestId;More in Documents
