Showing
1 changed file
with
23 additions
and
0 deletions
@@ -19,6 +19,8 @@ import { Inject, Injectable } from '@angular/core'; | @@ -19,6 +19,8 @@ import { Inject, Injectable } from '@angular/core'; | ||
19 | import { TranslateService } from '@ngx-translate/core'; | 19 | import { TranslateService } from '@ngx-translate/core'; |
20 | import { DOCUMENT } from '@angular/common'; | 20 | import { DOCUMENT } from '@angular/common'; |
21 | import { WINDOW } from '@core/services/window.service'; | 21 | import { WINDOW } from '@core/services/window.service'; |
22 | +import { Tokenizer } from 'marked'; | ||
23 | +import * as marked from 'marked'; | ||
22 | 24 | ||
23 | const copyCodeBlock = '{:copy-code}'; | 25 | const copyCodeBlock = '{:copy-code}'; |
24 | const autoBlock = '{:auto}'; | 26 | const autoBlock = '{:auto}'; |
@@ -37,6 +39,7 @@ export class MarkedOptionsService extends MarkedOptions { | @@ -37,6 +39,7 @@ export class MarkedOptionsService extends MarkedOptions { | ||
37 | pedantic = false; | 39 | pedantic = false; |
38 | smartLists = true; | 40 | smartLists = true; |
39 | smartypants = false; | 41 | smartypants = false; |
42 | + mangle = false; | ||
40 | 43 | ||
41 | private renderer2 = new MarkedRenderer(); | 44 | private renderer2 = new MarkedRenderer(); |
42 | 45 | ||
@@ -46,6 +49,26 @@ export class MarkedOptionsService extends MarkedOptions { | @@ -46,6 +49,26 @@ export class MarkedOptionsService extends MarkedOptions { | ||
46 | @Inject(WINDOW) private readonly window: Window, | 49 | @Inject(WINDOW) private readonly window: Window, |
47 | @Inject(DOCUMENT) private readonly document: Document) { | 50 | @Inject(DOCUMENT) private readonly document: Document) { |
48 | super(); | 51 | super(); |
52 | + // @ts-ignore | ||
53 | + const tokenizer: Tokenizer = { | ||
54 | + autolink(src: string, mangle: (cap: string) => string): marked.Tokens.Link { | ||
55 | + if (src.endsWith(copyCodeBlock)) { | ||
56 | + return undefined; | ||
57 | + } else { | ||
58 | + // @ts-ignore | ||
59 | + return false; | ||
60 | + } | ||
61 | + }, | ||
62 | + url(src: string, mangle: (cap: string) => string): marked.Tokens.Link { | ||
63 | + if (src.endsWith(copyCodeBlock)) { | ||
64 | + return undefined; | ||
65 | + } else { | ||
66 | + // @ts-ignore | ||
67 | + return false; | ||
68 | + } | ||
69 | + } | ||
70 | + }; | ||
71 | + marked.use({tokenizer}); | ||
49 | this.renderer.code = (code: string, language: string | undefined, isEscaped: boolean) => { | 72 | this.renderer.code = (code: string, language: string | undefined, isEscaped: boolean) => { |
50 | if (code.endsWith(copyCodeBlock)) { | 73 | if (code.endsWith(copyCodeBlock)) { |
51 | code = code.substring(0, code.length - copyCodeBlock.length); | 74 | code = code.substring(0, code.length - copyCodeBlock.length); |