@memberjunction/ng-markdown 0.0.1 → 2.126.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,45 +1,213 @@
1
1
  # @memberjunction/ng-markdown
2
2
 
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
4
-
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
6
-
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
8
-
9
- ## Purpose
10
-
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@memberjunction/ng-markdown`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
15
-
16
- ## What is OIDC Trusted Publishing?
17
-
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
19
-
20
- ## Setup Instructions
21
-
22
- To properly configure OIDC trusted publishing for this package:
23
-
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
-
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**
3
+ A lightweight Angular module for rendering markdown content with rich features including syntax highlighting, Mermaid diagrams, collapsible sections, and more.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @memberjunction/ng-markdown
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Basic Setup
14
+
15
+ Import the `MarkdownModule` in your Angular module:
16
+
17
+ ```typescript
18
+ import { NgModule } from '@angular/core';
19
+ import { MarkdownModule } from '@memberjunction/ng-markdown';
20
+
21
+ @NgModule({
22
+ imports: [
23
+ MarkdownModule
24
+ ]
25
+ })
26
+ export class YourModule { }
27
+ ```
28
+
29
+ > **Note**: This module does NOT use `forRoot()`. Simply import `MarkdownModule` in any module where you need markdown rendering. The `MarkdownService` is provided at root level for efficient sharing across the application.
30
+
31
+ ### Basic Usage
32
+
33
+ ```html
34
+ <mj-markdown [data]="markdownContent"></mj-markdown>
35
+ ```
36
+
37
+ ### Advanced Usage
38
+
39
+ ```html
40
+ <mj-markdown
41
+ [data]="content"
42
+ [enableMermaid]="true"
43
+ [enableCollapsibleHeadings]="true"
44
+ [collapsibleHeadingLevel]="2"
45
+ [autoExpandLevels]="[2]"
46
+ [enableCodeCopy]="true"
47
+ [enableAlerts]="true"
48
+ [enableSmartypants]="true"
49
+ [enableSvgRenderer]="true"
50
+ [enableHtml]="false"
51
+ (rendered)="onRendered($event)"
52
+ (headingClick)="onHeadingClick($event)"
53
+ (codeCopied)="onCodeCopied($event)">
54
+ </mj-markdown>
55
+ ```
56
+
57
+ ## Features
58
+
59
+ ### Syntax Highlighting (Prism.js)
60
+ Code blocks are automatically highlighted using Prism.js with the Okaidia theme.
61
+
62
+ ### Mermaid Diagrams
63
+ Support for Mermaid diagram rendering:
64
+
65
+ ~~~markdown
66
+ ```mermaid
67
+ graph TD
68
+ A[Start] --> B[Process]
69
+ B --> C[End]
70
+ ```
71
+ ~~~
72
+
73
+ ### Collapsible Headings
74
+ Enable collapsible sections with expand/collapse all buttons:
75
+
76
+ ```html
77
+ <mj-markdown
78
+ [data]="content"
79
+ [enableCollapsibleHeadings]="true"
80
+ [collapsibleHeadingLevel]="2"
81
+ [autoExpandLevels]="[2]">
82
+ </mj-markdown>
83
+ ```
84
+
85
+ - `collapsibleHeadingLevel`: Heading level to start collapsing (1-6)
86
+ - `autoExpandLevels`: Array of heading levels to expand by default (e.g., `[2]` expands only h2)
87
+ - `collapsibleDefaultExpanded`: Whether sections are expanded by default (true/false)
88
+
89
+ ### Copy-to-Clipboard
90
+ Code blocks include a copy button that appears on hover.
91
+
92
+ ### GitHub-Style Alerts
93
+ Support for GitHub-style blockquote alerts:
94
+
95
+ ```markdown
96
+ > [!NOTE]
97
+ > Useful information that users should know.
98
+
99
+ > [!TIP]
100
+ > Helpful advice for doing things better.
101
+
102
+ > [!WARNING]
103
+ > Urgent info that needs immediate attention.
104
+ ```
105
+
106
+ ### Smartypants Typography
107
+ Automatically converts:
108
+ - "quotes" to "curly quotes"
109
+ - `--` to en-dash (–)
110
+ - `---` to em-dash (—)
111
+ - `...` to ellipsis (…)
112
+
113
+ ### SVG Code Block Rendering
114
+ Render SVG code blocks as actual images:
115
+
116
+ ~~~markdown
117
+ ```svg
118
+ <svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
119
+ <circle cx="50" cy="50" r="40" fill="blue"/>
120
+ </svg>
121
+ ```
122
+ ~~~
123
+
124
+ ### HTML Passthrough
125
+ Enable raw HTML rendering for mockups and custom layouts:
126
+
127
+ ```html
128
+ <mj-markdown
129
+ [data]="content"
130
+ [enableHtml]="true"
131
+ [enableJavaScript]="false">
132
+ </mj-markdown>
133
+ ```
134
+
135
+ > **Security Note**: When `enableHtml` is true, JavaScript is still stripped unless `enableJavaScript` is also true. Only enable `enableJavaScript` for fully trusted content.
136
+
137
+ ## Configuration Options
138
+
139
+ | Input | Type | Default | Description |
140
+ |-------|------|---------|-------------|
141
+ | `data` | `string` | `''` | Markdown content to render |
142
+ | `enableHighlight` | `boolean` | `true` | Enable Prism.js syntax highlighting |
143
+ | `enableMermaid` | `boolean` | `true` | Enable Mermaid diagram rendering |
144
+ | `enableCodeCopy` | `boolean` | `true` | Enable copy button on code blocks |
145
+ | `enableCollapsibleHeadings` | `boolean` | `false` | Enable collapsible heading sections |
146
+ | `collapsibleHeadingLevel` | `1-6` | `2` | Heading level to start collapsing |
147
+ | `collapsibleDefaultExpanded` | `boolean` | `true` | Default expansion state |
148
+ | `autoExpandLevels` | `number[]` | `undefined` | Specific levels to auto-expand |
149
+ | `enableAlerts` | `boolean` | `true` | Enable GitHub-style alerts |
150
+ | `enableSmartypants` | `boolean` | `true` | Enable typography improvements |
151
+ | `enableSvgRenderer` | `boolean` | `true` | Enable SVG code block rendering |
152
+ | `enableHtml` | `boolean` | `false` | Enable raw HTML passthrough |
153
+ | `enableJavaScript` | `boolean` | `false` | Allow JavaScript in HTML (security risk) |
154
+ | `enableHeadingIds` | `boolean` | `true` | Generate heading IDs for anchors |
155
+ | `headingIdPrefix` | `string` | `''` | Prefix for heading IDs |
156
+ | `enableLineNumbers` | `boolean` | `false` | Show line numbers in code blocks |
157
+ | `containerClass` | `string` | `''` | Custom CSS class for container |
158
+ | `mermaidTheme` | `string` | `'default'` | Mermaid theme (default/dark/forest/neutral/base) |
159
+ | `sanitize` | `boolean` | `true` | Sanitize HTML output |
160
+
161
+ ## Events
162
+
163
+ | Output | Type | Description |
164
+ |--------|------|-------------|
165
+ | `rendered` | `MarkdownRenderEvent` | Emitted when rendering is complete |
166
+ | `headingClick` | `HeadingInfo` | Emitted when a heading is clicked |
167
+ | `codeCopied` | `string` | Emitted when code is copied to clipboard |
168
+
169
+ ## Migration from ngx-markdown
170
+
171
+ If you're migrating from `ngx-markdown`:
172
+
173
+ 1. Replace imports:
174
+ ```typescript
175
+ // Before
176
+ import { MarkdownModule } from 'ngx-markdown';
177
+
178
+ // After
179
+ import { MarkdownModule } from '@memberjunction/ng-markdown';
180
+ ```
181
+
182
+ 2. Update module imports (no `forRoot()` needed):
183
+ ```typescript
184
+ // Before
185
+ MarkdownModule.forRoot()
186
+
187
+ // After
188
+ MarkdownModule
189
+ ```
190
+
191
+ 3. Update template selectors:
192
+ ```html
193
+ <!-- Before -->
194
+ <markdown [data]="content"></markdown>
195
+
196
+ <!-- After -->
197
+ <mj-markdown [data]="content"></mj-markdown>
198
+ ```
199
+
200
+ 4. The `MarkdownComponent` still exposes an `element` property for backward compatibility with code that accessed `element.nativeElement`.
201
+
202
+ ## Dependencies
203
+
204
+ - `marked` - Markdown parser
205
+ - `marked-alert` - GitHub-style alerts
206
+ - `marked-highlight` - Syntax highlighting integration
207
+ - `marked-smartypants` - Typography improvements
208
+ - `prismjs` - Syntax highlighting
209
+ - `mermaid` - Diagram rendering
210
+
211
+ ## License
212
+
213
+ ISC
@@ -0,0 +1,210 @@
1
+ import { EventEmitter, ElementRef, OnChanges, OnDestroy, SimpleChanges, ChangeDetectorRef, AfterViewInit } from '@angular/core';
2
+ import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
3
+ import { MarkdownService } from '../services/markdown.service';
4
+ import { MarkdownRenderEvent, HeadingInfo } from '../types/markdown.types';
5
+ import * as i0 from "@angular/core";
6
+ /**
7
+ * Angular component for rendering markdown content.
8
+ *
9
+ * Features:
10
+ * - Prism.js syntax highlighting for code blocks
11
+ * - Mermaid diagram rendering
12
+ * - Copy-to-clipboard for code blocks
13
+ * - Collapsible heading sections
14
+ * - GitHub-style alerts and heading IDs
15
+ *
16
+ * Usage:
17
+ * ```html
18
+ * <mj-markdown [data]="markdownContent"></mj-markdown>
19
+ *
20
+ * <mj-markdown
21
+ * [data]="content"
22
+ * [enableMermaid]="true"
23
+ * [enableCollapsibleHeadings]="true"
24
+ * (rendered)="onRendered($event)">
25
+ * </mj-markdown>
26
+ * ```
27
+ */
28
+ export declare class MarkdownComponent implements OnChanges, AfterViewInit, OnDestroy {
29
+ private elementRef;
30
+ private sanitizer;
31
+ private markdownService;
32
+ private cdr;
33
+ /**
34
+ * The markdown content to render
35
+ */
36
+ data: string;
37
+ /**
38
+ * Enable syntax highlighting
39
+ */
40
+ enableHighlight: boolean;
41
+ /**
42
+ * Enable Mermaid diagram rendering
43
+ */
44
+ enableMermaid: boolean;
45
+ /**
46
+ * Enable copy button on code blocks
47
+ */
48
+ enableCodeCopy: boolean;
49
+ /**
50
+ * Enable collapsible heading sections
51
+ */
52
+ enableCollapsibleHeadings: boolean;
53
+ /**
54
+ * Heading level at which to start collapsing
55
+ */
56
+ collapsibleHeadingLevel: 1 | 2 | 3 | 4 | 5 | 6;
57
+ /**
58
+ * Whether collapsible sections should be expanded by default
59
+ */
60
+ collapsibleDefaultExpanded: boolean;
61
+ /**
62
+ * Specify which heading levels should start expanded.
63
+ * Array of heading levels (2-6) that should be expanded by default.
64
+ * Takes precedence over collapsibleDefaultExpanded for specified levels.
65
+ *
66
+ * Examples:
67
+ * - [2] = Only h2 expanded, h3-h6 collapsed
68
+ * - [2, 3] = h2 and h3 expanded, h4-h6 collapsed
69
+ * - [] = All collapsed
70
+ * - undefined = Uses collapsibleDefaultExpanded for all levels
71
+ */
72
+ autoExpandLevels?: number[];
73
+ /**
74
+ * Enable GitHub-style alerts
75
+ */
76
+ enableAlerts: boolean;
77
+ /**
78
+ * Enable smartypants for typography (curly quotes, em/en dashes, ellipses)
79
+ */
80
+ enableSmartypants: boolean;
81
+ /**
82
+ * Enable SVG code block rendering
83
+ * When enabled, ```svg code blocks are rendered as actual SVG images
84
+ */
85
+ enableSvgRenderer: boolean;
86
+ /**
87
+ * Enable raw HTML passthrough in markdown content.
88
+ * Scripts and event handlers are still stripped unless enableJavaScript is true.
89
+ */
90
+ enableHtml: boolean;
91
+ /**
92
+ * Enable JavaScript in HTML content (<script> tags and on* handlers).
93
+ * WARNING: Major security risk - only enable for fully trusted content.
94
+ */
95
+ enableJavaScript: boolean;
96
+ /**
97
+ * Enable heading IDs for anchor links
98
+ */
99
+ enableHeadingIds: boolean;
100
+ /**
101
+ * Prefix for heading IDs
102
+ */
103
+ headingIdPrefix: string;
104
+ /**
105
+ * Enable line numbers in code blocks
106
+ */
107
+ enableLineNumbers: boolean;
108
+ /**
109
+ * Custom CSS class for the container
110
+ */
111
+ containerClass: string;
112
+ /**
113
+ * Mermaid theme
114
+ */
115
+ mermaidTheme: 'default' | 'dark' | 'forest' | 'neutral' | 'base';
116
+ /**
117
+ * Whether to sanitize HTML output
118
+ */
119
+ sanitize: boolean;
120
+ /**
121
+ * Emitted when rendering is complete
122
+ */
123
+ rendered: EventEmitter<MarkdownRenderEvent>;
124
+ /**
125
+ * Emitted when a heading anchor is clicked
126
+ */
127
+ headingClick: EventEmitter<HeadingInfo>;
128
+ /**
129
+ * Emitted when code is copied to clipboard
130
+ */
131
+ codeCopied: EventEmitter<string>;
132
+ /**
133
+ * The sanitized HTML content to display
134
+ */
135
+ renderedContent: SafeHtml;
136
+ /**
137
+ * Public accessor for the component's element reference.
138
+ * Provided for backward compatibility with ngx-markdown API.
139
+ */
140
+ get element(): ElementRef<HTMLElement>;
141
+ private renderStartTime;
142
+ private hasMermaid;
143
+ private hasCodeBlocks;
144
+ constructor(elementRef: ElementRef<HTMLElement>, sanitizer: DomSanitizer, markdownService: MarkdownService, cdr: ChangeDetectorRef);
145
+ ngOnChanges(changes: SimpleChanges): void;
146
+ ngAfterViewInit(): void;
147
+ ngOnDestroy(): void;
148
+ /**
149
+ * Render the markdown content
150
+ */
151
+ private render;
152
+ /**
153
+ * Process rendered content after DOM update
154
+ * Handles syntax highlighting, mermaid rendering, copy buttons, etc.
155
+ */
156
+ private postRenderProcessing;
157
+ /**
158
+ * Setup collapsible sections by adding toggle buttons and click listeners
159
+ */
160
+ private setupCollapsibleListeners;
161
+ /**
162
+ * Create the expand/collapse all action buttons for sections with children
163
+ */
164
+ private createActionButtons;
165
+ /**
166
+ * Toggle a collapsible section
167
+ * @param section The section element to toggle
168
+ * @param toggle The toggle button element
169
+ */
170
+ private toggleSection;
171
+ /**
172
+ * Collapse all descendant sections (used by action button)
173
+ */
174
+ private collapseDescendants;
175
+ /**
176
+ * Expand all descendant sections (used by action button)
177
+ */
178
+ private expandDescendants;
179
+ /**
180
+ * Setup click listeners for heading anchors
181
+ */
182
+ private setupHeadingClickListeners;
183
+ /**
184
+ * Setup listeners to emit code copy events
185
+ */
186
+ private setupCodeCopyListeners;
187
+ /**
188
+ * Cleanup event listeners
189
+ */
190
+ private cleanupEventListeners;
191
+ /**
192
+ * Force a re-render of the markdown content
193
+ */
194
+ refresh(): void;
195
+ /**
196
+ * Get the current heading list (for TOC building)
197
+ */
198
+ getHeadings(): HeadingInfo[];
199
+ /**
200
+ * Scroll to a heading by ID
201
+ */
202
+ scrollToHeading(headingId: string): void;
203
+ /**
204
+ * Strip JavaScript from HTML content while preserving layout HTML.
205
+ * Removes <script> tags, on* event handlers, and javascript: URLs.
206
+ */
207
+ private stripJavaScript;
208
+ static ɵfac: i0.ɵɵFactoryDeclaration<MarkdownComponent, never>;
209
+ static ɵcmp: i0.ɵɵComponentDeclaration<MarkdownComponent, "mj-markdown", never, { "data": { "alias": "data"; "required": false; }; "enableHighlight": { "alias": "enableHighlight"; "required": false; }; "enableMermaid": { "alias": "enableMermaid"; "required": false; }; "enableCodeCopy": { "alias": "enableCodeCopy"; "required": false; }; "enableCollapsibleHeadings": { "alias": "enableCollapsibleHeadings"; "required": false; }; "collapsibleHeadingLevel": { "alias": "collapsibleHeadingLevel"; "required": false; }; "collapsibleDefaultExpanded": { "alias": "collapsibleDefaultExpanded"; "required": false; }; "autoExpandLevels": { "alias": "autoExpandLevels"; "required": false; }; "enableAlerts": { "alias": "enableAlerts"; "required": false; }; "enableSmartypants": { "alias": "enableSmartypants"; "required": false; }; "enableSvgRenderer": { "alias": "enableSvgRenderer"; "required": false; }; "enableHtml": { "alias": "enableHtml"; "required": false; }; "enableJavaScript": { "alias": "enableJavaScript"; "required": false; }; "enableHeadingIds": { "alias": "enableHeadingIds"; "required": false; }; "headingIdPrefix": { "alias": "headingIdPrefix"; "required": false; }; "enableLineNumbers": { "alias": "enableLineNumbers"; "required": false; }; "containerClass": { "alias": "containerClass"; "required": false; }; "mermaidTheme": { "alias": "mermaidTheme"; "required": false; }; "sanitize": { "alias": "sanitize"; "required": false; }; }, { "rendered": "rendered"; "headingClick": "headingClick"; "codeCopied": "codeCopied"; }, never, never, false, never>;
210
+ }