

HtmlEntities — HtmlEntities v0.5.2

try { if(localStorage.getItem('night-mode') === 'true') document.body.className += ' night-mode'; } catch (e) { }

HtmlEntities

============

[![Module Version](https://img.shields.io/hexpm/v/html_entities.svg)](https://hex.pm/packages/html_entities)

[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/html_entities/)

[![Total Download](https://img.shields.io/hexpm/dt/html_entities.svg)](https://hex.pm/packages/html_entities)

[![License](https://img.shields.io/hexpm/l/html_entities.svg)](https://github.com/martinsvalin/html_entities/blob/master/LICENSE)

[![Last Updated](https://img.shields.io/github/last-commit/martinsvalin/html_entities.svg)](https://github.com/martinsvalin/html_entities/commits/master)

Elixir module for decoding and encoding HTML entities in a string.

Entity names, codepoints and their corresponding characters are copied from

[Wikipedia](https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references).

 Installation

---------------

Add the dependency to your `mix.exs` file, then run [`mix deps.get`](https://hexdocs.pm/mix/Mix.Tasks.Deps.Get.html).

```

defp deps do

 [

 {:html\_entities, "~> 0.5"}

 ]

end

```

 Usage

--------

Inside IEx:

```

iex> HtmlEntities.decode("Tom &amp; Jerry")

"Tom & Jerry"

iex> HtmlEntities.decode("&#161;Ay, caramba!")

"¡Ay, caramba!"

iex> HtmlEntities.encode("<< KAPOW!! >>")

"&lt;&lt; KAPOW!! &gt;&gt;"

```

Inside a module:

```

defmodule EntityTest do

 def non\_breaking\_space do

 HtmlEntities.decode("&#161;")

 end

end

```

 License

----------

Copyright (c) 2015 Martin Svalin

This library is MIT licensed. See the [LICENSE](https://github.com/martinsvalin/html_entities/blob/master/LICENSE) for details.





HtmlEntities — HtmlEntities v0.5.2

try { if(localStorage.getItem('night-mode') === 'true') document.body.className += ' night-mode'; } catch (e) { }

 HtmlEntities (HtmlEntities v0.5.2)

[View Source](https://github.com/martinsvalin/html_entities/blob/v0.5.2/lib/html_entities.ex#L1 "View Source")

===================================================================================================================================================

Decode and encode HTML entities in a string.

 Examples

-----------

Decoding:

```

iex> "Tom &amp; Jerry" |> HtmlEntities.decode

"Tom & Jerry"

iex> "&#161;Ay, caramba!" |> HtmlEntities.decode

"¡Ay, caramba!"

iex> "&#337; &#x151;" |> HtmlEntities.decode

"ő ő"

```

Encoding:

```

iex> "Tom & Jerry" |> HtmlEntities.encode

"Tom &amp; Jerry"

iex> "<< KAPOW!! >>" |> HtmlEntities.encode

"&lt;&lt; KAPOW!! &gt;&gt;"

```

 

[Link to this section](#summary)

 Summary

==========================================

[Functions](#functions)

------------------------

[decode(string)](#decode/1)

Decode HTML entities in a string.

[encode(string)](#encode/1)

Encode HTML entities in a string.

[Link to this section](#functions)

Functions

=============================================

[Link to this function](#decode/1 "Link to this function")

decode(string)

==============

[View Source](https://github.com/martinsvalin/html_entities/blob/v0.5.2/lib/html_entities.ex#L28 "View Source")

Specs

-----

```

decode([String.t](https://hexdocs.pm/elixir/String.html#t:t/0)()) :: [String.t](https://hexdocs.pm/elixir/String.html#t:t/0)()

```

Decode HTML entities in a string.

 

[Link to this function](#encode/1 "Link to this function")

encode(string)

==============

[View Source](https://github.com/martinsvalin/html_entities/blob/v0.5.2/lib/html_entities.ex#L77 "View Source")

Specs

-----

```

encode([String.t](https://hexdocs.pm/elixir/String.html#t:t/0)()) :: [String.t](https://hexdocs.pm/elixir/String.html#t:t/0)()

```

Encode HTML entities in a string.

 





HtmlEntities.Util — HtmlEntities v0.5.2

try { if(localStorage.getItem('night-mode') === 'true') document.body.className += ' night-mode'; } catch (e) { }

 HtmlEntities.Util (HtmlEntities v0.5.2)

[View Source](https://github.com/martinsvalin/html_entities/blob/v0.5.2/lib/html_entities/util.ex#L1 "View Source")

=============================================================================================================================================================

Utility functions for managing metadata.

Putting this code here makes it testable, and allows the code

generation part of HtmlEntities to be as small as possible.

 

[Link to this section](#summary)

 Summary

==========================================

[Types](#types)

----------------

[entity()](#t:entity/0)

[Functions](#functions)

------------------------

[convert\_line\_to\_entity(line)](#convert_line_to_entity/1)

Converts a line of comma-separated lines to entity definitions.

[load\_entities(filename)](#load_entities/1)

Load HTML entities from an external file.

[Link to this section](#types)

Types

=====================================

[Link to this type](#t:entity/0 "Link to this type")

entity()

========

[View Source](https://github.com/martinsvalin/html_entities/blob/v0.5.2/lib/html_entities/util.ex#L9 "View Source")

Specs

-----

```

entity() :: {[String.t](https://hexdocs.pm/elixir/String.html#t:t/0)(), [String.t](https://hexdocs.pm/elixir/String.html#t:t/0)(), [integer](https://hexdocs.pm/elixir/typespecs.html#basic-types)()}

```

[Link to this section](#functions)

Functions

=============================================

[Link to this function](#convert_line_to_entity/1 "Link to this function")

convert\_line\_to\_entity(line)

===============================

[View Source](https://github.com/martinsvalin/html_entities/blob/v0.5.2/lib/html_entities/util.ex#L19 "View Source")

Specs

-----

```

convert_line_to_entity([[String.t](https://hexdocs.pm/elixir/String.html#t:t/0)()] | [File.Stream.t](https://hexdocs.pm/elixir/File.Stream.html#t:t/0)()) :: [entity](#t:entity/0)()

```

Converts a line of comma-separated lines to entity definitions.

 

[Link to this function](#load_entities/1 "Link to this function")

load\_entities(filename)

========================

[View Source](https://github.com/martinsvalin/html_entities/blob/v0.5.2/lib/html_entities/util.ex#L13 "View Source")

Specs

-----

```

load_entities([String.t](https://hexdocs.pm/elixir/String.html#t:t/0)()) :: [[entity](#t:entity/0)()]

```

Load HTML entities from an external file.

 





API Reference — HtmlEntities v0.5.2

try { if(localStorage.getItem('night-mode') === 'true') document.body.className += ' night-mode'; } catch (e) { }

 API Reference HtmlEntities v0.5.2

===================================

 Modules

----------

[HtmlEntities](HtmlEntities.html)

Decode and encode HTML entities in a string.

[HtmlEntities.Util](HtmlEntities.Util.html)

Utility functions for managing metadata.

