NLdoc.Conversion.Writer.Html (NLdoc.Conversion.Writer.Html v1.4.1)

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.

Convert resources into Floki's Simple Form. 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()}
  | {:fn_asset_to_uri, (NLdoc.Spec.Asset.t() -> String.t())}

Functions

convert(content, opts \\ [])

@spec convert(content :: 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>"

convert_to_simple_form(content, opts \\ [])

@spec convert_to_simple_form(content :: NLdoc.Spec.Document.t(), opts :: [opt()]) ::
  Floki.html_tag()
@spec convert_to_simple_form(content :: [NLdoc.Spec.object()], opts :: [opt()]) :: [
  Floki.html_node()
]

Convert resources into Floki's Simple Form. Either pass a Document, or pass a List of resources.

Examples

iex> resources = [ ...> %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: "."} ...> ] ...> } ...> ] iex> NLdoc.Conversion.Writer.Html.convert_to_simple_form(resources) [{"h1", [], ["Hello ", {"em", [], ["World"]}]}, {"p", [], ["Followed by a ", {"strong", [], ["paragraph"]}, "."]}] iex> doc = %NLdoc.Spec.Document{children: resources} iex> NLdoc.Conversion.Writer.Html.convert_to_simple_form(doc) {"html", [{"lang", "und"}], [

{"head", [], [
  {"title", [], ["Document"]},
  {"style", [], [
    "section.footnotes { border-top: 1px solid; }",
    ".lst-square { list-style-type: square; }",
    ".lst-circle { list-style-type: circle; }"
  ]}
]},
{"body", [], [
  {"h1", [], ["Hello ", {"em", [], ["World"]}]},
  {"p", [], ["Followed by a ", {"strong", [], ["paragraph"]}, "."]}
]}

]}