UNPKG

ngx-markdown-it

Version:

An Angular library that renders markdown using [markdown-it](https://github.com/markdown-it/markdown-it).

1 lines 14.8 kB
{"version":3,"file":"ngx-markdown-it.mjs","sources":["../../../lib/ngx-markdown-it/src/lib/ngx-markdown-it-config.class.ts","../../../lib/ngx-markdown-it/src/lib/ngx-markdown-it.service.ts","../../../lib/ngx-markdown-it/src/lib/ngx-markdown-it.component.ts","../../../lib/ngx-markdown-it/src/lib/ngx-markdown-it.module.ts","../../../lib/ngx-markdown-it/src/public-api.ts","../../../lib/ngx-markdown-it/src/ngx-markdown-it.ts"],"sourcesContent":["/*\n * @file ngx-markdown-it-config.class.ts\n *\n * @brief Config class\n * @author David Suárez\n * @date Mon, 21 Jun 20 19:45:15 +0200\n *\n * @license\n *\n * ngx-markdown-it: angular markdown-it module\n *\n * Copyright (c) 2021 David Suárez\n *\n * Permission is hereby granted, free of charge, to any person\n * obtaining a copy of this software and associated documentation\n * files (the \"Software\"), to deal in the Software without\n * restriction, including without limitation the rights to use,\n * copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following\n * conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n * OTHER DEALINGS IN THE SOFTWARE.\n *\n */\n\nimport * as MarkdownIt from \"markdown-it\";\n\nexport class NgxMarkdownItConfig {\n\n /**\n * Syntax rules and options for common use cases:\n *\n * - default - similar to GFM, used when no preset name given.\n * - \"commonmark\" - configures parser to strict CommonMark mode.\n * - \"zero\" - all rules disabled.\n */\n presetName?: MarkdownIt.PresetName;\n\n /**\n * Plugins to apply.\n */\n plugins?: any[];\n};\n","/*\n * @file ngx-markdown-it.service.ts\n *\n * @brief Markdown It service\n * @author David Suárez\n * @date Mon, 21 Jun 20 19:45:15 +0200\n *\n * @license\n *\n * ngx-markdown-it: angular markdown-it module\n *\n * Copyright (c) 2021 David Suárez\n *\n * Permission is hereby granted, free of charge, to any person\n * obtaining a copy of this software and associated documentation\n * files (the \"Software\"), to deal in the Software without\n * restriction, including without limitation the rights to use,\n * copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following\n * conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n * OTHER DEALINGS IN THE SOFTWARE.\n *\n */\n\nimport { Injectable, Optional } from '@angular/core';\n\nimport { NgxMarkdownItConfig } from \"./ngx-markdown-it-config.class\";\n\nimport MarkdownIt from 'markdown-it';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class NgxMarkdownItService {\n\n private markdownIt: MarkdownIt;\n\n constructor(@Optional() config?: NgxMarkdownItConfig) {\n\n var presetName : MarkdownIt.PresetName = 'default';\n\n if (config && config.presetName) {\n presetName = config.presetName;\n }\n\n this.markdownIt = new MarkdownIt(presetName);\n\n if (config && config.plugins) {\n config.plugins.forEach(plugin => this.markdownIt.use(plugin));\n }\n }\n\n /**\n * Renders a markdown string to HTML\n *\n * @param {string} markdown Markdown string that you want to render.\n * @returns {string}\n */\n public render(markdown: string): string {\n return `${this.markdownIt.render(markdown)}`;\n }\n}\n","/*\n * @file ngx-markdown-it.component.ts\n *\n * @brief Component to render markdown to html\n * @author David Suárez\n * @date Mon, 21 Jun 20 19:45:15 +0200\n *\n * @license\n *\n * ngx-markdown-it: angular markdown-it module\n *\n * Copyright (c) 2021 David Suárez\n *\n * Permission is hereby granted, free of charge, to any person\n * obtaining a copy of this software and associated documentation\n * files (the \"Software\"), to deal in the Software without\n * restriction, including without limitation the rights to use,\n * copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following\n * conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n * OTHER DEALINGS IN THE SOFTWARE.\n *\n */\n\nimport { Component, AfterViewInit, EventEmitter, ElementRef, Input, Output } from '@angular/core';\n\nimport { NgxMarkdownItService } from \"./ngx-markdown-it.service\";\n\n@Component({\n selector: 'markdown-it',\n template: `<ng-content></ng-content>`,\n styles: []\n})\nexport class NgxMarkdownItComponent implements AfterViewInit {\n\n _markdown: string | undefined;\n\n @Output() ready = new EventEmitter<void>();\n\n @Input()\n set markdown(val: string) {\n this._markdown = val;\n this.render(this._markdown);\n }\n\n constructor(\n public element: ElementRef<HTMLElement>,\n private markdownService: NgxMarkdownItService,\n ) { }\n\n ngAfterViewInit(): void {\n if (this._markdown == null) {\n this.render(this.element.nativeElement.innerHTML.trim());\n return;\n\n } else {\n /*\n * This is probably done in markdown() setter, but because before the view is init, our component or parents ones\n * are not in a safe state, we should signal again.\n */\n this.ready.emit();\n return;\n }\n }\n\n render(markdown: string): void {\n this.element.nativeElement.innerHTML = this.markdownService.render(markdown);\n this.ready.emit();\n }\n}\n","/*\n * @file ngx-markdown-it.module.ts\n *\n * @brief Library module\n * @author David Suárez\n * @date Mon, 21 Jun 20 19:45:15 +0200\n *\n * @license\n *\n * ngx-markdown-it: angular markdown-it module\n *\n * Copyright (c) 2021 David Suárez\n *\n * Permission is hereby granted, free of charge, to any person\n * obtaining a copy of this software and associated documentation\n * files (the \"Software\"), to deal in the Software without\n * restriction, including without limitation the rights to use,\n * copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following\n * conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n * OTHER DEALINGS IN THE SOFTWARE.\n *\n */\n\nimport { NgModule, ModuleWithProviders, Optional, SkipSelf } from '@angular/core';\n\nimport { NgxMarkdownItComponent } from './ngx-markdown-it.component';\nimport { NgxMarkdownItService } from \"./ngx-markdown-it.service\";\nimport { NgxMarkdownItConfig } from \"./ngx-markdown-it-config.class\";\n\n@NgModule({\n declarations: [\n NgxMarkdownItComponent\n ],\n imports: [\n ],\n exports: [\n NgxMarkdownItComponent\n ]\n})\nexport class NgxMarkdownItModule {\n\n constructor(@Optional() @SkipSelf() parentModule?: NgxMarkdownItModule) {\n if (parentModule) {\n throw new Error(\n 'NgxMarkdownItModule is already loaded. Import it in the AppModule only');\n }\n }\n\n static forRoot(config?: NgxMarkdownItConfig): ModuleWithProviders<NgxMarkdownItModule> {\n return {\n ngModule: NgxMarkdownItModule,\n providers: [{\n provide: NgxMarkdownItConfig,\n useValue: config\n }\n ]\n };\n }\n}\n\n","/*\n * @file public-api.ts\n *\n * @brief Public API Surface of ngx-markdown-it\n * @author David Suárez\n * @date Mon, 21 Jun 20 19:45:15 +0200\n *\n * @license\n *\n * ngx-markdown-it: angular markdown-it module\n *\n * Copyright (c) 2021 David Suárez\n *\n * Permission is hereby granted, free of charge, to any person\n * obtaining a copy of this software and associated documentation\n * files (the \"Software\"), to deal in the Software without\n * restriction, including without limitation the rights to use,\n * copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the\n * Software is furnished to do so, subject to the following\n * conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n * OTHER DEALINGS IN THE SOFTWARE.\n *\n */\n\nexport * from './lib/ngx-markdown-it.service';\nexport * from './lib/ngx-markdown-it.component';\nexport * from './lib/ngx-markdown-it.module';\nexport * from './lib/ngx-markdown-it-config.class';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.NgxMarkdownItConfig","i1.NgxMarkdownItService"],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCG;MAIU,mBAAmB,CAAA;AAE9B;;;;;;AAMG;AACH,IAAA,UAAU,CAAyB;AAEnC;;AAEG;AACH,IAAA,OAAO,CAAS;AACjB,CAAA;AAAA;;ACrDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCG;MAWU,oBAAoB,CAAA;AAEvB,IAAA,UAAU,CAAa;AAE/B,IAAA,WAAA,CAAwB,MAA4B,EAAA;QAElD,IAAI,UAAU,GAA2B,SAAS,CAAC;AAEnD,QAAA,IAAI,MAAM,IAAI,MAAM,CAAC,UAAU,EAAE;AAC/B,YAAA,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;AAChC,SAAA;QAED,IAAI,CAAC,UAAU,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;AAE7C,QAAA,IAAI,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE;AAC1B,YAAA,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AACjE,SAAA;KACF;AAED;;;;;AAKG;AACI,IAAA,MAAM,CAAC,QAAgB,EAAA;QAC5B,OAAO,CAAA,EAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA,CAAE,CAAC;KAC9C;uGA3BU,oBAAoB,EAAA,IAAA,EAA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