
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@lyra/block-content-to-hyperscript
Advanced tools
Function for transforming Lyra block content to HyperScript
Render an array of block text from Lyra with HyperScript.
npm install --save @lyra/block-content-to-hyperscript
const h = require('hyperscript')
const blocksToHyperScript = require('@lyra/block-content-to-hyperscript')
const client = require('@lyra/client')({
dataset: '<some dataset>'
})
const serializers = {
types: {
code: props => h('pre', {className: props.node.language}, h('code', props.node.code))
}
}
client.fetch('*[_type == "article"][0]').then(article => {
const el = blocksToHyperScript({
blocks: article.body,
serializers: serializers
})
document.getElementById('root').appendChild(el)
})
className - When more than one block is given, a container node has to be created. Passing a className will pass it on to the container. Note: see renderContainerOnSingleChild.renderContainerOnSingleChild - When a single block is given as input, the default behavior is to not render any container. If you always want to render the container, pass true.serializers - Specifies the functions to use for rendering content. Merged with default serializers.serializers.types - Serializers for block types, see example aboveserializers.marks - Serializers for marks - data that annotates a text child of a block. See example usage below.serializers.list - Function to use when rendering a list nodeserializers.listItem - Function to use when rendering a list item nodeserializers.hardBreak - Function to use when transforming newline characters to a hard break (default: <br/>, pass false to render newline character)serializers.container - Serializer for the container wrapping the blocksimageOptions - When encountering image blocks, this defines which query parameters to apply in order to control size/crop mode etc.In addition, in order to render images without materializing the asset documents, you should also specify:
dataset - Name of the Lyra dataset containing the document that is being rendered.const input = [
{
_type: 'block',
children: [
{
_key: 'a1ph4',
_type: 'span',
marks: ['s0m3k3y'],
text: 'Lyra'
}
],
markDefs: [
{
_key: 's0m3k3y',
_type: 'highlight',
color: '#E4FC5B'
}
]
}
]
const highlight = props => h('span', {style: {backgroundColor: props.mark.color}}, props.children)
const content = blocksToHyperScript({
blocks: input,
serializers: {marks: {highlight}}
})
blocksToHyperScript({
blocks: input,
imageOptions: {w: 320, h: 240, fit: 'max'},
dataset: 'mydataset'
})
block-typeconst BlockRenderer = props => {
const style = props.node.style || 'normal'
if (/^h\d/.test(style)) {
const level = style.replace(/[^\d]/g, '')
return h('h2', {className: `my-heading level-${level}`}, props.children)
}
return style === 'blockquote'
? h('blockquote', {className: 'my-block-quote'}, props.children)
: h('p', {className: 'my-paragraph'}, props.children)
}
blocksToHyperScript({
blocks: input,
serializers: {types: {block: BlockRenderer}}
})
MIT-licensed. See LICENSE.
FAQs
Function for transforming Lyra block content to HyperScript
We found that @lyra/block-content-to-hyperscript demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.