• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jfcere / ngx-markdown / 3fd6366a-f091-402b-aa3c-ca4a17b31cfc

01 Sep 2025 04:49PM UTC coverage: 61.982% (-34.9%) from 96.89%
3fd6366a-f091-402b-aa3c-ca4a17b31cfc

Pull #597

circleci

jfcere
add support for sanitizer function
Pull Request #597: feat: add support for sanitizer function

84 of 121 branches covered (69.42%)

Branch coverage included in aggregate %.

12 of 12 new or added lines in 3 files covered. (100.0%)

123 existing lines in 6 files now uncovered.

185 of 313 relevant lines covered (59.11%)

12.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/lib/src/markdown.module.ts
1
import { InjectionToken, ModuleWithProviders, NgModule, Provider, SecurityContext } from '@angular/core';
2
import { ClipboardButtonComponent } from './clipboard-button.component';
3
import { CLIPBOARD_OPTIONS } from './clipboard-options';
4
import { LanguagePipe } from './language.pipe';
5
import { MarkdownComponent } from './markdown.component';
6
import { MarkdownPipe } from './markdown.pipe';
7
import { MARKED_EXTENSIONS } from './marked-extensions';
8
import { MARKED_OPTIONS } from './marked-options';
9
import { MERMAID_OPTIONS } from './mermaid-options';
10
import { provideMarkdown } from './provide-markdown';
11
import { SANITIZE } from './sanitize-options';
12

13
type InjectionTokenType<T extends InjectionToken<any>> = T extends InjectionToken<infer R> ? R : unknown;
14

15
interface TypedValueProvider<T extends InjectionToken<any>> {
16
  provide: T;
17
  useValue: InjectionTokenType<T>;
18
};
19

20
interface TypedFactoryProvider<T extends InjectionToken<any>> {
21
  provide: T;
22
  useFactory: (...args: any[]) => InjectionTokenType<T>;
23
  deps?: any[];
24
};
25

26
type TypedProvider<T extends InjectionToken<any>> = TypedValueProvider<T> | TypedFactoryProvider<T>;
27

28
type MultiTypedProvider<T extends InjectionToken<any>> = TypedProvider<T> & { multi: true };
29

30
export function isTypedProvider<T extends InjectionToken<any>>(provider: any): provider is TypedProvider<T> {
31
  return provider != null && provider.provide != null;
63✔
32
}
33

34
export function getSanitizeProvider(sanitize: MarkdownModuleConfig['sanitize']): Provider | undefined {
35
  return isTypedProvider(sanitize)
63!
36
    ? sanitize
37
    : { provide: SANITIZE, useValue: sanitize ?? SecurityContext.HTML };
63!
38
}
39

40
/**
41
 * @deprecated Will be removed in ngx-markdown v21, use provider syntax instead.
42
 * ```typescript
43
 * sanitize: { provide: SANITIZE, useValue: SecurityContext.HTML },
44
 * ```
45
 */
46
type SanitizeTokenType = InjectionTokenType<typeof SANITIZE>;
47

48
// having a dependency on `HttpClientModule` within a library
49
// breaks all the interceptors from the app consuming the library
50
// here, we explicitely ask the user to pass a provider with
51
// their own instance of `HttpClientModule`
52
export interface MarkdownModuleConfig {
53
  loader?: Provider;
54
  clipboardOptions?: TypedProvider<typeof CLIPBOARD_OPTIONS>;
55
  markedOptions?: TypedProvider<typeof MARKED_OPTIONS>;
56
  markedExtensions?: MultiTypedProvider<typeof MARKED_EXTENSIONS>[];
57
  mermaidOptions?: TypedProvider<typeof MERMAID_OPTIONS>;
58
  sanitize?: SanitizeTokenType | TypedProvider<typeof SANITIZE>;
59
}
60

61
const sharedDeclarations = [
1✔
62
  ClipboardButtonComponent,
63
  LanguagePipe,
64
  MarkdownComponent,
65
  MarkdownPipe,
66
];
67

68
@NgModule({
69
  imports: sharedDeclarations,
70
  exports: sharedDeclarations,
71
})
72
export class MarkdownModule {
1✔
73
  static forRoot(markdownModuleConfig?: MarkdownModuleConfig): ModuleWithProviders<MarkdownModule> {
74
    return {
63✔
75
      ngModule: MarkdownModule,
76
      providers: [
77
        provideMarkdown(markdownModuleConfig),
78
      ],
79
    };
80
  }
81

82
  static forChild(): ModuleWithProviders<MarkdownModule> {
UNCOV
83
    return {
×
84
      ngModule: MarkdownModule,
85
    };
86
  }
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc