Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// @flow
import PrismicDOM from 'prismic-dom';
import linkResolver from './link-resolver';
import { Fragment, type Element } from 'react';
const { Elements } = PrismicDOM.RichText;
export type HtmlSerializer = (
type: string,
element: Object, // There are so many types here
content: string,
children: Element[],
i: number
) => ?Element;
export const dropCapSerializer: HtmlSerializer = (
type,
element,
content,
children,
i
) => {
function htmlSerializer (type, element, content, children) {
const Elements = PrismicDOM.RichText.Elements;
// give headings an ID
switch(type) {
case Elements.heading1:
case Elements.heading2:
case Elements.heading3:
case Elements.heading4:
case Elements.heading5:
case Elements.heading6:
const level = type[type.length -1]
const id = children.join('')
.trim()
.toLowerCase()
.replace(/(&\w+;)/g, '')
.replace(/([^a-z\-\ ])/g, '')
.replace(/ /g, '-')
.replace(/--/g, '-');
const normalizeRichTextField = (value, linkResolver, htmlSerializer) => ({
html: PrismicDOM.RichText.asHtml(value, linkResolver, htmlSerializer),
text: PrismicDOM.RichText.asText(value),
raw: value,
})
const normalizeRichTextField = (value, linkResolver, htmlSerializer) => ({
html: PrismicDOM.RichText.asHtml(value, linkResolver, htmlSerializer),
text: PrismicDOM.RichText.asText(value),
raw: value,
})
const normalizeRichTextField = (value, linkResolver, htmlSerializer) => ({
html: PrismicDOM.RichText.asHtml(value, linkResolver, htmlSerializer),
text: PrismicDOM.RichText.asText(value),
raw: value,
})
.then(response => {
if ( !response ) throw('Integration not found');
response.data.descriptionHTML = PrismicDOM.RichText.asHtml(response.data.description)
return res.render('integrations/detail', {data: response.data})
})
.then(resolve)
_depth,
context,
) => {
const { doc, pluginOptions } = context
const { linkResolver, htmlSerializer } = pluginOptions
const linkResolverForField = linkResolver({ key: id, value, node: doc })
const htmlSerializerForField = htmlSerializer({ key: id, value, node: doc })
return {
html: PrismicDOM.RichText.asHtml(
value,
linkResolverForField,
htmlSerializerForField,
),
text: PrismicDOM.RichText.asText(value),
raw: value,
}
}
.map(({ primary: { image, caption } }) => {
return PrismicDom.RichText.asText(caption);
})
.find(Boolean)
const texts = _.reduce(fragments, (out, curr: any) => {
const text = _.get(curr, subpath);
if (!text) return out;
if (typeof text === 'string') {
out.push(text);
}
else {
out.push(PrismicDOM.RichText.asText(text));
}
return out;
}, Array());