Skip to content

Commit

Permalink
Merge pull request #18 from aem/headers
Browse files Browse the repository at this point in the history
Add support for header types, v0.1.5
  • Loading branch information
aem authored Jul 8, 2016
2 parents 7efbf7a + ddc7c78 commit 6c5d95b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 11 deletions.
4 changes: 0 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
**Pre-merge checklist**
- [ ] code has been tested in Node and all major browsers
- [ ] accompanying tests are written and passing
- [ ] `npm run install` passes with no errors
- [ ] `npm run lint` passes with no errors
Expand All @@ -10,7 +9,4 @@
**Reason for changes or related GitHub issue**


**Code example or screenshot if applicable**


@aem
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# docs-soap Changelog
<table>
<tr>
<td>
<strong>v0.1.5</strong>
</td>
<td>
<ul>
<li>Added support for all header types</li>
</ul>
</td>
</tr>
<tr>
<td>
<strong>v0.1.4</strong>
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ docs-soap is a small, simple library that can be used to transform clipboard con

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).

### New in 0.1.4
### New in 0.1.5
<ul>
<li>Added support for ordered lists</li>
<li>Added support for nested lists</li>
<li>Added support for all header types</li>
</ul>

### Exported API
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docs-soap",
"version": "0.1.4",
"version": "0.1.5",
"description": "A utility for cleaning Google Docs clipboard content into valid HTML",
"author": "aem <amarkon895@gmail.com>",
"keywords": [
Expand Down
9 changes: 9 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ export const elements = {
SUPERSCRIPT: 'sup',
SUBSCRIPT: 'sub'
};

export const headers = [
'H1',
'H2',
'H3',
'H4',
'H5',
'H6'
];
7 changes: 5 additions & 2 deletions src/docsSoap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

import { docsId, elements, styles } from './constants';
import { docsId, elements, headers, styles } from './constants';
import parseHTML from './parseHTML';

const wrapNodeAnchor = (
Expand Down Expand Up @@ -99,7 +99,10 @@ const getCleanNode = (
for (let i = 0; i < node.childNodes.length; i++) {
items.push(...getCleanNode(node.childNodes[i]));
}
items.map(i => newNode.appendChild(i));
items.map((i: Node): Node => newNode.appendChild(i));
} else if (headers.indexOf(node.nodeName) !== -1) {
newWrapper = document.createElement(node.nodeName);
newNode = applyInlineStyles(node.childNodes[0]);
} else if (node.nodeName === 'P') {
newWrapper = document.createElement('p');
newNode = applyBlockStyles(node);
Expand Down
8 changes: 8 additions & 0 deletions test/docsSoapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,12 @@ describe('Google Docs Converter', () => {
expect(doc.childNodes[0].childNodes[1].childNodes[1].childNodes[0].querySelectorAll(elements.UNDERLINE).length).toBe(1);
expect(doc.childNodes[0].childNodes[1].childNodes[1].childNodes[0].querySelector(elements.UNDERLINE).textContent).toBe('underline');
});

it('converts header types properly', () => {
const doc = parseHTML(docsSoap(documents.headers));
expect(doc.querySelectorAll('h1').length).toBe(1);
expect(doc.querySelectorAll('h2').length).toBe(1);
expect(doc.querySelectorAll('h3').length).toBe(1);
expect(doc.querySelectorAll('h4').length).toBe(1);
});
});
3 changes: 2 additions & 1 deletion test/fixtures/documents.json

Large diffs are not rendered by default.

0 comments on commit 6c5d95b

Please sign in to comment.