The CWA is in heavy development
The CWA is still in alpha and not ready for production - some code and implementations are likely to change. If you would like to try out the CWA, please enjoy what we have provided and feel free to provide feedback, or get involved on GitHub.
DraftComponent Helpers

HTML Content

Render rich-text HTML from a CWA resource with CwaLink replacing anchor tags so internal links stay client-side.

Rich-text components (e.g. a WYSIWYG or markdown-rendered field) output raw HTML containing <a> tags. Rendering that HTML with v-html works, but <a> tags cause full-page reloads for internal links. useHtmlContent solves this by replacing every <a> tag in the container with a <CwaLink> Vue component after mount.

Usage

<!-- app/cwa/components/RichText/RichText.vue -->
<template>
    <div ref="container" class="prose" v-html="content" />
</template>

<script setup lang="ts">
import { computed, ref, toRef } from 'vue'
import type { IriProp } from '#cwa/composables/cwa-resource'
import { useCwaResource, useHtmlContent } from '#imports'

const props = defineProps<IriProp>()

const { getResource, exposeMeta } = useCwaResource(toRef(props, 'iri'))
const resource = getResource()

const content = computed(() => resource.value?.data?.content ?? '')

const container = ref<HTMLElement | null>(null)
useHtmlContent(container, content)

defineExpose(exposeMeta)
</script>

Pass container — a template ref pointing to the element that receives the v-html content — and content, the HTML source itself. useHtmlContent walks the container's DOM, finds <a> elements, and mounts <CwaLink> components in their place, re-running whenever either the element or the HTML changes.

Pass the second argument. It is optional for backwards compatibility, but with only the container ref the conversion tracks the element rather than the HTML — so content that changes while the same element stays mounted keeps its raw <a> tags, and those internal links then cause full page loads. This bites whenever a field can change in place: an inline editor, or a resource updated over Mercure.

What It Does

  • Finds every <a href="..."> inside the container
  • Creates a <CwaLink> Vue component instance for each
  • Mounts it as a replacement — internal paths get <NuxtLink> behaviour, external URLs open in a new tab
  • Unmounts the replacement link apps before re-converting, and again when the parent component unmounts

When to Use It

Use useHtmlContent for any component that renders HTML strings from the API into the page — rich-text editors, markdown output, or any field where the content author controls anchor tags. Without it, every internal link causes a hard navigation.