All Projects → developit → Preact Markup

developit / Preact Markup

Licence: mit
⚡️ Render HTML5 as VDOM, with Components as Custom Elements!

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Preact Markup

Jsoup
jsoup: the Java HTML parser, built for HTML editing, cleaning, scraping, and XSS safety.
Stars: ✭ 9,184 (+5399.4%)
Mutual labels:  parse, dom, xml
Preact
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Stars: ✭ 30,527 (+18179.64%)
Mutual labels:  dom, jsx, preact
Breakdance
It's time for your markup to get down! HTML to markdown converter. Breakdance is a highly pluggable, flexible and easy to use.
Stars: ✭ 418 (+150.3%)
Mutual labels:  markdown, markup, parse
Dataformsjs
🌟 DataFormsJS 🌟 A minimal JavaScript Framework and standalone React and Web Components for rapid development of high quality websites and single page applications.
Stars: ✭ 95 (-43.11%)
Mutual labels:  markdown, jsx, preact
Mdx
Markdown for the component era
Stars: ✭ 11,948 (+7054.49%)
Mutual labels:  markdown, jsx
Svgo
Go Language Library for SVG generation
Stars: ✭ 1,779 (+965.27%)
Mutual labels:  xml, markup
Redux React Starter
DEPRECATED use the new https://github.com/didierfranc/react-webpack-4
Stars: ✭ 137 (-17.96%)
Mutual labels:  jsx, preact
Omil
📝Webpack loader for Omi.js React.js and Rax.js components 基于 Omi.js,React.js 和 Rax.js 单文件组件的webpack模块加载器
Stars: ✭ 140 (-16.17%)
Mutual labels:  jsx, preact
Jsx Dom
Use JSX to create DOM elements.
Stars: ✭ 117 (-29.94%)
Mutual labels:  dom, jsx
Virtual Dom
关于Vue,React,Preact和Omi等框架源码的解读
Stars: ✭ 139 (-16.77%)
Mutual labels:  jsx, preact
Nativejsx
JSX to native DOM API transpilation. 💛 <div> ⟹ document.createElement('div')!
Stars: ✭ 145 (-13.17%)
Mutual labels:  dom, jsx
Preact And Typescript
Some simple patterns for Typescript usage with Preact
Stars: ✭ 127 (-23.95%)
Mutual labels:  jsx, preact
Jstoxml
JavaScript object to XML converter (useful for RSS, podcasts, GPX, AMP, etc)
Stars: ✭ 127 (-23.95%)
Mutual labels:  xml, jsx
Preact Minimal
🚀 Minimal preact structure
Stars: ✭ 136 (-18.56%)
Mutual labels:  jsx, preact
Binding.scala
Reactive data-binding for Scala
Stars: ✭ 1,539 (+821.56%)
Mutual labels:  xml, dom
X0
Document & develop React components without breaking a sweat
Stars: ✭ 1,706 (+921.56%)
Mutual labels:  markdown, jsx
Svgdom
Straightforward DOM implementation to make SVG.js run headless on Node.js
Stars: ✭ 154 (-7.78%)
Mutual labels:  xml, dom
Goober
🥜 goober, a less than 1KB 🎉 css-in-js alternative with a familiar API
Stars: ✭ 2,317 (+1287.43%)
Mutual labels:  dom, preact
Didom
Simple and fast HTML and XML parser
Stars: ✭ 1,939 (+1061.08%)
Mutual labels:  dom, xml
Uxdm
🔀 UXDM helps developers migrate data from one system or format to another.
Stars: ✭ 159 (-4.79%)
Mutual labels:  markdown, xml

preact-markup NPM travis-ci

A <Markup> component that renders HTML (or XML) using Virtual DOM, mapping a set of element names to Components. Works beautifully with Preact.

Think of this like an HTML5 renderer where Web Components are implemented as Preact Components.

⚡️ JSFiddle Demo ⚡️

demo preview

Use Cases

  • Rendering Markdown in VDOM - see preact-markdown
  • Component-base app design and/or layout via HTML
  • Define app structure using a standard HTML CMS
  • Support arbitrary component extensions by allowing safe HTML
  • Build using Custom Elements, implemented using React's API

Overview

The <Markup /> component takes some markup, an optional mapping of custom element names to components, and an optional type of either xml or html.

In it's simplest form, <Markup /> is just a diffing XML/HTML renderer. It only re-renders when you change the markup prop.

import Markup from 'preact-markup';

let html = `<h1>hello</h1> <p>Testing 1 2 3...</p>`;
render(<Markup markup={html} />, document.body);

Note: by default, content is parsed as XML, which may be too strict for your content but is the fastest option. Pass type="html" to parse as HTML.

Custom Elements via Components

The real value of <Markup /> is seen when passing a components prop. This prop is an Object that lets us map any HTML/XML element name to a preact Component. The mapped component is injected and rendered as if it had been referenced from within JSX. HTML attributes defined on the custom element in markup get passed to the mapped Component as props.

import Markup from 'preact-markup';

const Sidebar = ({ title, children }) => (
	<aside class="sidebar">
		<h2>{ title }</h2>
		{ children }
	</aside>
);

let html = `
<h1>Hello, World</h1>
<sidebar title="My Sidebar!">
	<p>Sidebar contents.</p>
</sidebar>
`;
render(<Markup markup={html} components={{ Sidebar }} />, document.body);

When render() is invoked, Our <Sidebar /> component is substituted for the <sidebar> element, which means it gets mounted and rendered like a normal Preact Component. The result is this HTML DOM:

<div class="markup">
	<h1>Hello, World</h1>
	<aside class="sidebar">
		<h2>My Sidebar!</h2>
		<p>Sidebar contents.</p>
	</aside>
</div>

Subsequent render()s diff against that DOM just like a normal JSX rendering flow would.

Optional properties

type - By default, content is parsed as XML. Pass type="html" to use an HTML parser.

trim - Trimming tries to emulate HTML semantics by default, but these differ from JSX semantics. Pass false to retain all whitespace, or all to omit all whitespace.

onError - Suppress XML/HTML parse errors and instead pass them to this function.

allow-scripts - By default, preact-markup sanitizes the rendered HTML by removing script tags. The allow-scripts property re-enables script tags, executing any JavaScript code within them.

Example
let markup = `<em>hello!</em><h1>asdflkj</h1><script>alert("Hello world");</script>`;
render(<Markup markup={markup} allow-scripts />, document.body);

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].