Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/kawarimidoll/deno-markup-tag

Render markup tag easily
https://github.com/kawarimidoll/deno-markup-tag

deno deno-module denoland html markup svg

Last synced: 3 months ago
JSON representation

Render markup tag easily

Awesome Lists containing this project

README

        

# deno-markup-tag

[![ci](https://github.com/kawarimidoll/deno-markup-tag/workflows/ci/badge.svg)](.github/workflows/ci.yml)
[![deno version](https://img.shields.io/badge/deno-%5E1.13.0-green?logo=deno)](https://deno.land)
[![LICENSE](https://img.shields.io/badge/license-MIT-brightgreen)](LICENSE)
[![deno.land](https://img.shields.io/github/v/tag/kawarimidoll/deno-markup-tag?style=flat&logo=deno&label=deno.land&color=steelblue&sort=semver)](https://deno.land/x/markup_tag)
[![nest badge](https://nest.land/badge.svg)](https://nest.land/package/markup-tag)

## Usage

[![deno doc](https://doc.deno.land/badge.svg)](https://doc.deno.land/https/deno.land/x/markup_tag/mod.ts)

### Import

From [deno.land/x](https://deno.land/x):

```ts
import { tag } from "https://deno.land/x/[email protected]/mod.ts";
```

From [x.nest.land](http://nest.land):

```ts
import { tag } from "https://x.nest.land/[email protected]/mod.ts";
```

From [pax.deno.dev](http://pax.deno.dev):

```ts
import { tag } from "https://pax.deno.dev/kawarimidoll/[email protected]";
```

### tag

Render markup tag.

```ts
// common usage
assertEquals(
tag("div", { id: "foo", class: "bar" }, "Hello world!"),
`

Hello world!
`,
);

// void (no-close) tag
assertEquals(tag("meta", { charset: "utf-8" }), ``);

// nested tags
assertEquals(
tag("ul", { class: "nav" }, tag("li", "first"), tag("li", "second")),
`

`,
);

// boolean attributes
assertEquals(
tag("button", { type: "button", disabled: true }, "disabled"),
`disabled`,
);

// skip attributes
assertEquals(
tag("input", { type: "text", readonly: false }),
``,
);
```

### Character references

These constants are exported.

```ts
const NBSP = " ";
const LT = "<";
const GT = ">";
const AMP = "&";
const QUOT = """;
```

### sanitize

Sanitize `&`, `<`, `>` and `"` in string.

```ts
// common usage
assertEquals(
sanitize(``),
"<img src="https://www.example.com?width=10&height=10">",
);

// ignore sanitizing specific characters
assertEquals(sanitize("
", { lt: false, gt: false }), "
");
```