Skip to content

Instantly share code, notes, and snippets.

@pimterry
Last active May 18, 2016 13:23
Show Gist options
  • Save pimterry/860d7cd7b68d1944f600b02481c0db9f to your computer and use it in GitHub Desktop.
Save pimterry/860d7cd7b68d1944f600b02481c0db9f to your computer and use it in GitHub Desktop.
A linkifying example Server Component component.
var components = require("server-components");
// We have a DOM simulation: quite a few client-side JS libraries will Just Work
var linkify = require("linkifyjs/element");
/**
* A <linkify-urls> element, which finds plain text URLs within its content,
* and automatically rerenders them wrapped in <a> tags.
*/
var LinkifyElement = components.newElement();
LinkifyElement.createdCallback = function (document) {
linkify(this, {
target: () => null,
linkClass: "autolinked"
}, document);
};
components.registerElement("linkify-urls", { prototype: LinkifyElement });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment