@molecule/markdown
v1.0.1
Published
A library providing an interface for markdown services and a corresponding pipe
Downloads
6
Maintainers
Readme
Molecule Markdown
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, [email protected]
License
@molecule/markdown is available under the MIT license.