From 6ab2d963cde98d01c3e96c210923e8a17755c198 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Thu, 11 Aug 2016 12:28:41 -0700 Subject: [PATCH] fix html serializer for cases without children --- .eslintrc | 4 +-- lib/serializers/raw.js | 4 +-- .../deserialize/block-no-children/index.js | 25 +++++++++++++++++++ .../deserialize/block-no-children/input.html | 1 + .../deserialize/block-no-children/output.yaml | 7 ++++++ .../deserialize/inline-no-children/index.js | 25 +++++++++++++++++++ .../deserialize/inline-no-children/input.html | 1 + .../inline-no-children/output.yaml | 7 ++++++ .../block-with-empty-nodes/input.yaml | 5 ++++ .../block-with-empty-nodes/output.yaml | 7 ++++++ .../block-with-no-nodes/input.yaml | 4 +++ .../block-with-no-nodes/output.yaml | 7 ++++++ 12 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 test/serializers/fixtures/html/deserialize/block-no-children/index.js create mode 100644 test/serializers/fixtures/html/deserialize/block-no-children/input.html create mode 100644 test/serializers/fixtures/html/deserialize/block-no-children/output.yaml create mode 100644 test/serializers/fixtures/html/deserialize/inline-no-children/index.js create mode 100644 test/serializers/fixtures/html/deserialize/inline-no-children/input.html create mode 100644 test/serializers/fixtures/html/deserialize/inline-no-children/output.yaml create mode 100644 test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/input.yaml create mode 100644 test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/output.yaml create mode 100644 test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/input.yaml create mode 100644 test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/output.yaml diff --git a/.eslintrc b/.eslintrc index df7882be4..0a1911d9d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -44,8 +44,8 @@ "no-array-constructor": "error", "no-class-assign": "error", "no-const-assign": "error", - "no-console": "warn", - "no-debugger": "warn", + "no-console": "error", + "no-debugger": "error", "no-dupe-args": "error", "no-dupe-class-members": "error", "no-dupe-keys": "error", diff --git a/lib/serializers/raw.js b/lib/serializers/raw.js index 685fa86b8..ae2b14ff1 100644 --- a/lib/serializers/raw.js +++ b/lib/serializers/raw.js @@ -480,7 +480,7 @@ const Raw = { */ untersifyBlock(object) { - if (object.isVoid) { + if (object.isVoid || !object.nodes || !object.nodes.length) { return { data: object.data, kind: object.kind, @@ -506,7 +506,7 @@ const Raw = { */ untersifyInline(object) { - if (object.isVoid) { + if (object.isVoid || !object.nodes || !object.nodes.length) { return { data: object.data, kind: object.kind, diff --git a/test/serializers/fixtures/html/deserialize/block-no-children/index.js b/test/serializers/fixtures/html/deserialize/block-no-children/index.js new file mode 100644 index 000000000..4f362bef4 --- /dev/null +++ b/test/serializers/fixtures/html/deserialize/block-no-children/index.js @@ -0,0 +1,25 @@ + +export default { + rules: [ + { + deserialize(el, next) { + switch (el.tagName) { + case 'p': { + return { + kind: 'block', + type: 'paragraph', + nodes: next(el.children) + } + } + case 'a': { + return { + kind: 'inline', + type: 'link', + nodes: next(el.children) + } + } + } + } + } + ] +} diff --git a/test/serializers/fixtures/html/deserialize/block-no-children/input.html b/test/serializers/fixtures/html/deserialize/block-no-children/input.html new file mode 100644 index 000000000..31ee88261 --- /dev/null +++ b/test/serializers/fixtures/html/deserialize/block-no-children/input.html @@ -0,0 +1 @@ +

diff --git a/test/serializers/fixtures/html/deserialize/block-no-children/output.yaml b/test/serializers/fixtures/html/deserialize/block-no-children/output.yaml new file mode 100644 index 000000000..337747150 --- /dev/null +++ b/test/serializers/fixtures/html/deserialize/block-no-children/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - type: paragraph + isVoid: false + data: {} + nodes: + - characters: [] diff --git a/test/serializers/fixtures/html/deserialize/inline-no-children/index.js b/test/serializers/fixtures/html/deserialize/inline-no-children/index.js new file mode 100644 index 000000000..4f362bef4 --- /dev/null +++ b/test/serializers/fixtures/html/deserialize/inline-no-children/index.js @@ -0,0 +1,25 @@ + +export default { + rules: [ + { + deserialize(el, next) { + switch (el.tagName) { + case 'p': { + return { + kind: 'block', + type: 'paragraph', + nodes: next(el.children) + } + } + case 'a': { + return { + kind: 'inline', + type: 'link', + nodes: next(el.children) + } + } + } + } + } + ] +} diff --git a/test/serializers/fixtures/html/deserialize/inline-no-children/input.html b/test/serializers/fixtures/html/deserialize/inline-no-children/input.html new file mode 100644 index 000000000..0fcb3e8e2 --- /dev/null +++ b/test/serializers/fixtures/html/deserialize/inline-no-children/input.html @@ -0,0 +1 @@ +

diff --git a/test/serializers/fixtures/html/deserialize/inline-no-children/output.yaml b/test/serializers/fixtures/html/deserialize/inline-no-children/output.yaml new file mode 100644 index 000000000..337747150 --- /dev/null +++ b/test/serializers/fixtures/html/deserialize/inline-no-children/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - type: paragraph + isVoid: false + data: {} + nodes: + - characters: [] diff --git a/test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/input.yaml b/test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/input.yaml new file mode 100644 index 000000000..8a23705de --- /dev/null +++ b/test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/input.yaml @@ -0,0 +1,5 @@ + +nodes: + - kind: block + type: paragraph + nodes: [] diff --git a/test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/output.yaml b/test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/output.yaml new file mode 100644 index 000000000..337747150 --- /dev/null +++ b/test/serializers/fixtures/raw/deserialize-terse/block-with-empty-nodes/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - type: paragraph + isVoid: false + data: {} + nodes: + - characters: [] diff --git a/test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/input.yaml b/test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/input.yaml new file mode 100644 index 000000000..5db70fc35 --- /dev/null +++ b/test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/input.yaml @@ -0,0 +1,4 @@ + +nodes: + - kind: block + type: paragraph diff --git a/test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/output.yaml b/test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/output.yaml new file mode 100644 index 000000000..337747150 --- /dev/null +++ b/test/serializers/fixtures/raw/deserialize-terse/block-with-no-nodes/output.yaml @@ -0,0 +1,7 @@ + +nodes: + - type: paragraph + isVoid: false + data: {} + nodes: + - characters: []