Showing
1 changed file
with
23 additions
and
0 deletions
... | ... | @@ -19,6 +19,8 @@ import { Inject, Injectable } from '@angular/core'; |
19 | 19 | import { TranslateService } from '@ngx-translate/core'; |
20 | 20 | import { DOCUMENT } from '@angular/common'; |
21 | 21 | import { WINDOW } from '@core/services/window.service'; |
22 | +import { Tokenizer } from 'marked'; | |
23 | +import * as marked from 'marked'; | |
22 | 24 | |
23 | 25 | const copyCodeBlock = '{:copy-code}'; |
24 | 26 | const autoBlock = '{:auto}'; |
... | ... | @@ -37,6 +39,7 @@ export class MarkedOptionsService extends MarkedOptions { |
37 | 39 | pedantic = false; |
38 | 40 | smartLists = true; |
39 | 41 | smartypants = false; |
42 | + mangle = false; | |
40 | 43 | |
41 | 44 | private renderer2 = new MarkedRenderer(); |
42 | 45 | |
... | ... | @@ -46,6 +49,26 @@ export class MarkedOptionsService extends MarkedOptions { |
46 | 49 | @Inject(WINDOW) private readonly window: Window, |
47 | 50 | @Inject(DOCUMENT) private readonly document: Document) { |
48 | 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 | 72 | this.renderer.code = (code: string, language: string | undefined, isEscaped: boolean) => { |
50 | 73 | if (code.endsWith(copyCodeBlock)) { |
51 | 74 | code = code.substring(0, code.length - copyCodeBlock.length); | ... | ... |