html library

Typed, escaped HTML for Daravel responses (Laravel's Blade, as Dart functions). A separate import, because names such as a, p and text would clash with ordinary variables:

import 'package:daravel/html.dart';

Classes

Element
An element with attributes and children.
Fragment
Several nodes without a wrapping element.
HtmlDocument
A whole page: <!doctype html>, <head> with title, charset and viewport, and body.
HtmlNode
A typed HTML tree: text and attributes are escaped, raw markup has to be asked for (raw), and a node returned from a handler is sent as HTML.
RawHtml
Markup written as is (Blade's {!! $value !!}): only for trusted HTML.
TextNode
Text, escaped (Blade's {{ $value }}).

Functions

a(List<Object?> children, {required String href, String? classes, Map<String, Object?> attributes = const {}}) → Element
An <a> linking to the given URL.
article(List<Object?> children, {String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
An <article>.
br() → Element
A <br>.
button(List<Object?> children, {String type = 'button', String? classes, Map<String, Object?> attributes = const {}}) → Element
A <button>.
code(List<Object?> children, {String? classes, Map<String, Object?> attributes = const {}}) → Element
A <code>.
div(List<Object?> children, {String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
A <div>.
document(List<Object?> body, {String title = '', List<Object?> head = const [], String lang = 'en'}) → HtmlDocument
A whole page.
el(String tag, [List<Object?> children = const [], String? id, String? classes, Map<String, Object?> attributes = const {}]) → Element
Any element: el('details', [...], attributes: {'open': true}).
em(List<Object?> children, {String? classes, Map<String, Object?> attributes = const {}}) → Element
An <em>.
escapeHtml(String value) → String
Escapes & < > " ' for text and attribute values.
A <footer>.
form(List<Object?> children, {required String action, String method = 'POST', String? classes, Map<String, Object?> attributes = const {}}) → Element
A <form>.
fragment(List<Object?> children) → Fragment
Nodes without a wrapping element.
h1(List<Object?> children, {String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
An <h1>.
h2(List<Object?> children, {String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
An <h2>.
h3(List<Object?> children, {String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
An <h3>.
A <header>.
hr() → Element
An <hr>.
img({required String src, required String alt, String? classes, Map<String, Object?> attributes = const {}}) → Element
An <img>.
input({required String name, String type = 'text', Object? value, String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
An <input>.
label(List<Object?> children, {String? forId, String? classes, Map<String, Object?> attributes = const {}}) → Element
A <label>.
li(List<Object?> children, {String? classes, Map<String, Object?> attributes = const {}}) → Element
An <li>.
A <link rel=... href=...>.
mainEl(List<Object?> children, {String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
<main> (main is the Dart entry point name).
meta({Map<String, Object?> attributes = const {}}) → Element
A <meta>.
A <nav>.
ol(List<Object?> children, {String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
An <ol>.
p(List<Object?> children, {String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
A <p>.
pre(List<Object?> children, {String? classes, Map<String, Object?> attributes = const {}}) → Element
A <pre>.
raw(String html) → RawHtml
Trusted markup, written as is.
section(List<Object?> children, {String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
A <section>.
span(List<Object?> children, {String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
A <span>.
strong(List<Object?> children, {String? classes, Map<String, Object?> attributes = const {}}) → Element
A <strong>.
table(List<Object?> children, {String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
A <table>.
tbody(List<Object?> children) → Element
A <tbody>.
td(List<Object?> children, {String? classes, Map<String, Object?> attributes = const {}}) → Element
A <td>.
text(Object? value) → TextNode
Escaped text.
textarea({required String name, String value = '', String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
A <textarea>.
th(List<Object?> children, {String? classes, Map<String, Object?> attributes = const {}}) → Element
A <th>.
thead(List<Object?> children) → Element
A <thead>.
tr(List<Object?> children, {String? classes, Map<String, Object?> attributes = const {}}) → Element
A <tr>.
ul(List<Object?> children, {String? id, String? classes, Map<String, Object?> attributes = const {}}) → Element
A <ul>.