@molecule/markdown
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Molecule Markdown

CircleCI Codecov npm (scoped)

Molecule Markdown provides you an Angular directive '# Title'|md and a corresponding service, MarkdownService, which allows you to provide any markdown parser you wish. On the other hand, you need to provide a subclass for it in order to MarkdownPipe.

Example

@NgModule({
  import: [MarkdownModule],
  declarations: [MyComponent],
  providers: [{
    provide: MarkdownService,
    useClass: YourMarkdownService
  }]
})
export class MyModule {}

@Component({
  template: '{{myMarkdownText|md}}'
})
export class MyComponent {
  @Input() public myMarkdownText: string;
}

Using Marked

@Injectable()
export class MarkdedService extends MarkdownService {
  constructor() {
    marked.setOptions({ /* configuration options */ });
  }
  public markdownToHtml(markdown: string, ...args: any[]): string {
    return marked(markdown, options);
  }
}

Using Markdown It

@Injectable()
export class MarkdownItService extends MarkdownService {
  private readonly markdownIt: MarkdownIt;
  constructor() {
    this.markdownIt = new MarkdownIt();
  }
  public markdownToHtml(markdown: string, ...args: any[]): string {
    return this.markdownIt.render(markdown);
  }
}

Installation

$ npm install --save @molecule/markdown

Author

Valentin Knabel, @vknabel, dev@vknabel.com

License

@molecule/markdown is available under the MIT license.

Package Sidebar

Install

npm i @molecule/markdown

Weekly Downloads

0

Version

1.0.1

License

MIT

Last publish

Collaborators

  • vknabel