Skip to content

Commit

Permalink
[block-tools] Add option .blockTypeName for normalizeBlock function
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsmaskin committed Sep 7, 2020
1 parent eb63bb2 commit 82cf2d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 5 additions & 2 deletions packages/@sanity/block-tools/src/util/normalizeBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import {isEqual} from 'lodash'
import randomKey from './randomKey'

// For a block with _type 'block' (text), join spans where possible
export default function normalizeBlock(block, options: {allowedDecorators?: string[]} = {}) {
export default function normalizeBlock(
block,
options: {allowedDecorators?: string[]; blockTypeName?: string} = {}
) {
let newIndex = 0
if (!block._key) {
block._key = randomKey(12)
}
if (block._type !== 'block') {
if (block._type !== (options.blockTypeName || 'block')) {
return block
}
if (!block.children) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ describe('normalizeBlock', () => {
it('will normalize a block', () => {
const block = {
_type: 'block',
markDefs: [{
_key: '123123',
something: 'bogus'
}],
markDefs: [
{
_key: '123123',
something: 'bogus'
}
],
children: [
{
_type: 'span',
Expand Down

0 comments on commit 82cf2d9

Please sign in to comment.