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

jfcere / ngx-markdown / 1d74f11f-e24c-450c-8833-c4f1753d8817

08 Nov 2023 02:17AM CUT coverage: 96.939% (-0.3%) from 97.194%
1d74f11f-e24c-450c-8833-c4f1753d8817

push

circleci

web-flow
chore: update to marked version 9 (#474)

* chore: update to marked version 9

a new token `MARKDOWN_EXTENSIONS` has been added to provide extensions to marked
usage example
```
{
  provide: MARKDOWN_EXTENSIONS,
  useValue: [gfmHeadingId()],
}
```

update `readme.md` file
- removed from the examples all the options that were removed
- added section for the new marked extension token
- removed the part that we need to add node_modules/marked/marked.min.js to our scripts since it's not needed

breaking change
- all options that were removed from marked has been deleted from this library too, see more at https://marked.js.org/using_advanced#options
- some methods now return `Promise<string>` instead of `string`, because marked is doing so
- `srcRelativeLink` input is removed as the baseUrl option has been removed from marked, use https://www.npmjs.com/package/marked-base-url instead

* Update README.md

* test: fix the Marked testing by providing it using Angular dependency rejection

so it's possible to override it in the unit test
it starts with ɵ so IDE doesn't provide it in autocomplete suggestions

* feat: add `extensions` to the `MarkdownModuleConfig`

remove unused `loader` from the `MarkdownModuleConfig`

* Revert "feat: add `extensions` to the `MarkdownModuleConfig`"

This reverts commit be713bf63.

* Re-add extensions to the MarkdownModuleConfig

* Add missing unit tests

---------

Co-authored-by: jfcere <jfcere@sherweb.com>

98 of 106 branches covered (0.0%)

Branch coverage included in aggregate %.

15 of 15 new or added lines in 5 files covered. (100.0%)

282 of 286 relevant lines covered (98.6%)

21.24 hits per line

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

100.0
/lib/src/markdown.module.ts
1
import { CommonModule } from '@angular/common';
2
import { ModuleWithProviders, NgModule, Provider, SecurityContext } from '@angular/core';
3

4
// eslint-disable-next-line import/named
5
import { Marked, MarkedExtension } from 'marked';
6
import { ClipboardButtonComponent } from './clipboard-button.component';
7
import { LanguagePipe } from './language.pipe';
8
import { MARKED_EXTENSIONS } from './markdown-extensions';
9
import { MarkdownComponent } from './markdown.component';
10
import { MarkdownPipe } from './markdown.pipe';
11
import { MarkdownService, SECURITY_CONTEXT } from './markdown.service';
12
import { ɵMARKED } from './marked';
13

14
// having a dependency on `HttpClientModule` within a library
15
// breaks all the interceptors from the app consuming the library
16
// here, we explicitely ask the user to pass a provider with
17
// their own instance of `HttpClientModule`
18
export interface MarkdownModuleConfig {
19
  loader?: Provider;
20
  clipboardOptions?: Provider;
21
  markedOptions?: Provider;
22
  markedExtensions?: MarkedExtension[];
23
  sanitize?: SecurityContext;
24
}
25

26
const sharedDeclarations = [
1✔
27
  ClipboardButtonComponent,
28
  LanguagePipe,
29
  MarkdownComponent,
30
  MarkdownPipe,
31
];
32

33
@NgModule({
34
  imports: [CommonModule],
35
  exports: sharedDeclarations,
36
  declarations: sharedDeclarations,
37
})
38
export class MarkdownModule {
1✔
39
  static forRoot(markdownModuleConfig?: MarkdownModuleConfig): ModuleWithProviders<MarkdownModule> {
40
    return {
94✔
41
      ngModule: MarkdownModule,
42
      providers: [
43
        MarkdownService,
44
        markdownModuleConfig?.loader ?? [],
184✔
45
        markdownModuleConfig?.clipboardOptions ?? [],
186✔
46
        markdownModuleConfig?.markedOptions ?? [],
183✔
47
        {
48
          provide: MARKED_EXTENSIONS,
49
          useValue: markdownModuleConfig?.markedExtensions ?? [],
187✔
50
        },
51
        {
52
          provide: SECURITY_CONTEXT,
53
          useValue: markdownModuleConfig?.sanitize ?? SecurityContext.HTML,
130✔
54
        },
55
        {
56
          provide: ɵMARKED,
57
          useValue: Marked,
58
        },
59
      ],
60
    };
61
  }
62

63
  static forChild(): ModuleWithProviders<MarkdownModule> {
64
    return {
2✔
65
      ngModule: MarkdownModule,
66
    };
67
  }
68
}
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