Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gfldex/perl6-typesafe-html

typesafe baseclass for Typesafe::XHTML::Writer
https://github.com/gfldex/perl6-typesafe-html

Last synced: 13 days ago
JSON representation

typesafe baseclass for Typesafe::XHTML::Writer

Awesome Lists containing this project

README

        

# Typesafe::HTML
[![Build Status](https://travis-ci.org/gfldex/perl6-typesafe-html.svg?branch=master)](https://travis-ci.org/gfldex/perl6-typesafe-html)

Baseclass to be used with Typesafe::XHTML::Writer. It overloads `infix:<~>` to
guard against omision of HTML-element quotation. This is not a DOM
implementation, it's merely a secure way to concatanate HTML and non-HTML
strings. It's lightweight by design, resulting in fairly good speed.

The only characters that are turned into HTML-Entities are `<` and `&`. If you
need more use a modules that does not focus on speed.

## Usage:
```
use v6;
use Typesafe::HTML;

my $html = HTML.new('

this will not be quoted

');
$html ~= '

this will

';
$html = $html ~ '& this will also be quoted';
$html = '& this prefix too' ~ $html;

dd $html;

# OUTPUT: HTML $html = HTML.new('& this prefix too

this will not be quoted

<p>this will</p>& this will also be quoted');

$html = HTML.new ~ '& more quoting';

dd $html;

# OUTPUT: HTML $html = HTML.new('& more quoting');

put $html.Str;

# OUTPUT: & more quoting
```

## License

(c) Wenzel P. P. Peppmeyer, Released under Artistic License 2.0.