Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ Uses Vitest with two test projects:

## Package: @comark/angular

Located at `packages/comark-angular/`. Angular 17+ renderer with standalone components.
Located at `packages/comark-angular/`. Angular 21+ renderer (peer range `>=21 <23`, i.e. 21 through 22) with standalone components.

```
packages/comark-angular/
Expand All @@ -435,25 +435,41 @@ packages/comark-angular/
│ │ ├── if.component.ts # Structural conditional renderer
│ │ ├── math.component.ts # Math rendering component
│ │ └── mermaid.component.ts # Mermaid rendering component
│ ├── plugins/
│ │ ├── binding.ts # Re-exports binding plugin + Binding and If components
│ │ ├── math.ts # Re-exports comark/plugins/math + Math component
│ │ └── mermaid.ts # Re-exports comark/plugins/mermaid + Mermaid component
│ └── utils/
│ ├── caret.ts # Caret utilities for streaming
│ └── index.ts # Re-exports comark/utils
├── plugins/ # Secondary entry points (named exports)
│ ├── binding/
│ │ ├── index.ts # Re-exports binding plugin + Binding and If components
│ │ ├── binding.component.ts
│ │ └── if.component.ts
│ ├── math/
│ │ ├── index.ts # Re-exports math plugin + Math component
│ │ └── math.component.ts
│ └── mermaid/
│ ├── index.ts # Re-exports mermaid plugin + Mermaid component
│ └── mermaid.component.ts
├── scripts/
│ └── verify-build.mjs # Asserts partial-compilation metadata in dist after build
│ └── strip-sourcemaps.mjs # Removes ng-packagr source maps from dist after build
├── angular.json
├── ng-package.json
├── package.json
├── tsconfig.json
└── vitest.config.ts
```

### Build

Uses the Angular compiler (`ngc`) in partial-compilation mode so published
JavaScript and declarations contain the Angular metadata required by both JIT
and AOT consumers. `scripts/verify-build.mjs` runs after both `ngc` passes.
Built with `ng-packagr` via the Angular CLI (`@angular/build:ng-packagr`
builder): partial-compilation FESM bundles plus type declarations for the
main entry and each plugin secondary entry point. Plugin entry points use
named exports because the Angular Package Format strips `export default`
from entry points (e.g. `import { math, Math } from '@comark/angular/plugins/math'`).
`ng-packagr` always emits source maps, so `scripts/strip-sourcemaps.mjs` deletes
them after `ng build`. The package publishes from `dist/` via
`publishConfig.directory` (ng-packagr writes the published `package.json` there);
`.release-it.json` must not also set `publishPath`, or pnpm looks in `dist/dist`.
`test/bundle.test.ts` packs from that directory too.

### Exports

Expand All @@ -469,8 +485,8 @@ and AOT consumers. `scripts/verify-build.mjs` runs after both `ngc` passes.

```typescript
import { Markdown, MarkdownDocument, defineMarkdownComponent, defineMarkdownDocumentComponent } from '@comark/angular'
import math, { Math } from '@comark/angular/plugins/math'
import mermaid, { Mermaid } from '@comark/angular/plugins/mermaid'
import { math, Math } from '@comark/angular/plugins/math'
import { mermaid, Mermaid } from '@comark/angular/plugins/mermaid'
```

```html
Expand Down Expand Up @@ -592,9 +608,9 @@ import binding, { Binding, If } from '@comark/svelte/plugins/binding'

// Angular — renderer + plugin wrappers (plugin fn + Angular component)
import { Markdown, MarkdownDocument, defineMarkdownComponent, defineMarkdownDocumentComponent } from '@comark/angular'
import math, { Math } from '@comark/angular/plugins/math'
import mermaid, { Mermaid } from '@comark/angular/plugins/mermaid'
import binding, { Binding, If } from '@comark/angular/plugins/binding'
import { math, Math } from '@comark/angular/plugins/math'
import { mermaid, Mermaid } from '@comark/angular/plugins/mermaid'
import { binding, Binding, If } from '@comark/angular/plugins/binding'
```

## Coding Principles
Expand Down Expand Up @@ -877,7 +893,7 @@ export const DocsMarkdown = defineMarkdownComponent({

// Angular
import { defineMarkdownComponent } from '@comark/angular'
import math, { Math } from '@comark/angular/plugins/math'
import { math, Math } from '@comark/angular/plugins/math'

export const DocsMarkdown = defineMarkdownComponent({
plugins: [math()],
Expand Down
14 changes: 7 additions & 7 deletions docs/content/3.rendering/7.angular.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: 'Angular Markdown Component with Streaming (v17+)'
description: 'Render Markdown in Angular 17+ with standalone components, custom components, plugins, and streaming for AI output.'
title: 'Angular Markdown Component with Streaming (v21+)'
description: 'Render Markdown in Angular 21+ with standalone components, custom components, plugins, and streaming for AI output.'
navigation:
title: Angular
icon: i-simple-icons-angular
Expand All @@ -23,7 +23,7 @@ The `@comark/angular` package provides standalone components for rendering Comar

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

::callout{icon="i-lucide-info" color="info"}
Expand Down Expand Up @@ -135,8 +135,8 @@ For 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, { Math } from '@comark/angular/plugins/math'
import mermaid, { Mermaid } from '@comark/angular/plugins/mermaid'
import { math, Math } from '@comark/angular/plugins/math'
import { mermaid, Mermaid } from '@comark/angular/plugins/mermaid'

@Component({
selector: 'app-root',
Expand Down Expand Up @@ -552,8 +552,8 @@ Use `defineMarkdownComponent` and `defineMarkdownDocumentComponent` to create pr
```typescript [components/docs-markdown.ts]
import { defineMarkdownComponent } from '@comark/angular'
import shiki from '@comark/angular/plugins/shiki'
import math, { Math } from '@comark/angular/plugins/math'
import mermaid, { Mermaid } from '@comark/angular/plugins/mermaid'
import { math, Math } from '@comark/angular/plugins/math'
import { mermaid, Mermaid } from '@comark/angular/plugins/mermaid'

export const DocsMarkdown = defineMarkdownComponent({
plugins: [shiki(), math(), mermaid()],
Expand Down
14 changes: 7 additions & 7 deletions docs/skills/comark/references/rendering-angular.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Angular Rendering Guide

Complete guide for rendering Markdown documents in Angular 17+ applications.
Complete guide for rendering Markdown documents in Angular 21+ applications.

## Table of Contents

Expand Down Expand Up @@ -462,7 +462,7 @@ The `data` input allows passing ambient data for `:binding` resolution in markdo
```typescript
import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'
import binding, { Binding } from '@comark/angular/plugins/binding'
import { binding, Binding } from '@comark/angular/plugins/binding'

@Component({
selector: 'app-root',
Expand Down Expand Up @@ -500,8 +500,8 @@ Use `defineMarkdownComponent` or `defineMarkdownDocumentComponent` to create pre
```typescript
// docs-markdown.component.ts
import { defineMarkdownComponent } from '@comark/angular'
import math, { Math } from '@comark/angular/plugins/math'
import mermaid, { Mermaid } from '@comark/angular/plugins/mermaid'
import { math, Math } from '@comark/angular/plugins/math'
import { mermaid, Mermaid } from '@comark/angular/plugins/mermaid'

export const DocsMarkdown = defineMarkdownComponent({
plugins: [math(), mermaid()],
Expand Down Expand Up @@ -551,7 +551,7 @@ export const DocsMarkdownDocument = defineMarkdownDocumentComponent({
```typescript
import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'
import math, { Math } from '@comark/angular/plugins/math'
import { math, Math } from '@comark/angular/plugins/math'

@Component({
selector: 'app-root',
Expand All @@ -575,7 +575,7 @@ export class AppComponent {
```typescript
import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'
import mermaid, { Mermaid } from '@comark/angular/plugins/mermaid'
import { mermaid, Mermaid } from '@comark/angular/plugins/mermaid'

@Component({
selector: 'app-root',
Expand All @@ -597,7 +597,7 @@ The Mermaid component includes automatic dark mode support: it watches the `<htm
### Binding

```typescript
import binding, { Binding } from '@comark/angular/plugins/binding'
import { binding, Binding } from '@comark/angular/plugins/binding'

// See the "Data Binding" section above for full usage.
```
Expand Down
4 changes: 2 additions & 2 deletions packages/comark-angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Angular renderer for [Comark](https://comark.dev). Render markdown with custom s
- 🧩 `<comark-markdown>` component for one-shot markdown rendering
- 🎯 Map any Comark tag to a custom Angular component
- 🌊 Streaming-friendly with auto-close and caret support
- 🖥️ SSR-safe with Angular 17+ standalone components
- 🖥️ SSR-safe with Angular 21+ standalone components
- 🔌 Plugin ecosystem (math, mermaid, highlight, binding…)
- 🎯 Full TypeScript support

Expand All @@ -32,7 +32,7 @@ pnpm add @comark/angular
```typescript
import { Component } from '@angular/core'
import { Markdown } from '@comark/angular'
import math, { Math } from '@comark/angular/plugins/math'
import { math, Math } from '@comark/angular/plugins/math'

@Component({
selector: 'app-root',
Expand Down
42 changes: 42 additions & 0 deletions packages/comark-angular/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"cli": {
"packageManager": "pnpm",
"analytics": false
},
"newProjectRoot": "projects",
"projects": {
"comark-angular": {
"projectType": "library",
"root": "src",
"sourceRoot": "src",
"prefix": "comark",
"architect": {
"build": {
"builder": "@angular/build:ng-packagr",
"options": {
"project": "ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "tsconfig.lib.prod.json"
},
"development": {
"tsConfig": "tsconfig.lib.json"
}
},
"defaultConfiguration": "production"
},
"test": {
"builder": "@angular/build:unit-test",
"options": {
"tsConfig": "tsconfig.spec.json",
"runnerConfig": "vitest.config.ts",
"include": ["../test/**/*.d.ts", "../test/**/*.test.ts"]
}
}
}
}
}
}
8 changes: 8 additions & 0 deletions packages/comark-angular/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",
"dest": "./dist",
"lib": {
"entryFile": "src/index.ts"
},
"allowedNonPeerDependencies": ["comark"]
}
46 changes: 22 additions & 24 deletions packages/comark-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,44 @@
"type": "git",
"url": "git+https://github.com/comarkdown/comark.git"
},
"files": [
"dist"
],
"type": "module",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./plugins/*": "./dist/plugins/*.js",
"./utils": "./dist/utils/index.js"
},
"publishConfig": {
"access": "public"
"access": "public",
"directory": "dist"
},
"scripts": {
"stub": "node ../../scripts/stub.mjs",
"build": "ngc -p tsconfig.json && ngc -p tsconfig.json --removeComments true --declaration false && node scripts/verify-build.mjs",
"dev": "ngc -p tsconfig.json --watch",
"test": "vitest run",
"ng": "ng",
"build": "ng build && node scripts/strip-sourcemaps.mjs && node ../../scripts/sync-plugins.mjs",
"dev": "ng build --watch --configuration development",
"test": "ng test",
"prepack": "pnpm run build"
},
"dependencies": {
"comark": "workspace:*"
"comark": "workspace:*",
"tslib": "^2.3.0"
},
"devDependencies": {
"@angular/common": "^22.2.5",
"@angular-devkit/build-angular": "catalog:",
"@angular/cli": "catalog:",
"@angular/common": "catalog:",
"@angular/compiler": "catalog:",
"@angular/compiler-cli": "catalog:",
"@angular/core": "^22.2.5",
"@angular/platform-browser": "^22.2.5",
"@angular/core": "catalog:",
"@angular/platform-browser": "catalog:",
"@angular/platform-browser-dynamic": "catalog:",
"@angular/platform-server": "catalog:",
"@angular/router": "catalog:",
"happy-dom": "^20.14.5",
"ng-packagr": "catalog:",
"rxjs": "catalog:",
"typescript": "catalog:",
"vitest": "catalog:"
"vitest": "catalog:",
"zone.js": "catalog:"
},
"peerDependencies": {
"@angular/common": ">=17.0.0 <23.0.0",
"@angular/core": ">=17.0.0 <23.0.0",
"@angular/platform-browser": ">=17.0.0 <23.0.0",
"@angular/common": ">=21.0.0 <23.0.0",
"@angular/core": ">=21.0.0 <23.0.0",
"beautiful-mermaid": "catalog:",
"katex": "catalog:",
"shiki": "catalog:"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
Component,
Input,
ChangeDetectionStrategy,
ElementRef,
Renderer2,
OnChanges,
SimpleChanges,
inject,
input,
} from '@angular/core'

/**
Expand All @@ -25,12 +25,12 @@ export class Binding implements OnChanges {
* Resolved value for the binding, injected by the Comark renderer after
* looking up the `:value` dot-path against the ambient render context.
*/
@Input() value?: unknown
readonly value = input<unknown>()

/**
* Fallback rendered when `value` is `undefined` or `null`.
*/
@Input() defaultValue?: string
readonly defaultValue = input<string>()

private elementRef = inject(ElementRef)
private renderer = inject(Renderer2)
Expand All @@ -41,7 +41,8 @@ export class Binding implements OnChanges {
hostEl.removeChild(hostEl.firstChild)
}

const text = this.value !== undefined && this.value !== null ? String(this.value) : (this.defaultValue ?? '')
const text =
this.value() !== undefined && this.value() !== null ? String(this.value()) : (this.defaultValue() ?? '')

const textNode = this.renderer.createText(text)
this.renderer.appendChild(hostEl, textNode)
Expand Down
4 changes: 4 additions & 0 deletions packages/comark-angular/plugins/binding/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from 'comark/plugins/binding'
export { default as binding } from 'comark/plugins/binding'
export { Binding } from './binding.component'
export { If } from './if.component'
6 changes: 6 additions & 0 deletions packages/comark-angular/plugins/binding/ng-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "../../../node_modules/ng-packagr/ng-entrypoint.schema.json",
"lib": {
"entryFile": "index.ts"
}
}
3 changes: 3 additions & 0 deletions packages/comark-angular/plugins/math/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from 'comark/plugins/math'
export { default as math } from 'comark/plugins/math'
export { Math } from './math.component'
Loading
Loading