@memberjunction/ng-markdown 4.0.0 → 4.1.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 +73 -142
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @memberjunction/ng-markdown
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A feature-rich Angular component for rendering Markdown content with syntax highlighting, Mermaid diagrams, collapsible sections, GitHub-style alerts, and SVG rendering.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,33 +8,55 @@ A lightweight Angular module for rendering markdown content with rich features i
|
|
|
8
8
|
npm install @memberjunction/ng-markdown
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
The Markdown component replaces `ngx-markdown` with a MemberJunction-native implementation. It uses [marked](https://marked.js.org/) for parsing, [Prism.js](https://prismjs.com/) for syntax highlighting, and [Mermaid](https://mermaid.js.org/) for diagram rendering. The module does not use `forRoot()` -- simply import `MarkdownModule` wherever needed.
|
|
14
|
+
|
|
15
|
+
```mermaid
|
|
16
|
+
flowchart LR
|
|
17
|
+
subgraph Input["Markdown Source"]
|
|
18
|
+
A["Raw Markdown String"]
|
|
19
|
+
end
|
|
20
|
+
subgraph Parser["Parsing Pipeline"]
|
|
21
|
+
B["marked parser"]
|
|
22
|
+
B --> C["marked-highlight (Prism.js)"]
|
|
23
|
+
B --> D["marked-alert (GitHub alerts)"]
|
|
24
|
+
B --> E["marked-smartypants (typography)"]
|
|
25
|
+
end
|
|
26
|
+
subgraph Render["Rendering"]
|
|
27
|
+
C --> F["Syntax-highlighted code blocks"]
|
|
28
|
+
D --> G["Alert blockquotes"]
|
|
29
|
+
B --> H["Mermaid diagrams"]
|
|
30
|
+
B --> I["SVG code blocks"]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
A --> B
|
|
34
|
+
|
|
35
|
+
style Input fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
36
|
+
style Parser fill:#7c5295,stroke:#563a6b,color:#fff
|
|
37
|
+
style Render fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
38
|
+
```
|
|
12
39
|
|
|
13
|
-
|
|
40
|
+
## Usage
|
|
14
41
|
|
|
15
|
-
|
|
42
|
+
### Module Import
|
|
16
43
|
|
|
17
44
|
```typescript
|
|
18
|
-
import { NgModule } from '@angular/core';
|
|
19
45
|
import { MarkdownModule } from '@memberjunction/ng-markdown';
|
|
20
46
|
|
|
21
47
|
@NgModule({
|
|
22
|
-
imports: [
|
|
23
|
-
MarkdownModule
|
|
24
|
-
]
|
|
48
|
+
imports: [MarkdownModule] // No forRoot() needed
|
|
25
49
|
})
|
|
26
|
-
export class YourModule {
|
|
50
|
+
export class YourModule {}
|
|
27
51
|
```
|
|
28
52
|
|
|
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
53
|
### Basic Usage
|
|
32
54
|
|
|
33
55
|
```html
|
|
34
56
|
<mj-markdown [data]="markdownContent"></mj-markdown>
|
|
35
57
|
```
|
|
36
58
|
|
|
37
|
-
###
|
|
59
|
+
### Full Configuration
|
|
38
60
|
|
|
39
61
|
```html
|
|
40
62
|
<mj-markdown
|
|
@@ -48,109 +70,44 @@ export class YourModule { }
|
|
|
48
70
|
[enableSmartypants]="true"
|
|
49
71
|
[enableSvgRenderer]="true"
|
|
50
72
|
[enableHtml]="false"
|
|
73
|
+
[mermaidTheme]="'default'"
|
|
51
74
|
(rendered)="onRendered($event)"
|
|
52
75
|
(headingClick)="onHeadingClick($event)"
|
|
53
76
|
(codeCopied)="onCodeCopied($event)">
|
|
54
77
|
</mj-markdown>
|
|
55
78
|
```
|
|
56
79
|
|
|
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)
|
|
80
|
+
## Key Features
|
|
88
81
|
|
|
89
|
-
|
|
90
|
-
|
|
82
|
+
| Feature | Default | Description |
|
|
83
|
+
|---------|---------|-------------|
|
|
84
|
+
| Syntax highlighting | Enabled | Prism.js with Okaidia theme |
|
|
85
|
+
| Mermaid diagrams | Enabled | Render mermaid code blocks as diagrams |
|
|
86
|
+
| Code copy button | Enabled | Copy-to-clipboard on hover |
|
|
87
|
+
| GitHub-style alerts | Enabled | `[!NOTE]`, `[!TIP]`, `[!WARNING]` blockquotes |
|
|
88
|
+
| Smartypants typography | Enabled | Curly quotes, em/en dashes, ellipsis |
|
|
89
|
+
| SVG rendering | Enabled | Render SVG code blocks as images |
|
|
90
|
+
| Collapsible headings | Disabled | Expand/collapse heading sections |
|
|
91
|
+
| HTML passthrough | Disabled | Raw HTML rendering (security-sensitive) |
|
|
92
|
+
| JavaScript | Disabled | Allow JS in HTML (use only for trusted content) |
|
|
91
93
|
|
|
92
|
-
|
|
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
|
|
94
|
+
## Configuration Inputs
|
|
138
95
|
|
|
139
96
|
| Input | Type | Default | Description |
|
|
140
97
|
|-------|------|---------|-------------|
|
|
141
98
|
| `data` | `string` | `''` | Markdown content to render |
|
|
142
|
-
| `enableHighlight` | `boolean` | `true` |
|
|
143
|
-
| `enableMermaid` | `boolean` | `true` |
|
|
144
|
-
| `enableCodeCopy` | `boolean` | `true` |
|
|
145
|
-
| `enableCollapsibleHeadings` | `boolean` | `false` |
|
|
99
|
+
| `enableHighlight` | `boolean` | `true` | Prism.js syntax highlighting |
|
|
100
|
+
| `enableMermaid` | `boolean` | `true` | Mermaid diagram rendering |
|
|
101
|
+
| `enableCodeCopy` | `boolean` | `true` | Copy button on code blocks |
|
|
102
|
+
| `enableCollapsibleHeadings` | `boolean` | `false` | Collapsible heading sections |
|
|
146
103
|
| `collapsibleHeadingLevel` | `1-6` | `2` | Heading level to start collapsing |
|
|
147
104
|
| `collapsibleDefaultExpanded` | `boolean` | `true` | Default expansion state |
|
|
148
105
|
| `autoExpandLevels` | `number[]` | `undefined` | Specific levels to auto-expand |
|
|
149
|
-
| `enableAlerts` | `boolean` | `true` |
|
|
150
|
-
| `enableSmartypants` | `boolean` | `true` |
|
|
151
|
-
| `enableSvgRenderer` | `boolean` | `true` |
|
|
152
|
-
| `enableHtml` | `boolean` | `false` |
|
|
153
|
-
| `enableJavaScript` | `boolean` | `false` | Allow
|
|
106
|
+
| `enableAlerts` | `boolean` | `true` | GitHub-style alerts |
|
|
107
|
+
| `enableSmartypants` | `boolean` | `true` | Typography improvements |
|
|
108
|
+
| `enableSvgRenderer` | `boolean` | `true` | SVG code block rendering |
|
|
109
|
+
| `enableHtml` | `boolean` | `false` | Raw HTML passthrough |
|
|
110
|
+
| `enableJavaScript` | `boolean` | `false` | Allow JS in HTML |
|
|
154
111
|
| `enableHeadingIds` | `boolean` | `true` | Generate heading IDs for anchors |
|
|
155
112
|
| `headingIdPrefix` | `string` | `''` | Prefix for heading IDs |
|
|
156
113
|
| `enableLineNumbers` | `boolean` | `false` | Show line numbers in code blocks |
|
|
@@ -158,56 +115,30 @@ Enable raw HTML rendering for mockups and custom layouts:
|
|
|
158
115
|
| `mermaidTheme` | `string` | `'default'` | Mermaid theme (default/dark/forest/neutral/base) |
|
|
159
116
|
| `sanitize` | `boolean` | `true` | Sanitize HTML output |
|
|
160
117
|
|
|
161
|
-
##
|
|
118
|
+
## Outputs
|
|
162
119
|
|
|
163
|
-
|
|
|
164
|
-
|
|
165
|
-
| `rendered` | `MarkdownRenderEvent` | Emitted when rendering
|
|
120
|
+
| Event | Type | Description |
|
|
121
|
+
|-------|------|-------------|
|
|
122
|
+
| `rendered` | `MarkdownRenderEvent` | Emitted when rendering completes |
|
|
166
123
|
| `headingClick` | `HeadingInfo` | Emitted when a heading is clicked |
|
|
167
124
|
| `codeCopied` | `string` | Emitted when code is copied to clipboard |
|
|
168
125
|
|
|
169
126
|
## Migration from ngx-markdown
|
|
170
127
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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`.
|
|
128
|
+
1. Replace imports: `'ngx-markdown'` to `'@memberjunction/ng-markdown'`
|
|
129
|
+
2. Remove `forRoot()` from module imports
|
|
130
|
+
3. Update selectors: `<markdown>` to `<mj-markdown>`
|
|
131
|
+
4. The `element` property is preserved for backward compatibility
|
|
201
132
|
|
|
202
133
|
## Dependencies
|
|
203
134
|
|
|
204
|
-
- `marked`
|
|
205
|
-
- `marked-alert`
|
|
206
|
-
- `marked-highlight`
|
|
207
|
-
- `marked-smartypants`
|
|
208
|
-
- `prismjs`
|
|
209
|
-
- `mermaid`
|
|
135
|
+
- `marked` -- Markdown parser
|
|
136
|
+
- `marked-alert` -- GitHub-style alerts
|
|
137
|
+
- `marked-highlight` -- Syntax highlighting integration
|
|
138
|
+
- `marked-smartypants` -- Typography improvements
|
|
139
|
+
- `prismjs` -- Syntax highlighting
|
|
140
|
+
- `mermaid` -- Diagram rendering
|
|
210
141
|
|
|
211
|
-
##
|
|
142
|
+
## Related Packages
|
|
212
143
|
|
|
213
|
-
|
|
144
|
+
- [@memberjunction/ng-skip-chat](../skip-chat/README.md) -- Uses markdown for chat message rendering
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ng-markdown",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "MemberJunction: Lightweight Angular markdown component with Prism.js highlighting, Mermaid diagrams, and extensible features",
|
|
5
5
|
"main": "./dist/public-api.js",
|
|
6
6
|
"typings": "./dist/public-api.d.ts",
|