---
title: "Angular Markdown Component with Streaming (v21+)"
description: "Render Markdown in Angular 21+ with standalone components, custom components, plugins, and streaming for AI output."
canonical_url: "https://comark.dev/rendering/angular"
---
# Angular Markdown Component with Streaming (v21+)

> Render Markdown in Angular 21+ with standalone components, custom components, plugins, and streaming for AI output.

`@comark/angular` renders Markdown and Comark components in Angular using standalone components, with plugin support and streaming.

## Requirements

| Dependency     | Version            |
| -------------- | ------------------ |
| **Angular**    | `>=21.0.0 <23.0.0` |
| **TypeScript** | `>=5.5.0`          |

::callout{icon="i-lucide-info" color="info"}
`@comark/angular` works with the Angular CLI, Vite (via [`@analogjs/vite-plugin-angular`](https://analogjs.org)), Webpack, esbuild, or any other build tool that supports Angular.
::

## Installation

::code-group
```bash [pnpm]
pnpm add @comark/angular
```

```bash [npm]
npm install @comark/angular
```

```bash [yarn]
yarn add @comark/angular
```

```bash [bun]
bun add @comark/angular
```
::

## `<comark-markdown>`

`<comark-markdown>` parses and renders Markdown in one component. Its `value` input accepts a Markdown **string** or a pre-parsed [`MarkdownDocument`](https://comark.dev/getting-started/document-model).

~~~typescript [app.component.ts]
import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [Markdown],
  template: `<comark-markdown [value]="content" />`,
})
export class AppComponent {
  content = `# Hello World

This is **markdown** with Comark components.
`
}
~~~

::callout{icon="i-lucide-package" color="warning"}
Passing a document to `<comark-markdown>` skips parsing at runtime, but the **parser is still bundled** because `Markdown` imports it. To keep the client bundle free of the parser, use [`<comark-markdown-document>`](#comark-markdown-document) instead.
::

### Props (inputs)

| Input                             | Type                               | Default     | Description                                                                                                                                         |
| --------------------------------- | ---------------------------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `value`                           | `string \| MarkdownDocument`       | `''`        | Markdown string or pre-parsed document                                                                                                              |
| [`options`](#options)             | `ParserOptions`                    | `{}`        | Parser options (`autoUnwrap`, `autoClose`, and others)                                                                                              |
| [`plugins`](#plugins)             | `ComarkPlugin[]`                   | `[]`        | Array of plugins                                                                                                                                    |
| `unwrap`                          | `boolean \| string \| string[]`    | `false`     | Strip wrapper tags (MDC `unwrap`). `true` unwraps `<p>`; a comma- or space-separated string or array peels tags sequentially, for example `"ul li"` |
| [`components`](#components)       | `Record<string, Type<any>>`        | `{}`        | Custom Angular component mappings                                                                                                                   |
| [`streaming`](#streaming)         | `boolean`                          | `false`     | Enable streaming mode                                                                                                                               |
| `summary`                         | `boolean`                          | `false`     | Only render content before `<!-- more -->`                                                                                                          |
| [`effects`](#stream-effects)      | `readonly StreamEffect[]`          | `undefined` | Stream effects from `comark/effects`, such as `caret()`, `fade()` and `pace()`                                                                      |
| [`data`](#data)                   | `Record<string, unknown>`          | `{}`        | Runtime values referenced from Markdown via `:prop="data.path"`                                                                                     |
| [`transformNode`](#transformnode) | `NodeTransform \| NodeTransform[]` | `undefined` | Change the tag or props of element nodes right before they render                                                                                   |

#### `options`

See [ParserOptions](https://github.com/comarkdown/comark/blob/main/packages/comark/src/types.ts#L247) for available options.

```typescript [app.component.ts]
@Component({
  template: `<comark-markdown [value]="content" [options]="{ autoUnwrap: true, autoClose: true }" />`,
})
```

#### `plugins`

See [ComarkPlugin](https://comark.dev/plugins) for available plugins.

```typescript [app.component.ts]
import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'
import shiki from '@comark/plugin-shiki'
import githubLight from '@shikijs/themes/github-light'
import githubDark from '@shikijs/themes/github-dark'

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [Markdown],
  template: `<comark-markdown [value]="content" [plugins]="plugins" />`,
})
export class AppComponent {
  content = '```js\nconsole.log("hello")\n```'
  plugins = [
    shiki({
      themes: { light: githubLight, dark: githubDark },
    }),
  ]
}
```

For the `math` and `mermaid` plugins, also pass the companion components:

~~~typescript [app.component.ts]
import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'
import math from '@comark/plugin-katex'
import { Math } from '@comark/plugin-katex/angular'
import mermaid from '@comark/plugin-beautiful-mermaid'
import { Mermaid } from '@comark/plugin-beautiful-mermaid/angular'

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [Markdown],
  template: `
    <comark-markdown
      [value]="content"
      [plugins]="plugins"
      [components]="components"
    />
  `,
})
export class AppComponent {
  content = '$E = mc^2$'
  plugins = [math(), mermaid()]
  components = { Math, Mermaid }
}
~~~

#### `components`

Map custom Angular components to Comark elements in your Markdown.

::steps{level="4"}
#### Create a component

~~~typescript [components/alert.component.ts]
import { Component, Input } from '@angular/core'

@Component({
  selector: 'app-alert',
  standalone: true,
  template: `
    <div class="alert" [class]="'alert-' + type" role="alert">
      <ng-content />
    </div>
  `,
})
export class AlertComponent {
  @Input() type: 'info' | 'warning' | 'error' | 'success' = 'info'
}
~~~

#### Map the tag to your component

```typescript [app.component.ts]
import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'
import { AlertComponent } from './components/alert.component'
import { CardComponent } from './components/card.component'

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [Markdown],
  template: `<comark-markdown [value]="content" [components]="components" />`,
})
export class AppComponent {
  content = '...'
  components = { alert: AlertComponent, card: CardComponent }
}
```

#### Use it in your Markdown

```mdc
::alert{type="warning"}
This is a warning message!
::
```
::

::tip
See [Component bindings](#component-bindings) for how props map to your Angular component inputs, or [Component syntax](https://comark.dev/syntax/components) for nested components, inline syntax, and attributes.
::

#### `data`

Expose runtime values to Markdown authors. Any prop written with a `:` prefix resolves against the render context `{ frontmatter, meta, data, props }` when its value isn't valid JSON. See [Data binding](https://comark.dev/syntax/components#data-binding) for details.

```typescript [app.component.ts]
import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [Markdown],
  template: `<comark-markdown [value]="content" [data]="data" />`,
})
export class AppComponent {
  data = { user: { name: 'Ada', role: 'admin' } }
  content = `Hello, :badge{:label="data.user.name"}!`
}
```

#### `transformNode`

Change an element's tag or props right before it renders, using values that are only known at render time. The function receives the node's `tag`, its resolved `props`, and the render context. It returns a new `tag`, new `props`, or nothing to keep the node as it is. See [Transforming nodes before render](https://comark.dev/reference/reference#transforming-nodes-before-render) for the full rules.

```typescript [app.component.ts]
import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'
import type { NodeTransform } from '@comark/angular'

const user = { id: 42 }

const transformNode: NodeTransform = ({ tag, props }) => {
  if (tag !== 'cta') return
  return { tag: 'a', props: { ...props, href: `/users/${user.id}/dashboard` } }
}

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [Markdown],
  template: `<comark-markdown [value]="content" [transformNode]="transformNode" />`,
})
export class AppComponent {
  transformNode = transformNode
  content = `::cta\nOpen your dashboard\n::`
}
```

Comark renders what the function returns as-is, without sanitizing it, and the [security plugin](https://comark.dev/plugins/built-in/security) doesn't apply to it. Validate anything you build from untrusted data, such as URLs from `data`.

Keep the function on a field instead of creating it in the template, so change detection sees the same input. Angular can call it twice for a node that renders as a custom component, so keep it free of side effects.

---

## `<comark-markdown-document>`

Renders a pre-parsed `MarkdownDocument` without any parsing. Use it when you parse on the server, in a build step, or via an API, so no parser or plugin code is shipped to the browser.

### Parsing

Parse your Markdown content and pass the document directly:

~~~typescript [docs.component.ts]
import { Component, OnInit } from '@angular/core'
import { MarkdownDocument } from '@comark/angular'
import { parseMarkdown } from 'comark'
import type { MarkdownDocument as MarkdownDocumentType } from 'comark'

@Component({
  selector: 'app-docs',
  standalone: true,
  imports: [MarkdownDocument],
  template: `
    @if (document) {
      <comark-markdown-document [value]="document" [components]="components" />
    }
  `,
})
export class DocsComponent implements OnInit {
  document: MarkdownDocumentType | null = null
  components = {}

  async ngOnInit() {
    const markdown = await fetch('/api/content').then((r) => r.text())
    this.document = await parseMarkdown(markdown)
  }
}
~~~

### Renderer props (inputs)

| Input                             | Type                               | Default     | Description                                                                    |
| --------------------------------- | ---------------------------------- | ----------- | ------------------------------------------------------------------------------ |
| `value`                           | `MarkdownDocument`                 | `-`         | **Required.** The parsed document returned by `parseMarkdown()`                |
| [`components`](#components)       | `Record<string, Type<any>>`        | `{}`        | Custom Angular component mappings                                              |
| [`streaming`](#streaming)         | `boolean`                          | `false`     | Enable streaming mode                                                          |
| [`effects`](#stream-effects)      | `readonly StreamEffect[]`          | `undefined` | Stream effects from `comark/effects`, such as `caret()`, `fade()` and `pace()` |
| [`data`](#data)                   | `Record<string, unknown>`          | `{}`        | Runtime values referenced from Markdown via `:prop="data.path"`                |
| [`transformNode`](#transformnode) | `NodeTransform \| NodeTransform[]` | `undefined` | Change the tag or props of element nodes right before they render              |

---

## Component bindings

Comark maps component attributes and content in Markdown to Angular inputs and content projection.

### Prop binding

Attributes in Comark syntax are passed as `@Input()` values to your component. Use the `:` prefix to pass typed values:

| Markdown                    | Angular input value       |
| --------------------------- | ------------------------- |
| `{type="warning"}`          | `"warning"` (string)      |
| `{:count="5"}`              | `5` (number)              |
| `{:active="true"}`          | `true` (boolean)          |
| `{:config='{"key":"val"}'}` | `{ key: 'val' }` (object) |

### Content projection

Default content in Comark maps to Angular's content projection (`<ng-content />`):

::code-group
~~~typescript [Angular]
@Component({
  selector: 'app-card',
  standalone: true,
  template: `
    <div class="card">
      <h3>{{ title }}</h3>
      <div class="card-body">
        <ng-content />
      </div>
    </div>
  `,
})
export class CardComponent {
  @Input() title = ''
}
~~~

```mdc [Comark]
::card{title="My Card"}
Default content goes here.
::
```
::

---

## Overriding HTML elements

Use the `Prose` prefix to override how native HTML elements render:

::steps{level="3"}
### Create an override component

~~~typescript [components/prose-h1.component.ts]
import { Component, Input } from '@angular/core'

@Component({
  selector: 'prose-h1',
  standalone: true,
  template: `
    <h1 [id]="id" class="custom-heading">
      <ng-content />
    </h1>
  `,
})
export class ProseH1Component {
  @Input() id?: string
}
~~~

### Map it via the `components` input

```typescript [app.component.ts]
@Component({
  template: `<comark-markdown [value]="content" [components]="components" />`,
})
export class AppComponent {
  components = { ProseH1: ProseH1Component }
}
```
::

### Resolution order

Components are resolved in this order:

1. `Prose{PascalTag}`: for example, `ProseH1` for `h1`
2. `{PascalTag}`: for example, `Alert` for `alert`
3. `{tag}`: for example, `alert`

If no custom component matches, the tag renders as a native HTML element.

---

## Streaming

Render Markdown incrementally as chunks arrive from an AI stream or live preview.

Set `streaming` to `true` while content is being received, then `false` when done:

~~~typescript [components/ai-chat.component.ts]
import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'
import { caret } from 'comark/effects'

@Component({
  selector: 'app-ai-chat',
  standalone: true,
  imports: [Markdown],
  template: `
    <comark-markdown
      [value]="content"
      [streaming]="isStreaming"
      [effects]="effects"
    />
  `,
})
export class AiChatComponent {
  content = ''
  isStreaming = false
  effects = [caret()]

  async askAI(prompt: string) {
    this.content = ''
    this.isStreaming = true

    const response = await fetch('/api/chat', {
      method: 'POST',
      body: JSON.stringify({ prompt }),
    })

    const reader = response.body!.getReader()
    const decoder = new TextDecoder()

    while (true) {
      const { done, value } = await reader.read()
      if (done) break
      this.content += decoder.decode(value, { stream: true })
    }

    this.isStreaming = false
  }
}
~~~

::callout{icon="i-lucide-info" color="info"}
`autoClose` is enabled by default and closes incomplete syntax such as `**bold text` on every parse. Disable it with `[options]="{ autoClose: false }"`.
::

### Stream effects

Pass effects from `comark/effects` through the `effects` input. Effects run in array order, so put `pace()` first, then `fade()`, then `caret()`. Define the array once as a class field so effects keep their state between change detection runs.

```typescript [app.component.ts]
import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'
import { caret, fade } from 'comark/effects'

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [Markdown],
  template: `<comark-markdown [value]="content" [streaming]="isStreaming" [effects]="effects" />`,
})
export class AppComponent {
  content = ''
  isStreaming = false
  effects = [fade(), caret()]
}
```

See [Stream effects](https://comark.dev/reference/reference#stream-effects) for every option and for writing custom effects.

### Caret

`caret()` appends a blinking cursor to the last text node while `streaming` is `true`. Import it from `comark/effects` and pass it through `effects`:

::warning
The `caret` and `fade` inputs were removed. For example, `[caret]="true"` becomes `[effects]="effects"` with `effects = [caret()]`, and `[fade]="{ delay: 30 }"` becomes `effects = [fade({ delay: 30 })]`, with both imported from `comark/effects`.
::

```typescript
import { caret } from 'comark/effects'

// Pass a custom class to style the caret yourself
effects = [caret({ class: 'my-caret' })]
```

```html
<comark-markdown [value]="content" [streaming]="isStreaming" [effects]="effects" />
```

```css
.my-caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: currentColor;
  animation: blink 1s step-end infinite;
  vertical-align: text-bottom;
}

@keyframes blink {
  50% { opacity: 0; }
}
```

### Fade-in

`fade()` fades in new text as it streams. Import it from `comark/effects` and pass it through `effects`. Only characters that were not on screen yet fade, and code blocks, math, and diagrams appear without animation:

```typescript
import { fade } from 'comark/effects'

// Stagger words, slower animation
effects = [fade({ delay: 30, duration: 400 })]
```

```html
<comark-markdown [value]="content" [streaming]="isStreaming" [effects]="effects" />
```

Pass `class` to animate with your own CSS. See [Stream effects](https://comark.dev/reference/reference#stream-effects) for every option and for writing custom effects.

---

## TypeScript support

Use `ComarkPlugin` from `comark` to type plugin arrays, and `ElementNode` to type the `__node` input in components that override HTML elements:

```typescript [comark-wrapper.component.ts]
import { Component, Input, Type } from '@angular/core'
import { Markdown } from '@comark/angular'
import type { ComarkPlugin } from 'comark'

@Component({
  selector: 'app-comark-wrapper',
  standalone: true,
  imports: [Markdown],
  template: `<comark-markdown [value]="content" [components]="components" [plugins]="plugins" />`,
})
export class ComarkWrapperComponent {
  @Input() content = ''
  @Input() components: Record<string, Type<any>> = {}
  @Input() plugins: ComarkPlugin[] = []
}
```

~~~typescript [components/heading.component.ts]
import { Component, Input } from '@angular/core'
import type { ElementNode } from 'comark'

@Component({
  selector: 'app-heading',
  standalone: true,
  template: `
    <h2 [id]="id" class="heading">
      <ng-content />
    </h2>
  `,
})
export class HeadingComponent {
  @Input() __node?: ElementNode
  @Input() id?: string
}
~~~

---

## Pre-configured components

Use `defineMarkdownComponent` and `defineMarkdownDocumentComponent` to create pre-configured wrappers with default plugins, components, and styling.

### `defineMarkdownComponent`

```typescript [components/docs-markdown.ts]
import { defineMarkdownComponent } from '@comark/angular'
import shiki from '@comark/plugin-shiki'
import math from '@comark/plugin-katex'
import { Math } from '@comark/plugin-katex/angular'
import mermaid from '@comark/plugin-beautiful-mermaid'
import { Mermaid } from '@comark/plugin-beautiful-mermaid/angular'

export const DocsMarkdown = defineMarkdownComponent({
  plugins: [shiki(), math(), mermaid()],
  components: { Math, Mermaid },
  class: 'prose dark:prose-invert',
})
```

Then use it like any other component. The returned component always uses the `comark-markdown-defined` selector:

```typescript [page.component.ts]
import { Component } from '@angular/core'
import { DocsMarkdown } from './components/docs-markdown'

@Component({
  selector: 'app-page',
  standalone: true,
  imports: [DocsMarkdown],
  template: `<comark-markdown-defined [value]="content" />`,
})
export class PageComponent {
  content = '# Hello\n\n$E = mc^2$'
}
```

Instance-level `[plugins]` and `[components]` inputs are merged with (and override) the config-level defaults. Both `defineMarkdownComponent` and `defineMarkdownDocumentComponent` also accept `transformNode`, which runs before the instance's `[transformNode]` input.

### `defineMarkdownDocumentComponent`

Creates a pre-configured `<comark-markdown-document>` component. The returned component always uses the `comark-markdown-document-defined` selector:

```typescript [components/docs-markdown-document.ts]
import { defineMarkdownDocumentComponent } from '@comark/angular'
import { Math } from '@comark/plugin-katex/angular'

export const DocsMarkdownDocument = defineMarkdownDocumentComponent({
  components: { Math },
  class: 'prose',
})
```

### `provideMarkdown` and `provideMarkdownDocument` (AOT-safe)

Angular AOT cannot statically resolve a component class returned by a factory in `imports` (NG1010 / ngtsc error -991010). For AOT builds, keep the static components in `imports` and register the config providers once at bootstrap. Every Markdown component in the app then uses that config.

```typescript [main.ts]
import { bootstrapApplication } from '@angular/platform-browser'
import { AppComponent } from './app.component'
import { provideMarkdown, provideMarkdownDocument } from '@comark/angular'
import shiki from '@comark/plugin-shiki'
import math from '@comark/plugin-katex'
import { Math } from '@comark/plugin-katex/angular'
import mermaid from '@comark/plugin-beautiful-mermaid'
import { Mermaid } from '@comark/plugin-beautiful-mermaid/angular'

bootstrapApplication(AppComponent, {
  providers: [
    provideMarkdown({
      plugins: [shiki(), math(), mermaid()],
      components: { Math, Mermaid },
      class: 'prose dark:prose-invert',
    }),
    provideMarkdownDocument({
      components: { Math },
      class: 'prose',
    }),
  ],
})
```

Components only import the static component. No provider or wrapper is needed in each component:

```typescript [page.component.ts]
import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'

@Component({
  selector: 'app-page',
  standalone: true,
  imports: [Markdown],
  template: `<comark-markdown [value]="content" />`,
})
export class PageComponent {
  content = '# Hello\n\n$E = mc^2$'
}
```

The same applies to `<comark-markdown-document>`: import `MarkdownDocument` and it picks up `provideMarkdownDocument` from the root injector. Use a signal for an asynchronously parsed document so zoneless change detection sees the update:

```typescript [page.component.ts]
import { Component, OnInit, signal } from '@angular/core'
import { parseMarkdown, type MarkdownDocument as MarkdownDocumentType } from 'comark'
import { MarkdownDocument } from '@comark/angular'

@Component({
  selector: 'app-page',
  standalone: true,
  imports: [MarkdownDocument],
  template: `@if (document(); as document) { <comark-markdown-document [value]="document" /> }`,
})
export class PageComponent implements OnInit {
  readonly document = signal<MarkdownDocumentType | undefined>(undefined)

  async ngOnInit(): Promise<void> {
    this.document.set(await parseMarkdown('# Hello'))
  }
}
```

`provideMarkdown` and `provideMarkdownDocument` return config `Provider` objects for `MARKDOWN_CONFIG` and `MARKDOWN_DOCUMENT_CONFIG`. Both tokens and their config interfaces are exported. Providers can also be scoped to a route or an ancestor component; the closest injector wins. Instance-level `[options]`, `[plugins]`, `[components]`, and `[transformNode]` inputs merge with the global config and win on conflict. Config plugins run before instance plugins; a same-name instance plugin replaces the config plugin. Config `transformNode` runs before the instance's own transform. The `defineMarkdown*` factories above still return component classes for JIT apps that disable AOT and import `@angular/compiler`.

---

---

- [Plugins](https://comark.dev/plugins)
- [Streaming API](https://comark.dev/reference/auto-close)


## Sitemap

See the full [sitemap](https://comark.dev/sitemap.md) for all pages.
