diff --git a/src/schemas/core.js b/src/schemas/core.js index 158ce1b6d..9746428b5 100644 --- a/src/schemas/core.js +++ b/src/schemas/core.js @@ -178,13 +178,13 @@ 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 || 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. * 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