transformer

package
v0.0.0-...-c9993b8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

Local Transformer

The modifications in this package are described in more detail here.

NOTE: The transformed AMP HTML produced by the library is only valid inside of a signed exchange, and not to be served as normal HTML. Also, the library is still a work-in-progress and not all transformations described in the link above are implemented.

How to use

The local transformer can be used separately from the packager/signer. Here's an example use of the binary:

  1. go get -u github.com/ampproject/amppackager/cmd/transform
  2. $GOPATH/bin/transform -url "documentURL" /path/to/html

For more help, $GOPATH/bin/transform -h

See the binary source code for an example use of the library.

Documentation

Overview

Package transformer invokes the golang HTML parser, executes the individual transformers (unless overridden), and prints the output to the provided string.

Index

Constants

This section is empty.

Variables

View Source
var SupportedVersions = []*rpb.VersionRange{{Min: 1, Max: 2}}

SupportedVersions is a set of all transform versions supported by this snapshot of the library. This should not include transforms not yet snapshotted to a finalized version. The ranges should be non-overlapping and in descending order. Visible for test.

Functions

func Process

func Process(r *rpb.Request) (string, *rpb.Metadata, error)

Process will parse the given request, which contains the HTML to transform, applying the requested list of transformers, and return the transformed HTML and list of resources to preload (absolute URLs), or an error.

If the requested list of transformers is empty, apply the default.

func SelectVersion

func SelectVersion(requested []*rpb.VersionRange) (int64, error)

SelectVersion returns the highest requested version number that the transformer supports, or an error if no such version exists. The requested list must consist of non-overlapping ranges in descending order.

The transfomer will select the highest version from requested that it supports. If requested is nil or empty, the transfomer will select the highest version it supports. In both cases, it shouldn't include in-development versions.

Types

This section is empty.

Directories

Path Synopsis
internal
amphtml
Package amphtml contains common constants and utilies for working with AMP HTML.
Package amphtml contains common constants and utilies for working with AMP HTML.
css
Package css contains tools for parsing a CSS3 stylesheet.
Package css contains tools for parsing a CSS3 stylesheet.
htmlnode
Package htmlnode contains helpers to interact with html.Node
Package htmlnode contains helpers to interact with html.Node
testing
Package testing provides test constants and utilities for the transformer and printer.
Package testing provides test constants and utilities for the transformer and printer.
Package layout applies the AMP layout algorithm to a custom element (prefixed with "amp-").
Package layout applies the AMP layout algorithm to a custom element (prefixed with "amp-").
Package printer emits the given html.Node as HTML text to an io.Writer.
Package printer emits the given html.Node as HTML text to an io.Writer.
Package transformers performs AMP transformations/optimizations on the DOM tree.
Package transformers performs AMP transformations/optimizations on the DOM tree.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL