instance-oom / ngx-markdown-editor

Angular markdown editor based on ace editor
http://lon-yang.github.io/markdown-editor/
Apache License 2.0
174 stars 48 forks source link
ace-editor angular-x markdown-editor

ngx-markdown-editor

Angular markdown editor based on ace editor

npm version npm GitHub license GitHub stars GitHub issues codesandbox.io

Online Demo

Usage

Installation

Install dependencies from npm repository:

npm i ace-builds bootstrap font-awesome

Install ngx-markdown-editor from npm repository:

npm i ngx-markdown-editor

Add the assets、styles and scripts in angular.json:

{
  ...
  "architect": {
    "build": {
      "options": {
        ...
        "assets": [
          {
            "glob": "**/*",
            "input": "node_modules/ace-builds/src-min",
            "output": "./assets/ace-builds/"
          }
        ],
        "styles": [
          "node_modules/bootstrap/dist/css/bootstrap.min.css",
          "node_modules/font-awesome/css/font-awesome.min.css",
          "node_modules/ngx-markdown-editor/assets/highlight.js/agate.min.css"
        ],
        "scripts": [
          "node_modules/ngx-markdown-editor/assets/highlight.js/highlight.min.js",
          "node_modules/ngx-markdown-editor/assets/marked.min.js"
        ]
        ...
      }
    }
  }
  ...    
}

Add ace.js in index.html

<html>
  <head>
    <script src="https://github.com/instance-oom/ngx-markdown-editor/raw/master/assets/ace-builds/ace.js"></script>
  </head>
  <body></body>
</html>
<=2.5.0

Install dependencies from npm repository: ```bash npm i brace bootstrap font-awesome ``` Install `ngx-markdown-editor` from npm repository: ```bash npm i ngx-markdown-editor ``` Add the styles and scripts in `angular.json`: ```json { ... "architect": { "build": { "options": { ... "styles": [ "node_modules/bootstrap/dist/css/bootstrap.min.css", "node_modules/font-awesome/css/font-awesome.min.css", "node_modules/ngx-markdown-editor/assets/highlight.js/agate.min.css" ], "scripts": [ "node_modules/ngx-markdown-editor/assets/highlight.js/highlight.min.js", "node_modules/ngx-markdown-editor/assets/marked.min.js" ] ... } } } ... } ``` Import `brace` in `polyfills.ts` ```ts import 'brace'; import 'brace/mode/markdown'; ```

Sample

import { LMarkdownEditorModule } from 'ngx-markdown-editor';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule, // make sure FormsModule is imported to make ngModel work
    LMarkdownEditorModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
<md-editor name="Content" 
  [upload]="doUpload" 
  [preRender]="preRenderFunc" 
  [postRender]="postRenderFunc"
  [(ngModel)]="content" 
  [height]="'200px'" 
  [mode]="mode" 
  [options]="options" 
  (onEditorLoaded)="onEditorLoaded($event)"
  (onPreviewDomChanged)="onPreviewDomChanged($event)"
  required 
  maxlength="500">
  <slot custom-btns></slot>
</md-editor>

Options

Tips: For Function input, please call bind at constructor to assign correct this pointer

Event