Skip to content

Commit

Permalink
move to TravisCI build (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
aem authored Jun 27, 2016
1 parent ae8429f commit 8903753
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
5 changes: 0 additions & 5 deletions .hound.yml

This file was deleted.

7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- "6"
script:
- npm run build
- npm run lint
- npm run test
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# docs-soap
# docs-soap [![Build Status](https://travis-ci.org/aem/docs-soap.svg?branch=master)](https://travis-ci.org/aem/docs-soap) [![npm version](https://badge.fury.io/js/docs-soap.svg)](https://badge.fury.io/js/docs-soap)
docs-soap is a small, 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](https://www.github.com/facebook/draft-js) Rich Text Editor and thus certain W3C HTML requirements aren't necessarily maintained. For example, while W3C requires unordered lists to be surrounded by `<ul>` tags, most HTML conversion engines will handle the unwrapped list items, so that standard is ignored.

This project was developed for use in a client-side project. To use in a Node environment, your project will also require [jsdom](https://www.npmjs.com/package/jsdom).
Expand All @@ -19,7 +19,7 @@ Tests are written in Mocha, using `expect` for assertions. `npm run test` will r
npm install --save docs-soap
```
```js
import { docsSoap } from 'docs-soap';
import docsSoap from 'docs-soap';
const html = '<body><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>" */
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"test": "mocha --compilers js:babel-register test",
"lint": "eslint --ext '.js' ./src"
},
"dependencies": {
"invariant": "^2.2.1"
},
"devDependencies": {
"babel-cli": "^6.9.0",
"babel-core": "^6.7.7",
Expand Down
16 changes: 8 additions & 8 deletions src/docsSoap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import invariant from 'invariant';
import parseHTML from './parseHTML';
const parseHTML = require('./parseHTML');

const DOCS_BOLD_WEIGHT = '700';
const ITALIC_STYLE = 'italic';
Expand Down Expand Up @@ -123,11 +122,12 @@ const getCleanDocument = (dirty) => {
return body;
};

export default (clipboardContent) => {
invariant(
typeof clipboardContent === 'string',
`Expected 'clipboardContent' to be a string of HTML, received ${typeof clipboardContent}`
);
invariant(clipboardContent.length > 0, 'Expected clipboardContent to have content, received empty string');
module.exports = (clipboardContent) => {
if (typeof clipboardContent !== 'string') {
throw new Error(`Expected 'clipboardContent' to be a string of HTML, received ${typeof clipboardContent}`);
}
if (clipboardContent.length <= 0) {
throw new Error('Expected clipboardContent to have content, received empty string');
}
return getCleanDocument(parseHTML(clipboardContent.replace(/(\r\n|\n|\r)/, ''))).outerHTML;
};
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import docsSoap from './docsSoap';
import parseHTML from './parseHTML';
const docsSoap = require('./docsSoap');
const parseHTML = require('./parseHTML');

module.exports = {
export default docsSoap;

export {
docsSoap,
parseHTML
};
4 changes: 2 additions & 2 deletions src/parseHTML.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function parseHTML(html) {
module.exports = function parseHTML(html) {
let doc = void 0;
if (typeof DOMParser !== 'undefined') {
const parser = new DOMParser();
Expand All @@ -8,4 +8,4 @@ export default function parseHTML(html) {
doc.documentElement.innerHTML = html;
}
return doc.body;
}
};
2 changes: 1 addition & 1 deletion test/docsSoapSpec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use es6';

import documents from './fixtures/documents';
import { docsSoap } from '../src/index';
import docsSoap from '../src/index';
import expect from 'expect';
import jsdom from 'mocha-jsdom';
import parseHTML from '../src/parseHTML';
Expand Down

0 comments on commit 8903753

Please sign in to comment.