@pablopunk/docs-soap
v1.2.1
Published
A utility for cleaning Google Docs clipboard content into valid HTML
Downloads
4
Maintainers
Readme
docs-soap
docs-soap is a small (1.5kb minified/gzipped), simple library that can be used to transform clipboard contents from Google Docs into readable HTML. This library was born from the need to parse clipboard content from Google Docs into a DraftJS Rich Text Editor and fits nicely into Draft's handlePastedText
hook.
This project was developed for use in a client-side project. To use in a Node environment, your project will also require jsdom-global.
New in 1.2.0
- The library is now ES5 compatible for use with create-react-app. This is a minor release to avoid breaking anyone's code who depends on the ES6 functionality.
Exported API
module.exports = {
default: docsSoap,
docsSoap,
parseHTML
};
Testing
Tests are written in Mocha, using expect
for assertions. npm run test
will run all tests in the test/
directory, allowing you to test the entire library's functionality at once. All contributions to the repository are expected to contain accompanying tests.
In the examples/
directory, there's a simple HTML example that, after running npm run build
in the project root, can be used to test your changes or just see the library in action.
Installation
ESM
yarn add docs-soap
import docsSoap from 'docs-soap';
CommonJS
yarn add docs-soap
const docsSoap = require('docs-soap').default;
Script tag
<script src="https://unpkg.com/[email protected]/dist/docs-soap.min.js"></script>
var docsSoap = window.docsSoap;
Usage
const html = '<body id="docs-internal-guid-1234"><b><span style="font-weight:700">bold text</span><span style="font-style:italic">some italic text</span></b></body>';
const clean = docsSoap(html);
console.log(clean); /* "<body><strong>some bold text</strong><i>some italic text</i></body>" */