Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
mobiledoc-vdom-renderer
Advanced tools
Render Mobiledoc as VDOM, for React or React-like `createElement` calls
This package renders Mobiledoc documents through calls to a createElement
function, often referred to as h
(for hyperscript) or provided as a global if you are using JSX. This allows embedding Mobiledoc content “natively” as virtual DOM in frameworks like React, preact, or hyperapp.
Alternatively, you can skip the “virtual” step and build DOM directly with a micro-renderer such as ultradom or even convert mobiledocs to arbitrary ASTs by adopting createElement
’s standard (type: (properties: object) => Node, properties: object, ...children: Node[]) => Node
signature for your builder.
npm install mobiledoc-vdom-renderer --save
or
yarn add mobiledoc-vdom-renderer
/* @jsx h */
import Renderer from 'mobiledoc-vdom-renderer'
// render: (mobiledoc: Mobiledoc) => Node[]
const render = Renderer({ createElement: h })
// Instant <Mobiledoc/> Component
export default function Mobiledoc({ mobiledoc }) {
return <div>{render(mobiledoc)}</div>
}
import Renderer, { upgradeMobiledoc } from 'mobiledoc-vdom-renderer'
Renderer
(default export)Renderer: (options: RendererOptions) => RenderFunction
Creates a render function ((mobiledoc: Mobiledoc) => Node[]
) from the supplied options
options
required{
createElement: CreateElement,
getCardComponent?: ComponentGetter,
getAtomComponent?: ComponentGetter,
getElement?: ComponentGetter = getElementDefault
}
createElement
requiredcreateElement: (
type: string | Component,
properties?: object,
...children: Node[]
) => Node
Any compatible function such as React.createElement
or hyperscript h
getCardComponent
getCardComponent: (type: string) => string | Component
Function which returns a string (tag name) or component ((properties: { payload: object }) => Node
) for the given card type (required if rendering a mobiledoc with cards)getAtomComponent
getAtomComponent: (type: string) => string | Component
Function which returns a string (tag name) or component ((properties: { payload: object }) => Node
) for the given atom type (required if rendering a mobiledoc with atoms)getElement
getElement: (tagName: string) => string | Component = getElementDefault
Function which returns a string (tag name) or component ((attributes: object) => Node
) to override rendering for the given tag name (for instance, to mix in HTML attributes or render a custom component instead)
import { getElementDefault } from 'mobiledoc-vdom-renderer'
getElement
’s default behavior is exported as getElementDefault
, which passes through valid tag names but throws an error for tags not on Mobiledoc’s markup section or markup whitelists; passing through all tag names instead (as in tagName => tagName
) allows (non-standard) mobiledocs containing arbitrary tags to be renderedupgradeMobiledoc
upgradeMobiledoc: (mobiledoc: Mobiledoc | Mobiledoc02x) => Mobiledoc
Upgrades a mobiledoc from any released version to the latest specification (0.3.1
)
import { Mobiledoc } from 'mobiledoc-vdom-renderer'
import Mobiledoc, * as MobiledocTypes from 'mobiledoc-vdom-renderer/types/mobiledoc'
This package includes complete Typescript definitions describing the Mobiledoc format, which may be imported directly for use with any mobiledoc-related code.
Contributions—including pull requests, bug reports, documentation, and suggestions—are welcome!
The code is written in Typescript in a pure functional style. Opinionated “best practices,” including functional programming, are strictly enforced by linters—it’ll help to use a code editor which supports both as-you-type linting and type-checking.
git clone https://github.com/bustle/mobiledoc-vdom-renderer.git
cd mobiledoc-vdom-renderer/
npm install
npm start
Watches the filesystem for changes (chokidar-cli) then lints (Typescript, Standard style, functional JS practices) and tests (ava snapshots) each file you touch
npm test
npm run snapshot
git
diff before committing!npm run format
FAQs
Render Mobiledoc as VDOM, for React or React-like `createElement` calls
The npm package mobiledoc-vdom-renderer receives a total of 5 weekly downloads. As such, mobiledoc-vdom-renderer popularity was classified as not popular.
We found that mobiledoc-vdom-renderer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 22 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.