NLdoc.Conversion.Writer.Html (NLdoc.Conversion.Writer.Html v1.1.0-alpha.2)

View Source

Writer for HTML, converting from Spec to HTML.

Summary

Functions

Convert resources into raw HTML. Either pass a Document, or pass a List of resources.

Types

acc()

html_tag_or_text()

@type html_tag_or_text() :: Floki.html_tag() | Floki.html_text()

opt()

@type opt() :: {:pretty, boolean()}

Functions

convert(resource, opts \\ [])

@spec convert(NLdoc.Spec.Document.t() | [NLdoc.Spec.object()], [opt()]) :: String.t()

Convert resources into raw HTML. Either pass a Document, or pass a List of resources.

Examples

iex> [ 
...>   %NLdoc.Spec.Heading{
...>     level: 1, 
...>     children: [
...>       %NLdoc.Spec.Text{text: "Hello "},
...>       %NLdoc.Spec.Text{text: "World", styling: [:italic]}
...>     ]
...>   },
...>   %NLdoc.Spec.Paragraph{
...>     children: [
...>       %NLdoc.Spec.Text{text: "Followed by a "},
...>       %NLdoc.Spec.Text{text: "paragraph", styling: [:bold]},
...>       %NLdoc.Spec.Text{text: "."}
...>     ]
...>   }
...> ]
...> |> NLdoc.Conversion.Writer.Html.convert()
"<h1>Hello <em>World</em></h1><p>Followed by a <strong>paragraph</strong>.</p>"