Skip to content

Commit

Permalink
Allow terminating whitespace in non-terminating spans
Browse files Browse the repository at this point in the history
This allows marked up content to have spaces around/adjacent
to it without allowing space at the beginning or end of a
block/paragraph.
  • Loading branch information
coreyward committed Oct 8, 2021
1 parent acde4e1 commit 2a586d0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/lib/blockValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ export const blockValidations = {
// Prevent preceding or trailing whitespace
noTerminatingWhitespace: (blocks) => {
const offendingPaths = (blocks || [])
.filter(
(block) =>
block._type === "block" &&
block.children.every(
(span) => span._type === "span" && span.text !== span.text.trim()
)
)
.filter(({ _type, children }) => {
if (_type !== "block") return false

const { 0: first, length, [length - 1]: last } = children || []

return first?.text.startsWith(" ") || last?.text.endsWith(" ")
})
.map((block, index) => [{ _key: block._key }] || [index])

return (
Expand Down

0 comments on commit 2a586d0

Please sign in to comment.