brackets 1.0.0 copy "brackets: ^1.0.0" to clipboard
brackets: ^1.0.0 copied to clipboard

Lean markup representation and rendering.

brackets #

A lightweight Dart package for building and rendering markup (HTML/XML).

Table of Contents #

Overview #

brackets offers a concise way to create markup structures in Dart using a unique approach based on Dart's extension methods and operators. Instead of providing a fluent API, it leverages extensions to create a terse, yet powerful markup generation system.

The resulting structure is an Abstract Syntax Tree (AST), which is represented using Algebraic Data Types (ADTs). This allows for easy manipulation and transformation of the markup structure.

Installation #

Add to your pubspec.yaml:

dependencies:
  brackets: ^1.0.0

Usage #

Basic Markup #

Create simple markup nodes:

final node = 'div'(['Hello'.$]);
print(node.render());

Output:

<div>Hello</div>

Working with HTML #

Build complete HTML documents:

final document = html([
  'head'([
    'title'(['My Page'.$]),
  ]),
  'body'([
    'h1'(['Welcome'.$]),
    'p'(['Content here'.$]),
  ]),
]);

print(document.render());

Output:

<!DOCTYPE html><html><head><title>My Page</title></head><body><h1>Welcome</h1><p>Content here</p></body></html>

Working with XML #

Create XML documents:

final xmlDoc = xml([
  'root'([
    'child'(['data'.$]),
  ]),
]);

print(xmlDoc.render());

Output:

<?xml version="1.0" encoding="UTF-8"?><root><child>data</child></root>

Attributes #

Add attributes to tags:

final element = 'div'(
  ['Content'.$],
  attrs: {'class': 'container', 'id': 'main'},
);

print(element.render());

Output:

<div class="container" id="main">Content</div>

For more examples, check the example file.

1
likes
150
points
101
downloads

Publisher

verified publisheryakov.codes

Weekly Downloads

Lean markup representation and rendering.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on brackets