Normalize dirty HTML and DOCX/RTF documents into clean, understandable HTML
import React, { ClipboardEvent, useState } from 'react';
import { cleanDocx } from '@prezly/docx-cleaner';
const MyComponent = () => {
const [value, setValue] = useState<string>('');
function handlePaste(event: ClipboardEvent<HTMLTextAreaElement>) {
const html = event.clipboardData.getData('text/html');
const rtf = event.clipboardData.getData('text/rtf');
try {
const cleanHtml = cleanDocx(html, rtf);
setValue(cleanHtml);
} catch (error) {
setValue(error.message);
console.error(error);
}
};
return <textarea value={value} onPaste={handlePaste} />;
};
export default MyComponent;
In order to start developing, run the build in watch mode.
npm install # install dependencies
npm run build:watch # start watcher
npm run release # reinstall & rebuild everything from scratch and...
# ...and run a wizard that'll guide you through publishing the npm package
Brought to you by Prezly.