Renders publishing post markdown to HTML with caching support.
Uses PhoenixKit.Cache for performance optimization of markdown rendering. Cache keys include content hashes for automatic invalidation.
Summary
Functions
Clears all publishing post caches.
Clears the render cache for a specific group.
The PHK component tags the renderer understands, for editors that must keep
them intact. See @component_tags.
Returns whether the global render cache is enabled.
Returns whether render cache is enabled for a specific group. Does not check the global setting.
Invalidates cache for a specific post.
The post's author notes in document order:
[%{number: n, id: stable_id, body: text}]. The id is derived from the
note text (not the number), so a comment anchored to a note survives the
author inserting an earlier note — it detaches only when the note text
itself changes. The post template uses this to render the slide-out
panels in "panel" notes style; a <Note> inside a code fence is ignored
(same mask as rendering).
Stable DOM/comment anchor for a note: a short url-safe digest of the
note text. Content-addressed on purpose — see list_notes/1. Repeated
identical note texts get occurrence-suffixed digests (2nd, 3rd, …) so
panel DOM ids stay unique; the first occurrence keeps the plain digest,
so existing comments never detach when a duplicate appears later.
Returns the settings key for per-group render cache. Used by other modules that need to write to the setting.
Returns whether render caching is enabled for a group.
Renders markdown or PHK content directly without caching.
Renders a post's markdown content to HTML.
Functions
@spec clear_all_cache() :: :ok
Clears all publishing post caches.
Useful for testing or when doing bulk updates.
@spec clear_group_cache(String.t()) :: {:ok, non_neg_integer()} | {:error, any()}
Clears the render cache for a specific group.
Returns {:ok, count} with the number of entries cleared.
Examples
Renderer.clear_group_cache("my-group")
# => {:ok, 15}
@spec component_tags() :: [String.t()]
The PHK component tags the renderer understands, for editors that must keep
them intact. See @component_tags.
@spec global_render_cache_enabled?() :: boolean()
Returns whether the global render cache is enabled.
Returns whether render cache is enabled for a specific group. Does not check the global setting.
Invalidates cache for a specific post.
Called when a post is updated in the admin editor.
Examples
Renderer.invalidate_cache("docs", "getting-started", "en")
The post's author notes in document order:
[%{number: n, id: stable_id, body: text}]. The id is derived from the
note text (not the number), so a comment anchored to a note survives the
author inserting an earlier note — it detaches only when the note text
itself changes. The post template uses this to render the slide-out
panels in "panel" notes style; a <Note> inside a code fence is ignored
(same mask as rendering).
Stable DOM/comment anchor for a note: a short url-safe digest of the
note text. Content-addressed on purpose — see list_notes/1. Repeated
identical note texts get occurrence-suffixed digests (2nd, 3rd, …) so
panel DOM ids stay unique; the first occurrence keeps the plain digest,
so existing comments never detach when a duplicate appears later.
Returns the settings key for per-group render cache. Used by other modules that need to write to the setting.
Returns whether render caching is enabled for a group.
Checks both the global setting and per-group setting. Both must be enabled (or default to enabled) for caching to work.
Renders markdown or PHK content directly without caching.
Automatically detects PHK XML format and routes to PageBuilder. Falls back to MDEx markdown rendering for non-XML content.
Examples
html = Renderer.render_markdown(content)
Renders a post's markdown content to HTML.
Caches the result for published posts using content-hash-based keys. Lazy-loads cache (only caches after first render).
Respects publishing_render_cache_enabled (global) and
publishing_render_cache_enabled_{group_slug} (per-group) settings.
Examples
{:ok, html} = Renderer.render_post(post)