- - -
- - - Rocket Ship - - - - - - - - - - {{ title }} app is running! - - - Rocket Ship Smoke - - - -
- - -

Resources

-

Here are some links to help you get started:

- - - - -

Next Steps

-

What do you want to do next with your app?

- - - -
-
- - - New Component -
- -
- - - Angular Material -
- -
- - - Add PWA Support -
- -
- - - Add Dependency -
- -
- - - Run and Watch Tests -
- -
- - - Build for Production -
-
- - -
-
ng generate component xyz
-
ng add @angular/material
-
ng add @angular/pwa
-
ng add _____
-
ng test
-
ng build
-
- - - - - - - - - Gray Clouds Background - - +

Component using content from text area

+
+ +
- - - - - - - - - diff --git a/src/app/app.component.scss b/src/app/app.component.scss index e69de29..a818835 100644 --- a/src/app/app.component.scss +++ b/src/app/app.component.scss @@ -0,0 +1,28 @@ + +h1 { + color: blue; +} + +h2 { + color: mediumslateblue; +} + +.xpand-textarea { + border-radius: 5px; + padding: 0.4em; + resize: vertical; +} + +markdown-it { + padding: 0.4em; +} + +.demo-container { + display: flex; +} + +.demo-container * { + width: 49%; +} + + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 68959e4..8105e69 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,4 +1,13 @@ -import { Component } from '@angular/core'; +import {Component, VERSION, ViewChild} from '@angular/core'; + +import * as packageInfo from '../../projects/ngx-markdown-it/package.json'; + +import { NgxMarkdownItService } from "ngx-markdown-it"; +import { NgxMarkdownItComponent } from "../../projects/ngx-markdown-it/src/lib/ngx-markdown-it.component"; + +import { markmap as MarkmapView } from 'markmap-lib/dist/view'; + +const {version} = packageInfo @Component({ selector: 'app-root', @@ -6,5 +15,34 @@ import { Component } from '@angular/core'; styleUrls: ['./app.component.scss'] }) export class AppComponent { - title = 'ngx-markdown-it-demo'; + + @ViewChild('ngxMarkdownIt') ngxMarkdownIt? : NgxMarkdownItComponent; + + angularVersion = VERSION.full; + ngxMarkdownItVersion = version; + markdown = ` +# Edit the markdown text here, it will update + +The markdown-it library has the markmap plugin, so you can render mindmaps like: +\`\`\`mindmap +# root +## child1 + - child3 +## child2 + - child3 +\`\`\` + `; + + constructor(private ngxMarkdownItService: NgxMarkdownItService) { } + + markdownReady() : void { + if (this.ngxMarkdownIt) { + + this.ngxMarkdownIt + .element + .nativeElement + .querySelectorAll('.markmap-svg') + .forEach(mindmap => MarkmapView(mindmap, JSON.parse(mindmap.innerHTML))) + } + } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8dfc1d6..70d08ad 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,14 +1,26 @@ import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; +import { FormsModule } from '@angular/forms'; import { AppComponent } from './app.component'; +import { NgxMarkdownItModule } from "ngx-markdown-it"; +import { NgxMarkdownItConfig } from "ngx-markdown-it"; + +import { default as markmapPlugin } from 'markdown-it-markmap'; + @NgModule({ declarations: [ AppComponent ], imports: [ - BrowserModule + BrowserModule, + FormsModule, + NgxMarkdownItModule.forRoot({ + plugins: [ + markmapPlugin + ] + }) ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/markdown-it-markmap.d.ts b/src/app/markdown-it-markmap.d.ts new file mode 100644 index 0000000..337358e --- /dev/null +++ b/src/app/markdown-it-markmap.d.ts @@ -0,0 +1 @@ +declare module 'markdown-it-markmap'; diff --git a/src/app/markmap-lib.d.ts b/src/app/markmap-lib.d.ts new file mode 100644 index 0000000..4afecd5 --- /dev/null +++ b/src/app/markmap-lib.d.ts @@ -0,0 +1,2 @@ +// XXX: the package contains the types !!! +declare module 'markmap-lib/dist/view'; diff --git a/tsconfig.json b/tsconfig.json index 6df8283..3e9629a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,12 @@ "sourceMap": true, "declaration": false, "downlevelIteration": true, + "paths": { + "ngx-markdown-it": [ + "dist/ngx-markdown-it/ngx-markdown-it", + "dist/ngx-markdown-it" + ] + }, "experimentalDecorators": true, "moduleResolution": "node", "importHelpers": true, @@ -19,7 +25,8 @@ "lib": [ "es2018", "dom" - ] + ], + "resolveJsonModule": true }, "angularCompilerOptions": { "enableI18nLegacyMessageIdFormat": false,