From bfc05b587acb6729741bead24e7c3b465bdd2e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Fri, 2 Dec 2016 17:29:09 +0100 Subject: [PATCH 1/3] Adapt schema to add empty text nodes around all inlines --- src/schemas/core.js | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/schemas/core.js b/src/schemas/core.js index 158ce1b6d..c77b26b10 100644 --- a/src/schemas/core.js +++ b/src/schemas/core.js @@ -184,7 +184,7 @@ const rules = [ const prev = index > 0 ? node.nodes.get(index - 1) : null const next = node.nodes.get(index + 1) const insertBefore = !prev - const insertAfter = !next || isInlineVoid(next) + const insertAfter = !next || (next.kind == 'inline') if (insertAfter || insertBefore) { list = list.push({ insertAfter, insertBefore, index }) @@ -267,13 +267,13 @@ const rules = [ const next = nodes.get(i + 1) // If it's the first node, and the next is a void, preserve it. - if (!prev && isInlineVoid(next)) return + if (!prev && next.kind == 'inline') return - // It it's the last node, and the previous is a void, preserve it. - if (!next && isInlineVoid(prev)) return + // It it's the last node, and the previous is an inline, preserve it. + if (!next && prev.kind == 'inline') return - // If it's surrounded by voids, preserve it. - if (next && prev && isInlineVoid(next) && isInlineVoid(prev)) return + // If it's surrounded by inlines, preserve it. + if (next && prev && next.kind == 'inline' && prev.kind == 'inline') return // Otherwise, remove it. return true @@ -290,17 +290,6 @@ const rules = [ ] -/** - * Test if a `node` is an inline void node. - * - * @param {Node} node - * @return {Boolean} - */ - -function isInlineVoid(node) { - return (node.kind == 'inline' && node.isVoid) -} - /** * Create the core schema. * From 8738b0a48da752d93950acb0654d121f724cbdef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Fri, 2 Dec 2016 17:53:12 +0100 Subject: [PATCH 2/3] Fix condition in core rule to add test around all inlines --- src/schemas/core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/schemas/core.js b/src/schemas/core.js index c77b26b10..9746428b5 100644 --- a/src/schemas/core.js +++ b/src/schemas/core.js @@ -178,11 +178,11 @@ const rules = [ }, validate: (node) => { const invalids = node.nodes.reduce((list, child, index) => { - if (child.kind == 'block') return list - if (!child.isVoid) return list + if (child.kind !== 'inline') return list const prev = index > 0 ? node.nodes.get(index - 1) : null const next = node.nodes.get(index + 1) + // We don't test if "prev" is inline, since it has already been processed in the loop const insertBefore = !prev const insertAfter = !next || (next.kind == 'inline') From 909e7d358f62d9a3ad59d0bca0608ba83cb305db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Fri, 2 Dec 2016 17:57:24 +0100 Subject: [PATCH 3/3] Adapt tests for schema --- .../default-inline-children/no-block/output.yaml | 4 ++++ .../end-block/index.js | 0 .../end-block/input.yaml | 0 .../end-block/output.yaml | 0 .../end-inline/index.js | 0 .../end-inline/input.yaml | 0 .../end-inline/output.yaml | 4 ++++ .../multiple/index.js | 0 .../multiple/input.yaml | 0 .../multiple/output.yaml | 0 .../not-void}/index.js | 0 .../not-void/input.yaml | 10 ++++++++++ .../not-void/output.yaml | 15 +++++++++++++++ .../only-child}/index.js | 0 .../only-child/input.yaml | 0 .../only-child/output.yaml | 0 .../start-block}/index.js | 0 .../start-block/input.yaml | 0 .../start-block/output.yaml | 0 .../with-inline/index.js | 2 ++ .../with-inline/input.yaml | 0 .../with-inline/output.yaml | 4 ++++ 22 files changed, 39 insertions(+) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/end-block/index.js (100%) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/end-block/input.yaml (100%) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/end-block/output.yaml (100%) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/end-inline/index.js (100%) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/end-inline/input.yaml (100%) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/end-inline/output.yaml (79%) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/multiple/index.js (100%) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/multiple/input.yaml (100%) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/multiple/output.yaml (100%) rename test/schema/fixtures/{default-void-text-around/only-child => default-inline-text-around/not-void}/index.js (100%) create mode 100644 test/schema/fixtures/default-inline-text-around/not-void/input.yaml create mode 100644 test/schema/fixtures/default-inline-text-around/not-void/output.yaml rename test/schema/fixtures/{default-void-text-around/start-block => default-inline-text-around/only-child}/index.js (100%) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/only-child/input.yaml (100%) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/only-child/output.yaml (100%) rename test/schema/fixtures/{default-void-text-around/with-inline => default-inline-text-around/start-block}/index.js (100%) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/start-block/input.yaml (100%) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/start-block/output.yaml (100%) create mode 100644 test/schema/fixtures/default-inline-text-around/with-inline/index.js rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/with-inline/input.yaml (100%) rename test/schema/fixtures/{default-void-text-around => default-inline-text-around}/with-inline/output.yaml (78%) diff --git a/test/schema/fixtures/default-inline-children/no-block/output.yaml b/test/schema/fixtures/default-inline-children/no-block/output.yaml index fa6cf7b7c..bb58a82eb 100644 --- a/test/schema/fixtures/default-inline-children/no-block/output.yaml +++ b/test/schema/fixtures/default-inline-children/no-block/output.yaml @@ -3,8 +3,12 @@ nodes: - kind: block type: default nodes: + - kind: text + text: "" - kind: inline type: default nodes: - kind: text text: one + - kind: text + text: "" diff --git a/test/schema/fixtures/default-void-text-around/end-block/index.js b/test/schema/fixtures/default-inline-text-around/end-block/index.js similarity index 100% rename from test/schema/fixtures/default-void-text-around/end-block/index.js rename to test/schema/fixtures/default-inline-text-around/end-block/index.js diff --git a/test/schema/fixtures/default-void-text-around/end-block/input.yaml b/test/schema/fixtures/default-inline-text-around/end-block/input.yaml similarity index 100% rename from test/schema/fixtures/default-void-text-around/end-block/input.yaml rename to test/schema/fixtures/default-inline-text-around/end-block/input.yaml diff --git a/test/schema/fixtures/default-void-text-around/end-block/output.yaml b/test/schema/fixtures/default-inline-text-around/end-block/output.yaml similarity index 100% rename from test/schema/fixtures/default-void-text-around/end-block/output.yaml rename to test/schema/fixtures/default-inline-text-around/end-block/output.yaml diff --git a/test/schema/fixtures/default-void-text-around/end-inline/index.js b/test/schema/fixtures/default-inline-text-around/end-inline/index.js similarity index 100% rename from test/schema/fixtures/default-void-text-around/end-inline/index.js rename to test/schema/fixtures/default-inline-text-around/end-inline/index.js diff --git a/test/schema/fixtures/default-void-text-around/end-inline/input.yaml b/test/schema/fixtures/default-inline-text-around/end-inline/input.yaml similarity index 100% rename from test/schema/fixtures/default-void-text-around/end-inline/input.yaml rename to test/schema/fixtures/default-inline-text-around/end-inline/input.yaml diff --git a/test/schema/fixtures/default-void-text-around/end-inline/output.yaml b/test/schema/fixtures/default-inline-text-around/end-inline/output.yaml similarity index 79% rename from test/schema/fixtures/default-void-text-around/end-inline/output.yaml rename to test/schema/fixtures/default-inline-text-around/end-inline/output.yaml index 3b04c3296..50fa37807 100644 --- a/test/schema/fixtures/default-void-text-around/end-inline/output.yaml +++ b/test/schema/fixtures/default-inline-text-around/end-inline/output.yaml @@ -3,6 +3,8 @@ nodes: - kind: block type: default nodes: + - kind: text + text: "" - kind: inline type: link nodes: @@ -13,3 +15,5 @@ nodes: isVoid: true - kind: text text: "" + - kind: text + text: "" diff --git a/test/schema/fixtures/default-void-text-around/multiple/index.js b/test/schema/fixtures/default-inline-text-around/multiple/index.js similarity index 100% rename from test/schema/fixtures/default-void-text-around/multiple/index.js rename to test/schema/fixtures/default-inline-text-around/multiple/index.js diff --git a/test/schema/fixtures/default-void-text-around/multiple/input.yaml b/test/schema/fixtures/default-inline-text-around/multiple/input.yaml similarity index 100% rename from test/schema/fixtures/default-void-text-around/multiple/input.yaml rename to test/schema/fixtures/default-inline-text-around/multiple/input.yaml diff --git a/test/schema/fixtures/default-void-text-around/multiple/output.yaml b/test/schema/fixtures/default-inline-text-around/multiple/output.yaml similarity index 100% rename from test/schema/fixtures/default-void-text-around/multiple/output.yaml rename to test/schema/fixtures/default-inline-text-around/multiple/output.yaml diff --git a/test/schema/fixtures/default-void-text-around/only-child/index.js b/test/schema/fixtures/default-inline-text-around/not-void/index.js similarity index 100% rename from test/schema/fixtures/default-void-text-around/only-child/index.js rename to test/schema/fixtures/default-inline-text-around/not-void/index.js diff --git a/test/schema/fixtures/default-inline-text-around/not-void/input.yaml b/test/schema/fixtures/default-inline-text-around/not-void/input.yaml new file mode 100644 index 000000000..ad5feb036 --- /dev/null +++ b/test/schema/fixtures/default-inline-text-around/not-void/input.yaml @@ -0,0 +1,10 @@ + +nodes: + - kind: block + type: default + nodes: + - kind: inline + type: link + nodes: + - kind: text + text: "Hello" diff --git a/test/schema/fixtures/default-inline-text-around/not-void/output.yaml b/test/schema/fixtures/default-inline-text-around/not-void/output.yaml new file mode 100644 index 000000000..2834adaec --- /dev/null +++ b/test/schema/fixtures/default-inline-text-around/not-void/output.yaml @@ -0,0 +1,15 @@ + + +nodes: + - kind: block + type: default + nodes: + - kind: text + text: "" + - kind: inline + type: link + nodes: + - kind: text + text: "Hello" + - kind: text + text: "" diff --git a/test/schema/fixtures/default-void-text-around/start-block/index.js b/test/schema/fixtures/default-inline-text-around/only-child/index.js similarity index 100% rename from test/schema/fixtures/default-void-text-around/start-block/index.js rename to test/schema/fixtures/default-inline-text-around/only-child/index.js diff --git a/test/schema/fixtures/default-void-text-around/only-child/input.yaml b/test/schema/fixtures/default-inline-text-around/only-child/input.yaml similarity index 100% rename from test/schema/fixtures/default-void-text-around/only-child/input.yaml rename to test/schema/fixtures/default-inline-text-around/only-child/input.yaml diff --git a/test/schema/fixtures/default-void-text-around/only-child/output.yaml b/test/schema/fixtures/default-inline-text-around/only-child/output.yaml similarity index 100% rename from test/schema/fixtures/default-void-text-around/only-child/output.yaml rename to test/schema/fixtures/default-inline-text-around/only-child/output.yaml diff --git a/test/schema/fixtures/default-void-text-around/with-inline/index.js b/test/schema/fixtures/default-inline-text-around/start-block/index.js similarity index 100% rename from test/schema/fixtures/default-void-text-around/with-inline/index.js rename to test/schema/fixtures/default-inline-text-around/start-block/index.js diff --git a/test/schema/fixtures/default-void-text-around/start-block/input.yaml b/test/schema/fixtures/default-inline-text-around/start-block/input.yaml similarity index 100% rename from test/schema/fixtures/default-void-text-around/start-block/input.yaml rename to test/schema/fixtures/default-inline-text-around/start-block/input.yaml diff --git a/test/schema/fixtures/default-void-text-around/start-block/output.yaml b/test/schema/fixtures/default-inline-text-around/start-block/output.yaml similarity index 100% rename from test/schema/fixtures/default-void-text-around/start-block/output.yaml rename to test/schema/fixtures/default-inline-text-around/start-block/output.yaml diff --git a/test/schema/fixtures/default-inline-text-around/with-inline/index.js b/test/schema/fixtures/default-inline-text-around/with-inline/index.js new file mode 100644 index 000000000..9a676e861 --- /dev/null +++ b/test/schema/fixtures/default-inline-text-around/with-inline/index.js @@ -0,0 +1,2 @@ + +export default {} diff --git a/test/schema/fixtures/default-void-text-around/with-inline/input.yaml b/test/schema/fixtures/default-inline-text-around/with-inline/input.yaml similarity index 100% rename from test/schema/fixtures/default-void-text-around/with-inline/input.yaml rename to test/schema/fixtures/default-inline-text-around/with-inline/input.yaml diff --git a/test/schema/fixtures/default-void-text-around/with-inline/output.yaml b/test/schema/fixtures/default-inline-text-around/with-inline/output.yaml similarity index 78% rename from test/schema/fixtures/default-void-text-around/with-inline/output.yaml rename to test/schema/fixtures/default-inline-text-around/with-inline/output.yaml index d7d303bcb..728c306ac 100644 --- a/test/schema/fixtures/default-void-text-around/with-inline/output.yaml +++ b/test/schema/fixtures/default-inline-text-around/with-inline/output.yaml @@ -4,11 +4,15 @@ nodes: - kind: block type: default nodes: + - kind: text + text: "" - kind: inline type: link nodes: - kind: text text: "Hello " + - kind: text + text: "" - kind: inline isVoid: true type: image