wampert
v0.0.1
Published
Angular Markdown rendering library with unified pipeline, syntax highlighting via shiki, and GFM support
Downloads
107
Maintainers
Readme
@anthropic/wampert
A powerful Angular library for rendering Markdown with syntax highlighting, GFM support, and full customization.
Features
- Syntax Highlighting: Beautiful code highlighting powered by Shiki with support for 100+ languages
- GFM Support: Full GitHub Flavored Markdown including tables, task lists, strikethrough, and autolinks
- Extensible: Add custom remark and rehype plugins
- Configurable: Theme and behavior customization via dependency injection
- SSR Compatible: Works with Angular Server-Side Rendering
Installation
npm install @anthropic/wampertPeer Dependencies
Make sure you have the following peer dependencies installed:
npm install @angular/common @angular/core @angular/platform-browserSetup
Add the provideMarkdown() provider to your application configuration:
import { ApplicationConfig } from '@angular/core';
import { provideMarkdown } from '@anthropic/wampert';
export const appConfig: ApplicationConfig = {
providers: [
provideMarkdown({
prettyCodeTheme: {
dark: 'github-dark',
light: 'github-light',
},
keepBackground: false,
}),
],
};Usage
Import the MarkdownComponent and use it in your templates:
import { Component } from '@angular/core';
import { MarkdownComponent } from '@anthropic/wampert';
@Component({
selector: 'app-example',
standalone: true,
imports: [MarkdownComponent],
template: `
<wampert-markdown [content]="markdownContent"></wampert-markdown>
`,
})
export class ExampleComponent {
markdownContent = `
# Hello World
This is **bold** and this is *italic*.
\`\`\`typescript
function greet(name: string): string {
return \`Hello, \${name}!\`;
}
\`\`\`
`;
}Configuration
provideMarkdown()
The main configuration function accepts the following options:
interface MarkdownConfig {
remarkPlugins?: RemarkPlugin[];
rehypePlugins?: RehypePlugin[];
prettyCodeTheme?: {
dark: string;
light: string;
};
keepBackground?: boolean;
}Custom Plugins
You can add custom remark and rehype plugins:
import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';
provideMarkdown({
remarkPlugins: [
{ plugin: remarkMath }
],
rehypePlugins: [
{ plugin: rehypeKatex, options: { strict: false } }
],
})Multi-Provider Support
For modular configuration, you can use the helper functions:
import {
provideRemarkPlugins,
provideRehypePlugins,
providePrettyCodeTheme
} from '@anthropic/wampert';
export const appConfig: ApplicationConfig = {
providers: [
provideRemarkPlugins([{ plugin: remarkMath }]),
provideRehypePlugins([{ plugin: rehypeKatex }]),
providePrettyCodeTheme('one-dark-pro', 'github-light'),
],
};Injection Tokens
For advanced use cases, you can inject tokens directly:
REMARK_PLUGINS- Multi-provider token for remark pluginsREHYPE_PLUGINS- Multi-provider token for rehype pluginsPRETTY_CODE_THEME- Theme configuration for rehype-pretty-codeKEEP_BACKGROUND- Boolean to control background preservation
Pipeline
The library uses the unified ecosystem with the following pipeline:
remark-parse- Parse markdown- Custom remark plugins (if provided)
remark-gfm- GitHub Flavored Markdownremark-rehype- Convert to HTML ASTrehype-slug- Add IDs to headings- Custom rehype plugins (if provided)
rehype-pretty-code- Syntax highlighting with Shikirehype-stringify- Convert to HTML string
Shiki Themes
The library uses Shiki for syntax highlighting. You can use any built-in Shiki theme:
github-dark/github-lightone-dark-prodraculanordvitesse-dark/vitesse-light- And many more...
See the Shiki themes documentation for a full list.
Dark Mode Support
The component renders both light and dark themes and uses CSS to show the appropriate one:
/* Default to light mode */
pre[data-theme='dark'],
code[data-theme='dark'] {
display: none;
}
@media (prefers-color-scheme: dark) {
pre[data-theme='light'],
code[data-theme='light'] {
display: none;
}
pre[data-theme='dark'],
code[data-theme='dark'] {
display: block;
}
}License
MIT
