From ddc7c787b505d66ad8767ec868b360f0460d4175 Mon Sep 17 00:00:00 2001 From: aem Date: Fri, 8 Jul 2016 13:44:55 -0400 Subject: [PATCH] Add support for header types, v0.1.5 --- .github/PULL_REQUEST_TEMPLATE.md | 4 ---- CHANGELOG.md | 10 ++++++++++ README.md | 5 ++--- package.json | 2 +- src/constants.js | 9 +++++++++ src/docsSoap.js | 7 +++++-- test/docsSoapSpec.js | 8 ++++++++ test/fixtures/documents.json | 3 ++- 8 files changed, 37 insertions(+), 11 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 2d787eb..78ba1a4 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -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 @@ -10,7 +9,4 @@ **Reason for changes or related GitHub issue** -**Code example or screenshot if applicable** - - @aem diff --git a/CHANGELOG.md b/CHANGELOG.md index b8c6743..5a6d743 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # docs-soap Changelog + + + +
+ v0.1.5 + +
    +
  • Added support for all header types
  • +
+
v0.1.4 diff --git a/README.md b/README.md index 399bbe4..aeae5d7 100644 --- a/README.md +++ b/README.md @@ -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
    -
  • Added support for ordered lists
  • -
  • Added support for nested lists
  • +
  • Added support for all header types
### Exported API diff --git a/package.json b/package.json index 38029a2..6310669 100644 --- a/package.json +++ b/package.json @@ -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 ", "keywords": [ diff --git a/src/constants.js b/src/constants.js index e7eb5d5..7733384 100644 --- a/src/constants.js +++ b/src/constants.js @@ -18,3 +18,12 @@ export const elements = { SUPERSCRIPT: 'sup', SUBSCRIPT: 'sub' }; + +export const headers = [ + 'H1', + 'H2', + 'H3', + 'H4', + 'H5', + 'H6' +]; diff --git a/src/docsSoap.js b/src/docsSoap.js index f132c2b..ea6012f 100644 --- a/src/docsSoap.js +++ b/src/docsSoap.js @@ -1,6 +1,6 @@ // @flow -import { docsId, elements, styles } from './constants'; +import { docsId, elements, headers, styles } from './constants'; import parseHTML from './parseHTML'; const wrapNodeAnchor = ( @@ -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); diff --git a/test/docsSoapSpec.js b/test/docsSoapSpec.js index 9ac40c0..9a2ce3a 100644 --- a/test/docsSoapSpec.js +++ b/test/docsSoapSpec.js @@ -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); + }); }); diff --git a/test/fixtures/documents.json b/test/fixtures/documents.json index b7739a6..5328ae9 100644 --- a/test/fixtures/documents.json +++ b/test/fixtures/documents.json @@ -2,5 +2,6 @@ "plain": "

Hello world.


", "inlineStyles": "

Some bold text

Some italicized text

Some underlined text

Some strikethrough text

Some superscript

Some subscript
", "links": "

this is a link

this is a bold link

this is an italicized link

this is a bold, italicized link
", - "nestedList": "
  1. Abcd
    1234

    1. In abcd

      1. Some text in italics and underline plus random stuff after

  2. xyz

    1. In xyz

      1. Last of all

  • Todo 1

  • Todo 2

    • subtodo

      • subsubsub


Asdfasdf

2. End






  1. Asdfasdfasdf

    1. Asdfasdfasdfasdf

  2. Asdfasdfasdf

    1. asdfasdfasdfasf

Asdfasdf

2. end

  1. end

  2. asdfasdf

  3. s

  4. dfa

  5. sdf

  6. eight

  7. ten


" + "nestedList": "
  1. Abcd
    1234

    1. In abcd

      1. Some text in italics and underline plus random stuff after

  2. xyz

    1. In xyz

      1. Last of all

  • Todo 1

  • Todo 2

    • subtodo

      • subsubsub


Asdfasdf

2. End






  1. Asdfasdfasdf

    1. Asdfasdfasdfasdf

  2. Asdfasdfasdf

    1. asdfasdfasdfasf

Asdfasdf

2. end

  1. end

  2. asdfasdf

  3. s

  4. dfa

  5. sdf

  6. eight

  7. ten


", + "headers": "

This is an H1

This is an H2

This is an H3

This is an H4

" }