The HTML to Text API allows you to convert HTML content into plain text format. It provides a simple and efficient way to extract textual data from HTML documents, web pages, or any HTML-encoded content.
POST /api/convert
This endpoint accepts a JSON payload with the HTML content and converts it to plain text.
Parameter | Type | Description |
---|---|---|
html |
string | Required. The HTML content to be converted. |
whitelist |
string[] | Optional. A list of whitelisted HTML tags. |
blacklist |
string[] | Optional. A list of blacklisted HTML tags. |
POST /api/convert
Content-Type: application/json
{
"html": "<h1>Hello, World!</h1><p>This is an example HTML content.</p>",
"whitelist": ["h1", "p"]
}
HTTP/1.1 200 OK
Content-Type: application/json
{
"text": "Hello, World! This is an example HTML content."
}
HTTP Status Code | Description |
---|---|
400 Bad Request | If the required html parameter is missing or invalid. |
500 Internal Server Error | In case of server-side errors. |
whitelist
parameter allows you to specify the HTML tags that should be included in the conversion process.blacklist
parameter allows you to specify the HTML tags that should be excluded from the conversion process.text
field.fetch('https://api.example.com/api/convert', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
html: '<h1>Hello, World!</h1><p>This is an example HTML content.</p>',
whitelist: ['h1', 'p']
})
})
.then(response => response.json())
.then(data => {
console.log(data.text);
})
.catch(error => {
console.error(error);
});