Sablon.HTMLConverter.AST (sablon v0.4.4)

Copy Markdown View Source

Dispatch helpers shared by every AST node.

An AST node is a struct whose module implements to_docx/1, children/1, put_children/2 and describe/1. Keeping the contract this small is what lets an application register its own AST class for a custom HTML tag.

Summary

Functions

Applies visitor to ast and, recursively, to its children.

Renders an attribute map as XML attributes, prefixed with a space.

The child AST nodes of ast.

Converts a single CSS property, walking style_chain in order.

A compact textual rendering of the tree, mirroring #inspect in the Ruby gem. Useful in tests and when debugging a conversion.

Collects every node in the tree for which pattern matches.

Maps CSS properties onto their WordML equivalents.

Replaces the child AST nodes of ast.

Serialises an AST node to WordML.

Functions

accept(nodes, visitor)

@spec accept(struct() | [struct()], module() | (struct() -> struct())) ::
  struct() | [struct()]

Applies visitor to ast and, recursively, to its children.

A visitor is a module (or a function) returning the node it was given, possibly modified - which is how Sablon.HTMLConverter.Visitor strips the trailing newline of a paragraph.

attributes_to_docx(attributes)

@spec attributes_to_docx(map() | list()) :: binary()

Renders an attribute map as XML attributes, prefixed with a space.

children(ast)

@spec children(struct()) :: [struct()]

The child AST nodes of ast.

convert_style_property(arg1, key, value)

@spec convert_style_property([atom()], term(), term()) :: {term(), term()}

Converts a single CSS property, walking style_chain in order.

describe(nodes)

@spec describe(struct() | [struct()]) :: binary()

A compact textual rendering of the tree, mirroring #inspect in the Ruby gem. Useful in tests and when debugging a conversion.

grep(nodes, pattern)

@spec grep(struct() | [struct()], module() | (struct() -> boolean())) :: [struct()]

Collects every node in the tree for which pattern matches.

process_properties(style_chain, properties)

@spec process_properties([atom()], Sablon.Props.t()) :: Sablon.Props.t()

Maps CSS properties onto their WordML equivalents.

style_chain names the converter tables to search, from the most specific AST node to :node; keys that are already atoms are WordML properties and are passed through untouched.

put_children(ast, children)

@spec put_children(
  struct(),
  [struct()]
) :: struct()

Replaces the child AST nodes of ast.

to_docx(nodes)

@spec to_docx(struct() | [struct()]) :: binary()

Serialises an AST node to WordML.