Skip to content

Commit 6c5d95b

Browse files
authored
Merge pull request #18 from aem/headers
Add support for header types, v0.1.5
2 parents 7efbf7a + ddc7c78 commit 6c5d95b

File tree

8 files changed

+37
-11
lines changed

8 files changed

+37
-11
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
**Pre-merge checklist**
2-
- [ ] code has been tested in Node and all major browsers
32
- [ ] accompanying tests are written and passing
43
- [ ] `npm run install` passes with no errors
54
- [ ] `npm run lint` passes with no errors
@@ -10,7 +9,4 @@
109
**Reason for changes or related GitHub issue**
1110

1211

13-
**Code example or screenshot if applicable**
14-
15-
1612
@aem

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# docs-soap Changelog
22
<table>
3+
<tr>
4+
<td>
5+
<strong>v0.1.5</strong>
6+
</td>
7+
<td>
8+
<ul>
9+
<li>Added support for all header types</li>
10+
</ul>
11+
</td>
12+
</tr>
313
<tr>
414
<td>
515
<strong>v0.1.4</strong>

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ docs-soap is a small, simple library that can be used to transform clipboard con
44

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

7-
### New in 0.1.4
7+
### New in 0.1.5
88
<ul>
9-
<li>Added support for ordered lists</li>
10-
<li>Added support for nested lists</li>
9+
<li>Added support for all header types</li>
1110
</ul>
1211

1312
### Exported API

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docs-soap",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "A utility for cleaning Google Docs clipboard content into valid HTML",
55
"author": "aem <[email protected]>",
66
"keywords": [

src/constants.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ export const elements = {
1818
SUPERSCRIPT: 'sup',
1919
SUBSCRIPT: 'sub'
2020
};
21+
22+
export const headers = [
23+
'H1',
24+
'H2',
25+
'H3',
26+
'H4',
27+
'H5',
28+
'H6'
29+
];

src/docsSoap.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
import { docsId, elements, styles } from './constants';
3+
import { docsId, elements, headers, styles } from './constants';
44
import parseHTML from './parseHTML';
55

66
const wrapNodeAnchor = (
@@ -99,7 +99,10 @@ const getCleanNode = (
9999
for (let i = 0; i < node.childNodes.length; i++) {
100100
items.push(...getCleanNode(node.childNodes[i]));
101101
}
102-
items.map(i => newNode.appendChild(i));
102+
items.map((i: Node): Node => newNode.appendChild(i));
103+
} else if (headers.indexOf(node.nodeName) !== -1) {
104+
newWrapper = document.createElement(node.nodeName);
105+
newNode = applyInlineStyles(node.childNodes[0]);
103106
} else if (node.nodeName === 'P') {
104107
newWrapper = document.createElement('p');
105108
newNode = applyBlockStyles(node);

test/docsSoapSpec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,12 @@ describe('Google Docs Converter', () => {
9898
expect(doc.childNodes[0].childNodes[1].childNodes[1].childNodes[0].querySelectorAll(elements.UNDERLINE).length).toBe(1);
9999
expect(doc.childNodes[0].childNodes[1].childNodes[1].childNodes[0].querySelector(elements.UNDERLINE).textContent).toBe('underline');
100100
});
101+
102+
it('converts header types properly', () => {
103+
const doc = parseHTML(docsSoap(documents.headers));
104+
expect(doc.querySelectorAll('h1').length).toBe(1);
105+
expect(doc.querySelectorAll('h2').length).toBe(1);
106+
expect(doc.querySelectorAll('h3').length).toBe(1);
107+
expect(doc.querySelectorAll('h4').length).toBe(1);
108+
});
101109
});

test/fixtures/documents.json

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)