NativeElixirPdfUtilities.Validators.HtmlUrlValidator (native_elixir_pdf_utilities v1.1.0)

View Source

Prepares static document URLs independently of resource authorization.

The first HTML base[href] outside template and foreign trees supplies the resolution base. :base_url supplies the fallback URL; local caller values retain their existing directory meaning. Consumers must authorize resolved resources against the original caller root, never against this context.

Anchor destinations are {:uri, url} or {:fragment, identifier}. The latter requires final document target positions and must not be emitted as a URI. This context contains no filesystem permissions and grants no access.

Summary

Functions

Admits an absolute initial input URL without granting resource access.

Classifies the HTML about:blank URL family without granting resource access.

Prepares the document's resolution base without changing caller permissions.

Prepares an authored base against an already validated document URL.

Resolves a static anchor into a URI or a same-document fragment destination.

Resolves a URL reference against a prepared base, without authorizing or reading it.

Prepares a resource reference for the existing authorized asset loader.

Tests an absolute initial URL input without a base or resource access.

Validates a base element's attributes and empty content.

Types

context()

@type context() :: %{
  fallback_base: String.t() | nil,
  resolution_base: String.t() | nil,
  authored_base?: boolean()
}

destination()

@type destination() :: {:uri, String.t()} | {:fragment, String.t()}

Functions

absolute_input_url?(source)

@spec absolute_input_url?(binary()) :: boolean()

Admits an absolute initial input URL without granting resource access.

blank_document_url(reference)

@spec blank_document_url(term()) :: {:ok, String.t()} | :not_blank

Classifies the HTML about:blank URL family without granting resource access.

document_context(dom, opts)

@spec document_context(
  map(),
  keyword()
) ::
  {:ok, context()}
  | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Prepares the document's resolution base without changing caller permissions.

document_context_from_url(dom, fallback)

@spec document_context_from_url(map(), String.t() | nil) ::
  {:ok, context()}
  | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Prepares an authored base against an already validated document URL.

Unlike document_context/2, this preserves a child document's file URL as a document URL. The caller supplies a validated parsed DOM and absolute fallback URL, and retains ownership of authorization, document/tree identities and budgets.

prepare_anchor(href, context)

@spec prepare_anchor(term(), context()) ::
  {:ok, destination()}
  | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Resolves a static anchor into a URI or a same-document fragment destination.

resolve_reference(reference, base)

@spec resolve_reference(String.t(), String.t() | nil) ::
  {:ok, String.t()}
  | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Resolves a URL reference against a prepared base, without authorizing or reading it.

resource_reference(reference, context)

@spec resource_reference(String.t(), context()) ::
  {:ok, String.t()}
  | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Prepares a resource reference for the existing authorized asset loader.

valid_initial_input_url?(value)

@spec valid_initial_input_url?(term()) ::
  {:ok, boolean()}
  | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Tests an absolute initial URL input without a base or resource access.

validate_base_element(attributes, children)

@spec validate_base_element(map(), list()) ::
  :ok | {:error, {atom(), NativeElixirPdfUtilities.Diagnostics.diagnostic()}}

Validates a base element's attributes and empty content.