npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

CETEIcean

v1.9.2

Published

JavaScript library to load a TEI XML document and register it as HTML5 custom elements.

Downloads

411

Readme

CETEIcean 🐳

/sɪˈti:ʃn/

Build Status

What is this?

tl;dr: CETEIcean lets you display unmodified TEI documents in a web browser! Examples may be found here.

CETEIcean is a Javascript library that allows TEI documents to be displayed in a web browser without first transforming them to HTML. It uses the emerging Web Components standards, especially Custom Elements. It works by loading the TEI file dynamically, renaming the elements to follow the Custom Elements conventions, and registering them with the browser.

Because it preserves the full structure and information from your TEI data model, CETEIcean allows you to build rich web applications from your source documents using standard tools like CSS and Javascript.

CETEIcean was inspired by TEI Boilerplate, which also displays TEI in the browser, but differs from it in a couple of important ways. CETEIcean does not rely on an in-browser XSLT transformation, triggered by an XSLT directive in the source, so no modification to the source XML is necessary for it to work. Because it follows the Custom Elements standard, the HTML it produces is valid and there are no possibilities of element name collisions (like HTML <p> vs. TEI <p> for example).

Usage

You can use CETEIcean in your projects just by grabbing the CETEI.js file from the latest release and linking to it in an HTML file like the examples do. Note that you'll want also to grab the example CSS or make your own. If you want to build and play with it on your own, follow the steps below.

Simple Usage Example

This code fetches a TEI file, transforms it into HTML Custom Elements, and places the result in a div with id "TEI".

var CETEIcean = new CETEI()
CETEIcean.getHTML5("URL_TO_YOUR_TEI.xml", function(data) {
  document.getElementById("TEI").appendChild(data)
})

By default, CETEIcean saves and restores the scroll position for a document via a URL fragment. To turn this behavior off, particularly when using CETEIcean for Server Side Rendering, you can set the ignoreFragmentId option to true:

new CETEI({
  ignoreFragmentId: true
})

Usage with Node

CETEIcean can be used on the server by providing a DOM implementation, such as JSDOM. You can pass a document object as an option when instantiating CETEIcean.

import { JSDOM } from 'jsdom';
import CETEI from 'CETEIcean';

const jdom = new JSDOM(`<TEI xmlns="http://www.tei-c.org/ns/1.0" />`, {contentType: 'text/xml'});
new CETEI({
  documentObject: jdom.window.document
})

Other methods

getHTML5( url, callback, perElementFn )

Returns a Promise that fetches an XML source document then calls the makeHTML5 method on the returned document.

Parameters:

  • url: The XML document will be fetched from the provided URL.
  • callback: A function to be called on the results.
  • perElementFn: A function to be called on each resulting element.

makeHTML5( XML, callback, perElementFn )

Converts the supplied XML string into HTML5 Custom Elements.

Parameters:

  • XML: The XML document serialized to string.
  • callback: A function to be called on the results.
  • perElementFn: A function to be called on each resulting element.

domToHTML5( XML_dom, callback, perElementFn )

Converts the supplied XML string into HTML5 Custom Elements.

Parameters:

  • XML_dom: The XML document as DOM.
  • callback: A function to be called on the results.
  • perElementFn: A function to be called on each resulting element.

unsetNamespace( ns )

To change a namespace to prefix mapping, the namespace must first be unset. Takes a namespace URI. In order to process a TEI P4 document, e.g., the TEI namespace must be unset before it can be set to the empty string.

setBaseUrl( base )

Sets the base URL for the document. Used to rewrite relative links in the XML source (which may be in a completely different location from the HTML wrapper).

Install

Get NodeJS.

Run

npm i

Build

npm run build

puts a copy of CETEI.js in the dist/ folder

Develop

npm run dev

runs a local web server on port 8888. Browse to the examples in the test/ folder. Make changes and they'll show up when you reload.

Use

Run the build process and then include the generated CETEI.js file in an HTML document like the simpleTest.html file in the test/ folder. Or, use the server-side language and framework of your choice to generate such files on demand.

Customize

TEI documents displayed using CETEIcean can be customized via CSS or by specifying behaviors for individual elements. For documentation on behaviors see the wiki.