ngx-markdown-it
TypeScript icon, indicating that this package has built-in type declarations

16.0.1 • Public • Published

ngx-markdown-it

An Angular library that renders markdown using markdown-it.

You can try online @StackBlitz.

Installation

Use your favorite package manager to install ngx-markdown-it. For example, with NPM:

npm install ngx-markdown-it

Don't forget to install markdown-it too:

npm install markdown-it

Configuration

As usual, with Angular, you must import the module inside your main application:

import { NgxMarkdownItModule } from "ngx-markdown-it";

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    NgxMarkdownItModule
  ],
  providers: [],
  bootstrap: []
})
export class AppModule { }

Optionally, you can pass a NgxMarkdownItConfig class to the module, to allow to configure the markdown-it library. For example, to use the markdown-it-markmap plugin:

import { NgxMarkdownItModule } from "ngx-markdown-it";
import { NgxMarkdownItConfig } from "ngx-markdown-it";

import { default as markmapPlugin } from 'markdown-it-markmap';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    NgxMarkdownItModule.forRoot({
      plugins: [
        markmapPlugin
      ]
    })
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Usage

The module provides a component and a service.

markdown-it component

A simple component to render the mardown.

<markdown-it [markdown]="markdown"></markdown-it>
<markdown-it ngPreserveWhitespaces># A level 1 header</markdown-it>

markdown-it service

A service to allow more advanced usage of the markdown-it parser.

import { Component, OnInit } from '@angular/core';
import { NgxMarkdownItService } from 'ngx-markdown-it';

@Component({ ... })
export class Foo implements OnInit {
  constructor(private markdownItService: NgxMarkdownItService) { }

  ngOnInit() {
    console.log(this.markdownItService.render('# A level 1 header'));
  }
}

Development

The library is located in projects/ngx-markdown-it. The root app is only a demo to test the library.

Package Sidebar

Install

npm i ngx-markdown-it

Weekly Downloads

96

Version

16.0.1

License

MIT

Unpacked Size

67 kB

Total Files

17

Last publish

Collaborators

  • deiv