Skip to content

Commit

Permalink
fix: add missing blockquote style (#144)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Roe <daniel@roe.dev>
  • Loading branch information
SlicoHP and danielroe authored May 15, 2021
1 parent 7c6ad0b commit b2e55d8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/components/sanity-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const defaults: Required<Serializers> = {
h5: 'h5',
h6: 'h6',
normal: 'p',
blockquote: 'blockquote',
},
listItem: 'li',
container: 'div',
Expand All @@ -99,9 +100,7 @@ function getProps (item?: Record<string, any>) {
const obj = Object.entries(item).reduce(
(obj, [key, value]) => {
switch (true) {
case (['_key', 'key']).includes(
key,
):
case ['_key', 'key'].includes(key):
obj.key = value
return obj

Expand Down Expand Up @@ -199,7 +198,10 @@ function wrapMarks (
)
}

function walkList (blocks: Array<CustomBlock | Block | List>, block: CustomBlock | Block | List) {
function walkList (
blocks: Array<CustomBlock | Block | List>,
block: CustomBlock | Block | List,
) {
const { length } = blocks

// Not a list item
Expand Down Expand Up @@ -254,7 +256,7 @@ function renderBlocks (
)
if (process.env.NODE_ENV === 'development') {
if (!node || (Array.isArray(node) && !node.length))
// eslint-disable-next-line
// eslint-disable-next-line
console.warn(
`No serializer found for block type "${block._type}".`,
block,
Expand All @@ -279,9 +281,10 @@ export const SanityContent = extendVue({
renderContainerOnSingleChild: { type: Boolean, default: false },
},
render (h, { props, data }) {
const serializers = defu(props.serializers, defaults) as Required<
Serializers
>
const serializers = defu(
props.serializers,
defaults,
) as Required<Serializers>

serializers.types.list =
serializers.types.list ||
Expand Down
6 changes: 6 additions & 0 deletions test/unit/__snapshots__/sanity-content.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SanityContent should render blockquote blocks 1`] = `
<div>
<blockquote>Build your next Vue.js application with confidence using <a href="https://nuxtjs.org">NuxtJS</a>. An open source framework making web development simple and powerful.</blockquote>
</div>
`;

exports[`SanityContent should render exampleMarkDefs blocks 1`] = `
<div>
<ul>
Expand Down
34 changes: 34 additions & 0 deletions test/unit/sanity-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,40 @@ const exampleBlocks: Record<string, ExampleBlock | ExampleBlock[]> = {
listItem: 'bullet',
},
],
blockquote: {
_key: 'd810da8ac845',
_type: 'block',
children: [
{
_key: 'd810da8ac8450',
_type: 'span',
marks: [],
text: 'Build your next Vue.js application with confidence using ',
},
{
_key: 'd810da8ac8451',
_type: 'span',
marks: [
'c9c6224401ba',
],
text: 'NuxtJS',
},
{
_key: 'd810da8ac8452',
_type: 'span',
marks: [],
text: '. An open source framework making web development simple and powerful.',
},
],
markDefs: [
{
_key: 'c9c6224401ba',
_type: 'link',
href: 'https://nuxtjs.org',
},
],
style: 'blockquote',
},
exampleMarkDefs: {
_key: '3522a2a863b9',
_type: 'block',
Expand Down

0 comments on commit b2e55d8

Please sign in to comment.