defmodule NLdoc.Validation.Rules.PAsHeading do @moduledoc """ Ensures paragraph elements are not used to style headings. """ alias NLdoc.Spec.Paragraph alias NLdoc.Validation.Severity use NLdoc.Validation.Rule, severity: Severity.warning(), rule: "p-as-heading", ruleset: "https://dequeuniversity.com/rules/axe/html", ruleset_version: "4.10", validates: [Paragraph] @impl true def valid?(paragraph = %Paragraph{children: children}, _) do !Enum.all?(children, &bold?/1) || !NLdoc.Spec.Content.discernible_text?(paragraph) end @spec bold?(term()) :: boolean() defp bold?(%{styling: styling, text: text}), do: Enum.member?(styling, :bold) || !NLdoc.Spec.Content.discernible_text?(text) defp bold?(_), do: false end