amperize
AMP up your plain HTML
Last updated a year ago by aileencgn .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install amperize 
SYNC missed versions from official npm registry.

Amperize

Version npm Build Status Dependencies Coverage Status

AMP up your plain HTML. Replaces regular HTML tags with their equivalent AMP components.

Installation

npm install amperize

Node.js

var Amperize = require('amperize');

var html = '<img src="https://example.com/image.jpg" />';

var amperize = new Amperize();

amperize.parse(html, function (error, result) {
    if (error) {
        // do something with error
        return new Error(err);
    }
    // do something with result
    return result;
});

Restrictions

Amperize is build to convert the <body> part of your HTML. It will not create the AMP boilerplate and will not add the required <script> for each component.

Currently supported AMP HTML components

<amp-img>

<amp-img> reference

Amperize will convert common <img> tags into AMP HTML conform <amp-img> tags. With the sub-dependencies [probe-image-size](https://github.com/nodeca/probe-image-size) and [image-size](https://github.com/image-size/image-size), Amperize will fetch the necessarywidthandheight` properties for the given image.

It will fall back to the default values width: 600 and height: 400, if the dimensions couldn't be fetched.

If any other error occurs (eg. missing src property), Amperize will not transform the tag and return the original.

<amp-anim>

<amp-anim> reference

When the <img> tag that needs to be transformed, is a .gif animation, Amperize will convert it into <amp-anim>, following the same rules as for <amp-img>.

<amp-iframe>

<amp-iframe> reference

Amperize converts iFrames like embedded videos from Vimeo, etc. into <amp-iframe> tags. If the src attribute is an http URL it will be switched to https in order to pass AMP validation.

<amp-youtube>

<amp-youtube> reference

Amperize converts iFrames with a "YouTube" URL into <amp-youtube> tags. If the src attribute is an http URL it will be switched to https in order to pass AMP validation.

<amp-audio>

<amp-audio> reference

Converts HTML <audio> into <amp-audio>. If the src attribute is an http URL it will be switched to https in order to pass AMP validation.

Development

git clone git@github.com:jbhannah/amperize.git

cd amperize

npm install

npm run watch

npm run watch will restart the tests on changes.

Tests

Running the test:

npm run test

Code coverage:

npm run coverage

Credits

Borrows heavily from Minimize, especially the constructor, parse, amperizer, and traverse functions in the Amperize object, and the unit tests. Copyright (c) 2013 Moveo - Martijn Swaagman. Used under the MIT License (see LICENSE).

Current Tags

  • 0.6.1                                ...           latest (5 months ago)

22 Versions

  • 0.6.1                                ...           5 months ago
  • 0.6.0                                ...           a year ago
  • 0.5.2                                ...           a year ago
  • 0.5.1                                ...           a year ago
  • 0.5.0                                ...           a year ago
  • 0.4.0                                ...           a year ago
  • 0.3.8                                ...           2 years ago
  • 0.3.7                                ...           3 years ago
  • 0.3.6                                ...           3 years ago
  • 0.3.5                                ...           3 years ago
  • 0.3.4                                ...           3 years ago
  • 0.3.3                                ...           3 years ago
  • 0.3.2                                ...           3 years ago
  • 1.0.0                                ...           4 years ago
  • 0.3.1                                ...           4 years ago
  • 0.3.0                                ...           4 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.5                                ...           5 years ago
  • 0.1.4                                ...           5 years ago
  • 0.1.3                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Downloads
Today 1
This Week 1
This Month 32
Last Day 0
Last Week 4
Last Month 23
Dependencies (11)
Dev Dependencies (9)

Copyright 2014 - 2016 © taobao.org |